#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 = 0; n < 20; n++) {
    int f;
    int result = fac(&f, n);
    printf("r=%2d n=%10d f=%10d\n", result, n, f);
  }
  for (i = 0, n = 0; i < 1000; i++, n = 2 * n + 1) {
    int f;
    int result = fac(&f, n);
    printf("i=%4d r=%2d n=%10d f=%10d\n", i, result, n, f);
  }
  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   $0x0,-0x18(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    117b <main+0x5b>
mov    -0x18(%rbp),%esi
lea    -0x1c(%rbp),%rdi
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    11da <main+0xba>
mov    -0x18(%rbp),%esi
lea    -0x24(%rbp),%rdi
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>
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
lea    0x4(%rsp),%r14
lea    0xed3(%rip),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
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
lea    0xe92(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
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
add    %ebx,%ebx
add    $0x1,%ebx
cmp    $0x3e8,%ebp
jne    1180 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"r=%2d n=%10d f=%10d\0A\00"
@.str.1 = [27 x i8] c"i=%4d r=%2d 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 0, 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* %8, i32 %16)
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 ([21 x i8], [21 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 = %37, %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 1000
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = load i32, i32* %7
%31 = call i32 @fac(i32* %10, i32 %30)
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 ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33, i32 %34, i32 %35)
br label %37
37: ; preds = %29
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
%40 = load i32, i32* %7
%41 = mul nsw i32 2, %40
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %26
43: ; preds = %26
ret i32 0
}

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