Compiler projects using llvm
; RUN: llvm-profgen --format=text --perfscript=%s  --binary=%S/Inputs/inline-cs-pseudoprobe.perfbin --output=%t --show-pseudo-probe --show-disassembly-only | FileCheck %s
; RUN: llvm-profgen --format=text --perfscript=%s  --binary=%S/Inputs/inline-cs-pseudoprobe.perfbin --output=%t --show-pseudo-probe --show-disassembly-only --disassemble-functions=main,foo  | FileCheck %s -check-prefix=SYM

PERF_RECORD_MMAP2 2854748/2854748: [0x400000(0x1000) @ 0 00:1d 123291722 526021]: r-xp /home/inline-cs-pseudoprobe.perfbin

; CHECK: Pseudo Probe Desc:
; CHECK: GUID: 6699318081062747564 Name: foo
; CHECK: Hash: 563088904013236
; CHECK: GUID: 15822663052811949562 Name: main
; CHECK: Hash: 281479271677951
; CHECK: GUID: 16434608426314478903 Name: bar
; CHECK: Hash: 72617220756



; CHECK:      <bar>:

; CHECK:       [Probe]: FUNC: bar Index: 1  Type: Block
; CHECK-NEXT:  [Probe]: FUNC: bar Index: 4  Type: Block
; CHECK-NEXT:      754: imull $2863311531, %edi, %eax

; CHECK:      <foo>:
; CHECK:       [Probe]: FUNC: foo Index: 1  Type: Block
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 2  Type: Block
; CHECK-NEXT:      770: movl  $1, %ecx

; CHECK:       [Probe]: FUNC: foo Index: 5  Type: Block
; CHECK-NEXT:      780: addl  $30, %esi
; CHECK:       [Probe]: FUNC: foo Index: 6  Type: Block
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 2  Type: Block
; CHECK-NEXT:      783: addl  $1, %ecx

; CHECK:       [Probe]: FUNC: foo Index: 3  Type: Block
; CHECK-NEXT:      78e:	movl	%ecx, %edx

; CHECK:       [Probe]: FUNC: foo Index: 4  Type: Block
; CHECK-NEXT:  [Probe]: FUNC: bar Index: 1  Type: Block  Inlined: @ foo:8
; CHECK-NEXT:  [Probe]:	FUNC: bar Index: 4  Type: Block  Inlined: @ foo:8
; CHECK-NEXT:      7bf: addl  %ecx, %edx


; CHECK:       [Probe]: FUNC: foo Index: 6  Type: Block
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 2  Type: Block
; CHECK-NEXT:      7cf:	addl	$1, %ecx

; CHECK:       [Probe]: FUNC: foo Index: 7  Type: Block
; CHECK-NEXT:      7de: movl  $2098432, %edi

; CHECK:       [Probe]: FUNC: foo Index: 9  Type: DirectCall
; CHECK-NEXT:      7e5: callq 0x930


; CHECK:      <main>:
; CHECK:       [Probe]: FUNC: main Index: 1  Type: Block
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 1  Type: Block  Inlined: @ main:2
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 2  Type: Block  Inlined: @ main:2
; CHECK-NEXT:      7f0: movl  $1, %ecx

; CHECK:       [Probe]: FUNC: foo Index: 5  Type: Block  Inlined: @ main:2
; CHECK-NEXT:      800: addl  $30, %esi
; CHECK:       [Probe]: FUNC: foo Index: 6  Type: Block  Inlined: @ main:2
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 2  Type: Block  Inlined: @ main:2
; CHECK-NEXT:      803: addl  $1, %ecx

; CHECK:       [Probe]: FUNC: foo Index: 3  Type: Block  Inlined: @ main:2
; CHECK-NEXT:      80e:	movl	%ecx, %edx

; CHECK:       [Probe]: FUNC: foo Index: 4  Type: Block  Inlined: @ main:2
; CHECK-NEXT:  [Probe]: FUNC: bar Index: 1  Type: Block  Inlined: @ main:2 @ foo:8
; CHECK-NEXT:  [Probe]:	FUNC: bar Index: 4  Type: Block  Inlined: @ main:2 @ foo:8
; CHECK-NEXT:      83f: addl  %ecx, %edx

; CHECK:       [Probe]: FUNC: foo Index: 6  Type: Block  Inlined: @ main:2
; CHECK-NEXT:  [Probe]: FUNC: foo Index: 2  Type: Block  Inlined: @ main:2
; CHECK-NEXT:      84f: addl  $1, %ecx

; CHECK:       [Probe]: FUNC: foo Index: 7  Type: Block  Inlined: @ main:2
; CHECK-NEXT:      85e: movl  $2098432, %edi

; CHECK:       [Probe]: FUNC: foo Index: 9  Type: DirectCall  Inlined: @ main:2
; CHECK-NEXT:      865: callq 0x930

; SYM-NOT: <bar>:
; SYM: <foo>:
; SYM: <main>:



; clang -O3 -fuse-ld=lld -fpseudo-probe-for-profiling
; -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Xclang -mdisable-tail-calls
; -g test.c  -o a.out

#include <stdio.h>

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

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

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