Compiler projects using llvm
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t --skip-symbolization
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE
; RUN: llvm-profgen --format=text --use-dwarf-correlation --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t --skip-symbolization
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe.perfbin --output=%t1
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe.perfbin --output=%t1 --update-total-samples
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK-UPDATE-TOTAL-SAMPLE
; RUN: llvm-profgen --format=text --use-dwarf-correlation --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
; RUN: echo -e "0\n0" > %t
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe.perfbin --output=%t1 --fill-zero-for-all-funcs
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK-ALL-ZERO
; RUN: llvm-profgen --format=text --unsymbolized-profile=%S/Inputs/out-of-bounds.raw.prof --binary=%S/Inputs/inline-noprobe.perfbin --output=%t1
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK-OB

CHECK: main:2609:0
CHECK:  0: 0
CHECK:  2: 0
CHECK:  1: foo:2609
CHECK:   2.1: 42
CHECK:   3: 62
CHECK:   3.2: 21
CHECK:   4: 0
CHECK:   65526: 62
CHECK:   3.1: bar:546
CHECK:    1: 42
CHECK:    65533: 42
CHECK:   3.2: bar:189
CHECK:    1: 21

CHECK-UPDATE-TOTAL-SAMPLE: main:292:0
CHECK-UPDATE-TOTAL-SAMPLE:  0: 0
CHECK-UPDATE-TOTAL-SAMPLE:  2: 0
CHECK-UPDATE-TOTAL-SAMPLE:  1: foo:292
CHECK-UPDATE-TOTAL-SAMPLE:   2.1: 42
CHECK-UPDATE-TOTAL-SAMPLE:   3: 62
CHECK-UPDATE-TOTAL-SAMPLE:   3.2: 21
CHECK-UPDATE-TOTAL-SAMPLE:   4: 0
CHECK-UPDATE-TOTAL-SAMPLE:   65526: 62
CHECK-UPDATE-TOTAL-SAMPLE:   3.1: bar:84
CHECK-UPDATE-TOTAL-SAMPLE:    1: 42
CHECK-UPDATE-TOTAL-SAMPLE:    65533: 42
CHECK-UPDATE-TOTAL-SAMPLE:   3.2: bar:21
CHECK-UPDATE-TOTAL-SAMPLE:    1: 21

CHECK-ALL-ZERO: bar:0:0
CHECK-ALL-ZERO:  1: 0
CHECK-ALL-ZERO:  5: 0
CHECK-ALL-ZERO: foo:0:0
CHECK-ALL-ZERO:  0: 0
CHECK-ALL-ZERO:  2.1: 0
CHECK-ALL-ZERO:  3: 0
CHECK-ALL-ZERO:  3.2: 0
CHECK-ALL-ZERO:  4: 0
CHECK-ALL-ZERO:  3.1: bar:0
CHECK-ALL-ZERO:   1: 0
CHECK-ALL-ZERO:  3.2: bar:0
CHECK-ALL-ZERO:   1: 0
CHECK-ALL-ZERO:   7: 0
CHECK-ALL-ZERO: main:0:0
CHECK-ALL-ZERO:  0: 0
CHECK-ALL-ZERO:  2: 0
CHECK-ALL-ZERO:  1: foo:0
CHECK-ALL-ZERO:   2.1: 0
CHECK-ALL-ZERO:   3: 0
CHECK-ALL-ZERO:   3.2: 0
CHECK-ALL-ZERO:   4: 0
CHECK-ALL-ZERO:   3.1: bar:0
CHECK-ALL-ZERO:    1: 0
CHECK-ALL-ZERO:   3.2: bar:0
CHECK-ALL-ZERO:    1: 0

CHECK-RAW-PROFILE:      3
CHECK-RAW-PROFILE-NEXT: 650-691:21
CHECK-RAW-PROFILE-NEXT: 669-677:20
CHECK-RAW-PROFILE-NEXT: 669-691:21
CHECK-RAW-PROFILE-NEXT: 2
CHECK-RAW-PROFILE-NEXT: 677->650:21
CHECK-RAW-PROFILE-NEXT: 691->669:43

;CHECK-OB: foo:114:0
;CHECK-OB:  0: 1
;CHECK-OB:  2.1: 1
;CHECK-OB:  3: 1
;CHECK-OB:  3.2: 1
;CHECK-OB:  4: 1
;CHECK-OB:  3.1: bar:13
;CHECK-OB:   1: 1
;CHECK-OB:   65533: 1
;CHECK-OB:  3.2: bar:24
;CHECK-OB:   1: 1
;CHECK-OB:   7: 1
;CHECK-OB: main:100:0
;CHECK-OB:  0: 1
;CHECK-OB:  2: 1
;CHECK-OB:  1: foo:80
;CHECK-OB:   2.1: 1
;CHECK-OB:   3: 1
;CHECK-OB:   3.2: 1
;CHECK-OB:   4: 1
;CHECK-OB:   65526: 1
;CHECK-OB:   3.1: bar:13
;CHECK-OB:    1: 1
;CHECK-OB:    65533: 1
;CHECK-OB:   3.2: bar:9
;CHECK-OB:    1: 1
;CHECK-OB: bar:14:0
;CHECK-OB:  1: 1
;CHECK-OB:  5: 1

; original code:
; clang -O3 -g -fdebug-info-for-profiling test.c -o a.out
#include <stdio.h>

int bar(int x, int y) {
  if (x % 2) {
    return x - y;
  }
  return x + y;
}

void foo() {
  int s, i = 0;
  while (i++ < 4000 * 4000)
    if (i % 3) s = bar(i, s); else s += bar(s, i);
  printf("sum is %d\n", s);
}

int main() {
  foo();
  return 0;
}