#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 */

/* Variables and functions */
int fac(int, int *);
int /*<<< orphan*/ printf(char *, int, int, int, ...);
int main(int argc, char *argv[]) {
  int i;
  int n;
  for (n = -1; n < 20; n++) {
    int f;
    int r = fac(n, &f);
    printf("r=%02d n=%10d f=%10d\n", r, n, f);
  }
  for (i = 0, n = 0; i < 1000; i++, n = 2 * n + 1) {
    int f;
    int r = fac(n, &f);
    printf("i=%4d r=%02d n=%10d f=%10d\n", i, r, n, f);
    if (n < 0) {
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    117b <main+0x5b>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <fac@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <main+0x1d>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    11ee <main+0xce>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <fac@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jge    11cf <main+0xaf>
jmp    11ee <main+0xce>
jmp    11d4 <main+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <main+0x69>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
lea    0x4(%rsp),%r14
lea    0xece(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <fac@plt>
mov    0x4(%rsp),%ecx
mov    %rbp,%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x14,%ebx
jne    1140 <main+0x20>
mov    %rsp,%r14
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <fac@plt>
mov    (%rsp),%r8d
lea    0xe84(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %ebx,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <fac@plt>
mov    (%rsp),%r8d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0x21,%ebp
jne    11a0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"r=%02d n=%10d f=%10d\0A\00"
@.str.1 = [28 x i8] c"i=%4d r=%02d n=%10d f=%10d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 20
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %7
%17 = call i32 @fac(i32 %16, i32* %8)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %12
25: ; preds = %12
store i32 0, i32* %6
store i32 0, i32* %7
br label %26
26: ; preds = %41, %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 1000
br i1 %28, label %29, label %47
29: ; preds = %26
%30 = load i32, i32* %7
%31 = call i32 @fac(i32 %30, i32* %10)
store i32 %31, i32* %11
%32 = load i32, i32* %6
%33 = load i32, i32* %11
%34 = load i32, i32* %7
%35 = load i32, i32* %10
%36 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %29
br label %47
40: ; preds = %29
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
%44 = load i32, i32* %7
%45 = mul nsw i32 2, %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %26
47: ; preds = %39, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"r=%02d n=%10d f=%10d\0A\00"
@.str.1 = [28 x i8] c"i=%4d r=%02d n=%10d f=%10d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
br label %11
6: ; preds = %11
%7 = bitcast i32* %4 to i8*
%8 = call i32 @fac(i32 0, i32* %4)
%9 = load i32, i32* %4
%10 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %8, i32 0, i32 %9)
br label %18
11: ; preds = %2, %11
%12 = phi i32 [ -1, %2 ], [ %16, %11 ]
%13 = call i32 @fac(i32 %12, i32* %3)
%14 = load i32, i32* %3
%15 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %12, i32 %14)
%16 = add nsw i32 %12, 1
%17 = icmp eq i32 %16, 20
br i1 %17, label %6, label %11
18: ; preds = %6, %18
%19 = phi i32 [ 0, %6 ], [ %23, %18 ]
%20 = phi i32 [ 0, %6 ], [ %21, %18 ]
%21 = add nuw nsw i32 %20, 1
%22 = shl nuw nsw i32 %19, 1
%23 = or i32 %22, 1
%24 = call i32 @fac(i32 %23, i32* %4)
%25 = load i32, i32* %4
%26 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %24, i32 %23, i32 %25)
%27 = icmp eq i32 %21, 32
br i1 %27, label %28, label %18
28: ; preds = %18
ret i32 0
}