c-general.c 19.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
// Test instrumentation of general constructs in C.

// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOGEN %s

// RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v5 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
// Also check compatibility with older profiles.
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s

// PGOGEN: @[[SLC:__profc_simple_loops]] = private global [4 x i64] zeroinitializer
// PGOGEN: @[[IFC:__profc_conditionals]] = private global [11 x i64] zeroinitializer
// PGOGEN: @[[EEC:__profc_early_exits]] = private global [9 x i64] zeroinitializer
// PGOGEN: @[[JMC:__profc_jumps]] = private global [22 x i64] zeroinitializer
// PGOGEN: @[[SWC:__profc_switches]] = private global [19 x i64] zeroinitializer
// PGOGEN: @[[BSC:__profc_big_switch]] = private global [17 x i64] zeroinitializer
// PGOGEN: @[[BOC:__profc_boolean_operators]] = private global [8 x i64] zeroinitializer
// PGOGEN: @[[BLC:__profc_boolop_loops]] = private global [9 x i64] zeroinitializer
// PGOGEN: @[[COC:__profc_conditional_operator]] = private global [3 x i64] zeroinitializer
// PGOGEN: @[[DFC:__profc_do_fallthrough]] = private global [4 x i64] zeroinitializer
// PGOGEN: @[[MAC:__profc_main]] = private global [1 x i64] zeroinitializer
// PGOGEN: @[[STC:__profc_c_general.c_static_func]] = private global [2 x i64] zeroinitializer

// PGOGEN-LABEL: @simple_loops()
// PGOUSE-LABEL: @simple_loops()
// PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 0
void simple_loops() {
  int i;
  // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[SL1:[0-9]+]]
  for (i = 0; i < 100; ++i) {
  }
  // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 2
  // PGOUSE: br {{.*}} !prof ![[SL2:[0-9]+]]
  while (i > 0)
    i--;
  // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 3
  // PGOUSE: br {{.*}} !prof ![[SL3:[0-9]+]]
  do {} while (i++ < 75);

  // PGOGEN-NOT: store {{.*}} @[[SLC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @conditionals()
// PGOUSE-LABEL: @conditionals()
// PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 0
void conditionals() {
  // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[IF1:[0-9]+]]
  for (int i = 0; i < 100; ++i) {
    // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 2
    // PGOUSE: br {{.*}} !prof ![[IF2:[0-9]+]]
    if (i % 2) {
      // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 3
      // PGOUSE: br {{.*}} !prof ![[IF3:[0-9]+]]
      if (i) {}
    // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 4
    // PGOUSE: br {{.*}} !prof ![[IF4:[0-9]+]]
    } else if (i % 3) {
      // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 5
      // PGOUSE: br {{.*}} !prof ![[IF5:[0-9]+]]
      if (i) {}
    } else {
      // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 6
      // PGOUSE: br {{.*}} !prof ![[IF6:[0-9]+]]
      if (i) {}
    }

    // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 8
    // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 7
    // PGOUSE: br {{.*}} !prof ![[IF7:[0-9]+]]
    if (1 && i) {}
    // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 10
    // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 9
    // PGOUSE: br {{.*}} !prof ![[IF8:[0-9]+]]
    if (0 || i) {}
  }

  // PGOGEN-NOT: store {{.*}} @[[IFC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @early_exits()
// PGOUSE-LABEL: @early_exits()
// PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 0
void early_exits() {
  int i = 0;

  // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[EE1:[0-9]+]]
  if (i) {}

  // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 2
  // PGOUSE: br {{.*}} !prof ![[EE2:[0-9]+]]
  while (i < 100) {
    i++;
    // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 3
    // PGOUSE: br {{.*}} !prof ![[EE3:[0-9]+]]
    if (i > 50)
      break;
    // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 4
    // PGOUSE: br {{.*}} !prof ![[EE4:[0-9]+]]
    if (i % 2)
      continue;
  }

  // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 5
  // PGOUSE: br {{.*}} !prof ![[EE5:[0-9]+]]
  if (i) {}

  // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 6
  do {
    // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 7
    // PGOUSE: br {{.*}} !prof ![[EE6:[0-9]+]]
    if (i > 75)
      return;
    else
      i++;
  // PGOUSE: br {{.*}} !prof ![[EE7:[0-9]+]]
  } while (i < 100);

  // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 8
  // Never reached -> no weights
  if (i) {}

  // PGOGEN-NOT: store {{.*}} @[[EEC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @jumps()
// PGOUSE-LABEL: @jumps()
// PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 0
void jumps() {
  int i;

  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[JM1:[0-9]+]]
  for (i = 0; i < 2; ++i) {
    goto outofloop;
    // Never reached -> no weights
    if (i) {}
  }
// PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 3
outofloop:
  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 4
  // PGOUSE: br {{.*}} !prof ![[JM2:[0-9]+]]
  if (i) {}

  goto loop1;

  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 5
  // PGOUSE: br {{.*}} !prof ![[JM3:[0-9]+]]
  while (i) {
  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 6
  loop1:
    // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 7
    // PGOUSE: br {{.*}} !prof ![[JM4:[0-9]+]]
    if (i) {}
  }

  goto loop2;
// PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 8
first:
// PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 9
second:
// PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 10
third:
  i++;
  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 11
  // PGOUSE: br {{.*}} !prof ![[JM5:[0-9]+]]
  if (i < 3)
    goto loop2;

  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 12
  // PGOUSE: br {{.*}} !prof ![[JM6:[0-9]+]]
  while (i < 3) {
  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 13
  loop2:
    // PGOUSE: switch {{.*}} [
    // PGOUSE: ], !prof ![[JM7:[0-9]+]]
    switch (i) {
    // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 15
    case 0:
      goto first;
    // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 16
    case 1:
      goto second;
    // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 17
    case 2:
      goto third;
    }
    // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 14
  }

  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 18
  // PGOUSE: br {{.*}} !prof ![[JM8:[0-9]+]]
  for (i = 0; i < 10; ++i) {
    goto withinloop;
    // never reached -> no weights
    if (i) {}
  // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 20
  withinloop:
    // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 21
    // PGOUSE: br {{.*}} !prof ![[JM9:[0-9]+]]
    if (i) {}
  }

  // PGOGEN-NOT: store {{.*}} @[[JMC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @switches()
// PGOUSE-LABEL: @switches()
// PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 0
void switches() {
  static int weights[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};

  // No cases -> no weights
  switch (weights[0]) {
  // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 2
  default:
    break;
  }
  // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 1

  // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 3
  // PGOUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
  for (int i = 0, len = sizeof(weights) / sizeof(weights[0]); i < len; ++i) {
    // PGOUSE: switch {{.*}} [
    // PGOUSE: ], !prof ![[SW2:[0-9]+]]
    switch (i[weights]) {
    // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 5
    case 1:
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 6
      // PGOUSE: br {{.*}} !prof ![[SW3:[0-9]+]]
      if (i) {}
      // fallthrough
    // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 7
    case 2:
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 8
      // PGOUSE: br {{.*}} !prof ![[SW4:[0-9]+]]
      if (i) {}
      break;
    // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 9
    case 3:
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 10
      // PGOUSE: br {{.*}} !prof ![[SW5:[0-9]+]]
      if (i) {}
      continue;
    // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 11
    case 4:
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 12
      // PGOUSE: br {{.*}} !prof ![[SW6:[0-9]+]]
      if (i) {}
      // PGOUSE: switch {{.*}} [
      // PGOUSE: ], !prof ![[SW7:[0-9]+]]
      switch (i) {
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 14
      case 6 ... 9:
        // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 15
        // PGOUSE: br {{.*}} !prof ![[SW8:[0-9]+]]
        if (i) {}
        continue;
      }
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 13

    // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 16
    default:
      // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 17
      // PGOUSE: br {{.*}} !prof ![[SW9:[0-9]+]]
      if (i == len - 1)
        return;
    }
    // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 4
  }

  // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 18
  // Never reached -> no weights
  if (weights[0]) {}

  // PGOGEN-NOT: store {{.*}} @[[SWC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @big_switch()
// PGOUSE-LABEL: @big_switch()
// PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 0
void big_switch() {
  // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[BS1:[0-9]+]]
  for (int i = 0; i < 32; ++i) {
    // PGOUSE: switch {{.*}} [
    // PGOUSE: ], !prof ![[BS2:[0-9]+]]
    switch (1 << i) {
    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 3
    case (1 << 0):
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 4
      // PGOUSE: br {{.*}} !prof ![[BS3:[0-9]+]]
      if (i) {}
      // fallthrough
    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 5
    case (1 << 1):
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 6
      // PGOUSE: br {{.*}} !prof ![[BS4:[0-9]+]]
      if (i) {}
      break;
    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 7
    case (1 << 2) ... (1 << 12):
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 8
      // PGOUSE: br {{.*}} !prof ![[BS5:[0-9]+]]
      if (i) {}
      break;
    // The branch for the large case range above appears after the case body
    // PGOUSE: br {{.*}} !prof ![[BS6:[0-9]+]]

    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 9
    case (1 << 13):
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 10
      // PGOUSE: br {{.*}} !prof ![[BS7:[0-9]+]]
      if (i) {}
      break;
    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 11
    case (1 << 14) ... (1 << 28):
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 12
      // PGOUSE: br {{.*}} !prof ![[BS8:[0-9]+]]
      if (i) {}
      break;
    // The branch for the large case range above appears after the case body
    // PGOUSE: br {{.*}} !prof ![[BS9:[0-9]+]]

    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 13
    case (1 << 29) ... ((1 << 29) + 1):
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 14
      // PGOUSE: br {{.*}} !prof ![[BS10:[0-9]+]]
      if (i) {}
      break;
    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 15
    default:
      // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 16
      // PGOUSE: br {{.*}} !prof ![[BS11:[0-9]+]]
      if (i) {}
      break;
    }
    // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 2
  }

  // PGOGEN-NOT: store {{.*}} @[[BSC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  // PGOUSE: ret void
}

// PGOGEN-LABEL: @boolean_operators()
// PGOUSE-LABEL: @boolean_operators()
// PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 0
void boolean_operators() {
  int v;
  // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[BO1:[0-9]+]]
  for (int i = 0; i < 100; ++i) {
    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 2
    // PGOUSE: br {{.*}} !prof ![[BO2:[0-9]+]]
    v = i % 3 || i;

    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 3
    // PGOUSE: br {{.*}} !prof ![[BO3:[0-9]+]]
    v = i % 3 && i;

    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 5
    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 4
    // PGOUSE: br {{.*}} !prof ![[BO4:[0-9]+]]
    // PGOUSE: br {{.*}} !prof ![[BO5:[0-9]+]]
    v = i % 3 || i % 2 || i;

    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 7
    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 6
    // PGOUSE: br {{.*}} !prof ![[BO6:[0-9]+]]
    // PGOUSE: br {{.*}} !prof ![[BO7:[0-9]+]]
    v = i % 2 && i % 3 && i;
  }

  // PGOGEN-NOT: store {{.*}} @[[BOC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @boolop_loops()
// PGOUSE-LABEL: @boolop_loops()
// PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 0
void boolop_loops() {
  int i = 100;

  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 2
  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]
  // PGOUSE: br {{.*}} !prof ![[BL2:[0-9]+]]
  while (i && i > 50)
    i--;

  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 4
  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 3
  // PGOUSE: br {{.*}} !prof ![[BL3:[0-9]+]]
  // PGOUSE: br {{.*}} !prof ![[BL4:[0-9]+]]
  while ((i % 2) || (i > 0))
    i--;

  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 6
  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 5
  // PGOUSE: br {{.*}} !prof ![[BL5:[0-9]+]]
  // PGOUSE: br {{.*}} !prof ![[BL6:[0-9]+]]
  for (i = 100; i && i > 50; --i);

  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 8
  // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 7
  // PGOUSE: br {{.*}} !prof ![[BL7:[0-9]+]]
  // PGOUSE: br {{.*}} !prof ![[BL8:[0-9]+]]
  for (; (i % 2) || (i > 0); --i);

  // PGOGEN-NOT: store {{.*}} @[[BLC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @conditional_operator()
// PGOUSE-LABEL: @conditional_operator()
// PGOGEN: store {{.*}} @[[COC]], i64 0, i64 0
void conditional_operator() {
  int i = 100;

  // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[CO1:[0-9]+]]
  int j = i < 50 ? i : 1;

  // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 2
  // PGOUSE: br {{.*}} !prof ![[CO2:[0-9]+]]
  int k = i ?: 0;

  // PGOGEN-NOT: store {{.*}} @[[COC]],
  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
}

// PGOGEN-LABEL: @do_fallthrough()
// PGOUSE-LABEL: @do_fallthrough()
// PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 0
void do_fallthrough() {
  // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[DF1:[0-9]+]]
  for (int i = 0; i < 10; ++i) {
    int j = 0;
    // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 2
    do {
      // The number of exits out of this do-loop via the break statement
      // exceeds the counter value for the loop (which does not include the
      // fallthrough count). Make sure that does not violate any assertions.
      // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 3
      // PGOUSE: br {{.*}} !prof ![[DF3:[0-9]+]]
      if (i < 8) break;
      j++;
    // PGOUSE: br {{.*}} !prof ![[DF2:[0-9]+]]
    } while (j < 2);
  }
}

// PGOGEN-LABEL: @static_func()
// PGOUSE-LABEL: @static_func()
// PGOGEN: store {{.*}} @[[STC]], i64 0, i64 0
static void static_func() {
  // PGOGEN: store {{.*}} @[[STC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[ST1:[0-9]+]]
  for (int i = 0; i < 10; ++i) {
  }
}

// PGOUSE-DAG: ![[SL1]] = !{!"branch_weights", i32 101, i32 2}
// PGOUSE-DAG: ![[SL2]] = !{!"branch_weights", i32 101, i32 2}
// PGOUSE-DAG: ![[SL3]] = !{!"branch_weights", i32 76, i32 2}

// PGOUSE-DAG: ![[EE1]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[EE2]] = !{!"branch_weights", i32 52, i32 1}
// PGOUSE-DAG: ![[EE3]] = !{!"branch_weights", i32 2, i32 51}
// PGOUSE-DAG: ![[EE4]] = !{!"branch_weights", i32 26, i32 26}
// PGOUSE-DAG: ![[EE5]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[EE6]] = !{!"branch_weights", i32 2, i32 26}
// PGOUSE-DAG: ![[EE7]] = !{!"branch_weights", i32 26, i32 1}

// PGOUSE-DAG: ![[IF1]] = !{!"branch_weights", i32 101, i32 2}
// PGOUSE-DAG: ![[IF2]] = !{!"branch_weights", i32 51, i32 51}
// PGOUSE-DAG: ![[IF3]] = !{!"branch_weights", i32 51, i32 1}
// PGOUSE-DAG: ![[IF4]] = !{!"branch_weights", i32 34, i32 18}
// PGOUSE-DAG: ![[IF5]] = !{!"branch_weights", i32 34, i32 1}
// PGOUSE-DAG: ![[IF6]] = !{!"branch_weights", i32 17, i32 2}
// PGOUSE-DAG: ![[IF7]] = !{!"branch_weights", i32 100, i32 2}
// PGOUSE-DAG: ![[IF8]] = !{!"branch_weights", i32 100, i32 2}

// PGOUSE-DAG: ![[JM1]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[JM2]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[JM3]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[JM4]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[JM5]] = !{!"branch_weights", i32 3, i32 2}
// PGOUSE-DAG: ![[JM6]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[JM7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2}
// PGOUSE-DAG: ![[JM8]] = !{!"branch_weights", i32 11, i32 2}
// PGOUSE-DAG: ![[JM9]] = !{!"branch_weights", i32 10, i32 2}

// PGOUSE-DAG: ![[SW1]] = !{!"branch_weights", i32 16, i32 1}
// PGOUSE-DAG: ![[SW2]] = !{!"branch_weights", i32 6, i32 2, i32 3, i32 4, i32 5}
// PGOUSE-DAG: ![[SW3]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[SW4]] = !{!"branch_weights", i32 3, i32 2}
// PGOUSE-DAG: ![[SW5]] = !{!"branch_weights", i32 4, i32 1}
// PGOUSE-DAG: ![[SW6]] = !{!"branch_weights", i32 5, i32 1}
// PGOUSE-DAG: ![[SW7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2, i32 2}
// PGOUSE-DAG: ![[SW8]] = !{!"branch_weights", i32 5, i32 1}
// PGOUSE-DAG: ![[SW9]] = !{!"branch_weights", i32 2, i32 5}

// PGOUSE-DAG: ![[BS1]] = !{!"branch_weights", i32 33, i32 2}
// PGOUSE-DAG: ![[BS2]] = !{!"branch_weights", i32 29, i32 2, i32 2, i32 2, i32 2, i32 1}
// PGOUSE-DAG: ![[BS3]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[BS4]] = !{!"branch_weights", i32 2, i32 2}
// PGOUSE-DAG: ![[BS5]] = !{!"branch_weights", i32 12, i32 1}
// PGOUSE-DAG: ![[BS6]] = !{!"branch_weights", i32 12, i32 3}
// PGOUSE-DAG: ![[BS7]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[BS8]] = !{!"branch_weights", i32 16, i32 1}
// PGOUSE-DAG: ![[BS9]] = !{!"branch_weights", i32 16, i32 14}
// PGOUSE-DAG: ![[BS10]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[BS11]] = !{!"branch_weights", i32 3, i32 1}

// PGOUSE-DAG: ![[BO1]] = !{!"branch_weights", i32 101, i32 2}
// PGOUSE-DAG: ![[BO2]] = !{!"branch_weights", i32 67, i32 35}
// PGOUSE-DAG: ![[BO3]] = !{!"branch_weights", i32 67, i32 35}
// PGOUSE-DAG: ![[BO4]] = !{!"branch_weights", i32 67, i32 35}
// PGOUSE-DAG: ![[BO5]] = !{!"branch_weights", i32 18, i32 18}
// PGOUSE-DAG: ![[BO6]] = !{!"branch_weights", i32 51, i32 51}
// PGOUSE-DAG: ![[BO7]] = !{!"branch_weights", i32 34, i32 18}
// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 52, i32 1}
// PGOUSE-DAG: ![[BL2]] = !{!"branch_weights", i32 51, i32 2}
// PGOUSE-DAG: ![[BL3]] = !{!"branch_weights", i32 26, i32 27}
// PGOUSE-DAG: ![[BL4]] = !{!"branch_weights", i32 51, i32 2}
// PGOUSE-DAG: ![[BL5]] = !{!"branch_weights", i32 52, i32 1}
// PGOUSE-DAG: ![[BL6]] = !{!"branch_weights", i32 51, i32 2}
// PGOUSE-DAG: ![[BL7]] = !{!"branch_weights", i32 26, i32 27}
// PGOUSE-DAG: ![[BL8]] = !{!"branch_weights", i32 51, i32 2}
// PGOUSE-DAG: ![[CO1]] = !{!"branch_weights", i32 1, i32 2}
// PGOUSE-DAG: ![[CO2]] = !{!"branch_weights", i32 2, i32 1}

// PGOUSE-DAG: ![[DF1]] = !{!"branch_weights", i32 11, i32 2}
// PGOUSE-DAG: ![[DF2]] = !{!"branch_weights", i32 3, i32 3}
// PGOUSE-DAG: ![[DF3]] = !{!"branch_weights", i32 9, i32 5}

// PGOUSE-DAG: ![[ST1]] = !{!"branch_weights", i32 11, i32 2}

int main(int argc, const char *argv[]) {
  simple_loops();
  conditionals();
  early_exits();
  jumps();
  switches();
  big_switch();
  boolean_operators();
  boolop_loops();
  conditional_operator();
  do_fallthrough();
  static_func();
  return 0;
}