#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ crash_me();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int *, int *);
int /*<<< orphan*/ stderr;
int64_t fact(int n) {
  int one = 1;
  fprintf(stderr, "--fact arg: %p stackvar: %p\n", &n, &one);
  if (n == 1) {
    crash_me();
    return 1;
  }
  return n * fact(n - 1);
}


x86 assembly (clang, -O0):
<fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1030 <fprintf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    117c <fact+0x4c>
mov    $0x0,%al
call   1050 <crash_me@plt>
movl   $0x1,-0x4(%rbp)
jmp    1198 <fact+0x68>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fact@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fact>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0x8(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1030 <fprintf@plt>
mov    0x8(%rsp),%ebx
cmp    $0x1,%ebx
jne    1177 <fact+0x47>
xor    %eax,%eax
call   1050 <crash_me@plt>
mov    $0x1,%eax
jmp    1182 <fact+0x52>
lea    -0x1(%rbx),%edi
call   1040 <fact@plt>
imul   %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"--fact arg: %p stackvar: %p\0A\00"
define i32 @fact(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (...) @crash_me()
store i32 1, i32* %2
br label %17
11: ; preds = %1
%12 = load i32, i32* %3
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 1
%15 = call i32 @fact(i32 %14)
%16 = mul nsw i32 %12, %15
store i32 %16, i32* %2
br label %17
17: ; preds = %11, %9
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"--fact arg: %p stackvar: %p\0A\00"
define i32 @fact(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (...) @crash_me()
br label %15
11: ; preds = %1
%12 = add nsw i32 %7, -1
%13 = call i32 @fact(i32 %12)
%14 = mul nsw i32 %13, %7
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ 1, %9 ], [ %14, %11 ]
ret i32 %16
}