#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int atoi(char const *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int nCr(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  int k = 0;
  int n;
  int c;
  struct timeval start, end;
  if (argv[1][0] == '-' && argv[1][1] == 'h') {
    printf("Usage: formula <positive integer>");
  } else {
    n = atoi(argv[1]);
    gettimeofday(&start, NULL);
    printf("(1 + x)^%i = ", n);
    if (n == 0)
      printf("0");
    for (; k <= n; k++) {
      c = nCr(n, k);
      if (c == -1) {
        printf("Multiplication overflow. \n");
        return 1;
      } else {
        if (k != 0)
          printf("%i x^%i ", c, k);
        if (k != n && k != 0)
          printf("+ ");
      }
    }
    gettimeofday(&end, NULL);
  }
  printf("\n%ld microseconds\n", ((end.tv_sec * 1000000 + end.tv_usec) -
                                  (start.tv_sec * 1000000 + start.tv_usec)));
  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,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1199 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
jne    1199 <main+0x59>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1289 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11df <main+0x9f>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e4 <main+0xa4>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     127c <main+0x13c>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <nCr@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1222 <main+0xe2>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b4 <main+0x174>
cmpl   $0x0,-0x14(%rbp)
je     1240 <main+0x100>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1264 <main+0x124>
cmpl   $0x0,-0x14(%rbp)
je     1264 <main+0x124>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1269 <main+0x129>
jmp    126e <main+0x12e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e4 <main+0xa4>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x30(%rbp),%esi
add    -0x2c(%rbp),%esi
imul   $0xf4240,-0x28(%rbp),%eax
add    -0x24(%rbp),%eax
sub    %eax,%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    117f <main+0x1f>
cmpb   $0x68,0x1(%rdi)
je     1258 <main+0xf8>
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0xe89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
je     11db <main+0x7b>
jns    11e5 <main+0x85>
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%esi
sub    0x8(%rsp),%eax
imul   $0xf4240,%eax,%eax
sub    0xc(%rsp),%esi
add    %eax,%esi
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1249 <main+0xe9>
mov    $0x30,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%r12d
lea    0xe40(%rip),%r14
lea    0xe42(%rip),%r15
xor    %ebp,%ebp
jmp    1208 <main+0xa8>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%r12d
je     11a8 <main+0x48>
mov    %ebx,%edi
mov    %ebp,%esi
call   1070 <nCr@plt>
cmp    $0xffffffff,%eax
je     1238 <main+0xd8>
test   %ebp,%ebp
je     1200 <main+0xa0>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebp,%ebx
je     1200 <main+0xa0>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1200 <main+0xa0>
lea    0xe10(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [34 x i8] c"Usage: formula <positive integer>\00"
@.str.1 = [14 x i8] c"(1 + x)^%i = \00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [27 x i8] c"Multiplication overflow. \0A\00"
@.str.4 = [9 x i8] c"%i x^%i \00"
@.str.5 = [3 x i8] c"+ \00"
@.str.6 = [19 x i8] c"\0A%ld microseconds\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 %struct.timeval
%10 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %28
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 104
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %76
28: ; preds = %18, %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %7
%33 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %28
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %28
br label %41
41: ; preds = %71, %40
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = icmp sle i32 %42, %43
br i1 %44, label %45, label %74
45: ; preds = %41
%46 = load i32, i32* %7
%47 = load i32, i32* %6
%48 = call i32 @nCr(i32 %46, i32 %47)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %91
53: ; preds = %45
%54 = load i32, i32* %6
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = load i32, i32* %8
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %57, i32 %58)
br label %60
60: ; preds = %56, %53
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = icmp ne i32 %61, %62
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i32, i32* %6
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %67, %64, %60
br label %70
70: ; preds = %69
br label %71
71: ; preds = %70
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %41
74: ; preds = %41
%75 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
br label %76
76: ; preds = %74, %26
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%78 = load i32, i32* %77
%79 = mul nsw i32 %78, 1000000
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%81 = load i32, i32* %80
%82 = add nsw i32 %79, %81
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%84 = load i32, i32* %83
%85 = mul nsw i32 %84, 1000000
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%87 = load i32, i32* %86
%88 = add nsw i32 %85, %87
%89 = sub nsw i32 %82, %88
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %89)
store i32 0, i32* %3
br label %91
91: ; preds = %76, %51
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [34 x i8] c"Usage: formula <positive integer>\00"
@.str.1 = [14 x i8] c"(1 + x)^%i = \00"
@.str.4 = [9 x i8] c"%i x^%i \00"
@.str.5 = [3 x i8] c"+ \00"
@.str.6 = [19 x i8] c"\0A%ld microseconds\0A\00"
@str = [26 x i8] c"Multiplication overflow. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 104
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
unreachable
17: ; preds = %11, %2
%18 = tail call i32 @atoi(i8* %8)
%19 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%21 = icmp eq i32 %18, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @putchar(i32 48)
br label %26
24: ; preds = %17
%25 = icmp slt i32 %18, 0
br i1 %25, label %43, label %26
26: ; preds = %22, %24
br label %27
27: ; preds = %26, %40
%28 = phi i32 [ %41, %40 ], [ 0, %26 ]
%29 = tail call i32 @nCr(i32 %18, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %58
33: ; preds = %27
%34 = icmp eq i32 %28, 0
br i1 %34, label %40, label %35
35: ; preds = %33
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %28)
%37 = icmp eq i32 %28, %18
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %40
40: ; preds = %33, %38, %35
%41 = add nuw i32 %28, 1
%42 = icmp eq i32 %28, %18
br i1 %42, label %43, label %27
43: ; preds = %40, %24
%44 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%52 = load i32, i32* %51
%53 = sub i32 %46, %50
%54 = mul i32 %53, 1000000
%55 = sub i32 %48, %52
%56 = add i32 %55, %54
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %43, %31
%59 = phi i32 [ 0, %43 ], [ 1, %31 ]
ret i32 %59
}