int fact(int n) {
  do {
    asm goto("0: "
             ".byte 0x0f, 0x1f, 0x44, 0x00, 0x00;"
             ".pushsection trace_table, \"a\";"
             ".quad "
             "fact_entry"
             ", 0b, %l0;"
             ".popsection"
             :
             :
             :
             : __lbl_fact_entry);
    if (0) {
    __lbl_fact_entry:
      printf("fact(%d)\n", n);
    }
  } while (0);
  int out = 1;
  if (n > 1)
    out = n * fact(n - 1);
  do {
    asm goto("0: "
             ".byte 0x0f, 0x1f, 0x44, 0x00, 0x00;"
             ".pushsection trace_table, \"a\";"
             ".quad "
             "fact_exit"
             ", 0b, %l0;"
             ".popsection"
             :
             :
             :
             : __lbl_fact_exit);
    if (0) {
    __lbl_fact_exit:
      printf("fact(%d) = %d\n", n, out);
    }
  } while (0);
  return out;
}


x86 assembly (clang, -O0):
<fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
nopl   0x0(%rax,%rax,1)
jmp    1135 <fact+0x15>
xor    %eax,%eax
test   $0x1,%al
jne    1144 <fact+0x24>
jmp    115a <fact+0x3a>
jmp    1149 <fact+0x29>
mov    -0x4(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115f <fact+0x3f>
movl   $0x1,-0x8(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    118c <fact+0x6c>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1040 <fact@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <fact+0x71>
nopl   0x0(%rax,%rax,1)
jmp    119b <fact+0x7b>
xor    %eax,%eax
test   $0x1,%al
jne    11aa <fact+0x8a>
jmp    11c3 <fact+0xa3>
jmp    11af <fact+0x8f>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c8 <fact+0xa8>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fact>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x1,%ebp
cmp    $0x2,%ebx
jl     1141 <fact+0x21>
lea    -0x1(%rbx),%edi
call   1040 <fact@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    112a <fact+0xa>
lea    0xea2(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1146 <fact+0x26>

LLVM IR (-O0):
@.str = [10 x i8] c"fact(%d)\0A\00"
@.str.1 = [15 x i8] c"fact(%d) = %d\0A\00"
define i32 @fact(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
br label %4
4: ; preds = %1
to label %5 [label %7]
5: ; preds = %4
br i1 false, label %6, label %10
6: ; preds = %5
br label %7
7: ; preds = %6, %4
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %7, %5
br label %11
11: ; preds = %10
store i32 1, i32* %3
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %2
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 1
%18 = call i32 @fact(i32 %17)
%19 = mul nsw i32 %15, %18
store i32 %19, i32* %3
br label %20
20: ; preds = %14, %11
br label %21
21: ; preds = %20
to label %22 [label %24]
22: ; preds = %21
br i1 false, label %23, label %28
23: ; preds = %22
br label %24
24: ; preds = %23, %21
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %24, %22
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [10 x i8] c"fact(%d)\0A\00"
@.str.1 = [15 x i8] c"fact(%d) = %d\0A\00"
define i32 @fact(i32 %0) {
to label %4 [label %2]
2: ; preds = %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %4
4: ; preds = %2, %1
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = add nsw i32 %0, -1
%8 = tail call i32 @fact(i32 %7)
%9 = mul nsw i32 %8, %0
br label %10
10: ; preds = %4, %6
%11 = phi i32 [ %9, %6 ], [ 1, %4 ]
to label %14 [label %12]
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %11)
br label %14
14: ; preds = %12, %10
ret i32 %11
}