#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 */
long iterativeFactorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int main() {
  long int number, fact1, fact2, fact3;
  printf("Pascal's Triangle \n");
  printf("\n");
  printf("Enter a Whole Number (max. 12): ");
  scanf("%ld", &number);
  printf("\n");
  if (number > 12) {
    printf("Number > 12 \n");
    printf("\n");
    return 1;
  }
  for (int i = 0; i <= number; i++) {
    fact1 = iterativeFactorial(i);
    for (int j = number; j > i; j--) {
      printf("   ");
    }
    for (int j = 0; j <= i; j++) {
      int k;
      k = i - j;
      fact2 = iterativeFactorial(k);
      fact3 = iterativeFactorial(j);
      printf("%03ld   ", (fact1 / (fact2 * fact3)));
    }
    printf("\n");
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0xc,-0x10(%rbp)
jle    11ba <main+0x8a>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <main+0x170>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     128b <main+0x15b>
mov    -0x2c(%rbp),%edi
call   1030 <iterativeFactorial@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    120a <main+0xda>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    11e2 <main+0xb2>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     126f <main+0x13f>
mov    -0x2c(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1030 <iterativeFactorial@plt>
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%edi
call   1030 <iterativeFactorial@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
imul   -0x28(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1211 <main+0xe1>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c1 <main+0x91>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xecc(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe88(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    (%rsp),%rax
cmp    $0xc,%rax
jle    11ba <main+0x6a>
lea    0xe96(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebx
jmp    12a2 <main+0x152>
test   %rax,%rax
js     12a2 <main+0x152>
lea    0xe60(%rip),%r14
lea    0xe54(%rip),%r15
xor    %r12d,%r12d
jmp    11ff <main+0xaf>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r12
cmp    %r12,(%rsp)
lea    0xe31(%rip),%r14
jl     12a0 <main+0x150>
mov    %r12d,%edi
call   1030 <iterativeFactorial@plt>
mov    %rax,%r13
mov    (%rsp),%rbx
movslq %ebx,%rax
cmp    %rax,%r12
jge    1240 <main+0xf0>
add    $0xffffffff,%ebx
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movslq %ebx,%rax
lea    -0x1(%rax),%ebx
cmp    %rax,%r12
jl     1220 <main+0xd0>
mov    %r12d,%ebx
jmp    1271 <main+0x121>
nopl   0x0(%rax)
mov    %r12d,%ebx
xor    %ebp,%ebp
jmp    1271 <main+0x121>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rax
cqto
idiv   %rcx
mov    %rax,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebp
add    $0xffffffff,%ebx
jae    11e0 <main+0x90>
mov    %ebx,%edi
call   1030 <iterativeFactorial@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1030 <iterativeFactorial@plt>
mov    %rax,%rcx
imul   %r14,%rcx
mov    %r13,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1250 <main+0x100>
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
jmp    125b <main+0x10b>
xor    %ebx,%ebx
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Pascal's Triangle \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [33 x i8] c"Enter a Whole Number (max. 12): \00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [14 x i8] c"Number > 12 \0A\00"
@.str.5 = [4 x i8] c" \00"
@.str.6 = [9 x i8] c"%03ld \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %2)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = load i64, i64* %2
%16 = icmp sgt i64 %15, 12
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %69
20: ; preds = %0
store i32 0, i32* %6
br label %21
21: ; preds = %64, %20
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = load i64, i64* %2
%25 = icmp sle i64 %23, %24
br i1 %25, label %26, label %67
26: ; preds = %21
%27 = load i32, i32* %6
%28 = call i64 @iterativeFactorial(i32 %27)
store i64 %28, i64* %3
%29 = load i64, i64* %2
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
br label %31
31: ; preds = %37, %26
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35
%38 = load i32, i32* %7
%39 = add nsw i32 %38, -1
store i32 %39, i32* %7
br label %31
40: ; preds = %31
store i32 0, i32* %8
br label %41
41: ; preds = %59, %40
%42 = load i32, i32* %8
%43 = load i32, i32* %6
%44 = icmp sle i32 %42, %43
br i1 %44, label %45, label %62
45: ; preds = %41
%46 = load i32, i32* %6
%47 = load i32, i32* %8
%48 = sub nsw i32 %46, %47
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = call i64 @iterativeFactorial(i32 %49)
store i64 %50, i64* %4
%51 = load i32, i32* %8
%52 = call i64 @iterativeFactorial(i32 %51)
store i64 %52, i64* %5
%53 = load i64, i64* %3
%54 = load i64, i64* %4
%55 = load i64, i64* %5
%56 = mul nsw i64 %54, %55
%57 = sdiv i64 %53, %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %57)
br label %59
59: ; preds = %45
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %41
62: ; preds = %41
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %64
64: ; preds = %62
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %21
67: ; preds = %21
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %69
69: ; preds = %67, %17
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@.str.2 = [33 x i8] c"Enter a Whole Number (max. 12): \00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.5 = [4 x i8] c" \00"
@.str.6 = [9 x i8] c"%03ld \00"
@str = [19 x i8] c"Pascal's Triangle \00"
@str.7 = [13 x i8] c"Number > 12 \00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @putchar(i32 10)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%7 = call i32 @putchar(i32 10)
%8 = load i64, i64* %1
%9 = icmp sgt i64 %8, 12
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = icmp slt i64 %8, 0
br i1 %11, label %48, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %48
14: ; preds = %10, %32
%15 = phi i64 [ %34, %32 ], [ 0, %10 ]
%16 = phi i32 [ %37, %32 ], [ 1, %10 ]
%17 = trunc i64 %15 to i32
%18 = call i64 @iterativeFactorial(i32 %17)
%19 = load i64, i64* %1
%20 = shl i64 %19, 32
%21 = ashr exact i64 %20, 32
%22 = icmp slt i64 %15, %21
br i1 %22, label %24, label %23
23: ; preds = %26, %14
br label %38
24: ; preds = %14
%25 = trunc i64 %19 to i32
br label %26
26: ; preds = %24, %26
%27 = phi i32 [ %29, %26 ], [ %25, %24 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%29 = add nsw i32 %27, -1
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %15, %30
br i1 %31, label %26, label %23
32: ; preds = %38
%33 = call i32 @putchar(i32 10)
%34 = add nuw i64 %15, 1
%35 = load i64, i64* %1
%36 = icmp slt i64 %35, %34
%37 = add nuw i32 %16, 1
br i1 %36, label %48, label %14
38: ; preds = %23, %38
%39 = phi i32 [ %46, %38 ], [ 0, %23 ]
%40 = sub nsw i32 %17, %39
%41 = call i64 @iterativeFactorial(i32 %40)
%42 = call i64 @iterativeFactorial(i32 %39)
%43 = mul nsw i64 %42, %41
%44 = sdiv i64 %18, %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %44)
%46 = add nuw i32 %39, 1
%47 = icmp eq i32 %46, %16
br i1 %47, label %32, label %38
48: ; preds = %32, %10, %12
%49 = phi i32 [ 1, %12 ], [ 0, %10 ], [ 0, %32 ]
%50 = call i32 @putchar(i32 10)
ret i32 %49
}