#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 factorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int i, n, j;
  printf("Enter the number of rows you wish to see in pascal triangle: ");
  scanf("%d", &n);
  printf("The pascal's traingle is: \n");
  for (i = 0; i < n; i++) {
    for (j = 0; j <= (n - i - 2); j++)
      printf(" ");
    for (j = 0; j <= i; j++)
      printf("%ld ", factorial(i) / (factorial(j) * factorial(i - j)));
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1231 <main+0x101>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     11b5 <main+0x85>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <main+0x55>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1215 <main+0xe5>
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1030 <factorial@plt>
mov    -0x18(%rbp),%ecx
mov    %eax,%edx
mov    -0x14(%rbp),%eax
imul   %edx,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bc <main+0x8c>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1172 <main+0x42>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xece(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1237 <main+0xe7>
lea    0xea8(%rip),%r14
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    $0xfffffffe,%ebx
sub    %r15d,%ebx
add    %ebx,%eax
js     11d7 <main+0x87>
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
add    %ebx,%eax
add    $0x1,%ebp
cmp    %eax,%ebp
jl     11c0 <main+0x70>
xor    %ebx,%ebx
mov    %r15d,%ebp
nopl   0x0(%rax)
mov    %r15d,%edi
call   1050 <factorial@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1050 <factorial@plt>
mov    %eax,%r13d
mov    %ebp,%edi
call   1050 <factorial@plt>
mov    %eax,%ecx
imul   %r13d,%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jb     11e0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15d
mov    0x4(%rsp),%eax
cmp    %eax,%r15d
jl     11a0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"Enter the number of rows you wish to see in pascal triangle: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"The pascal's traingle is: \0A\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [5 x i8] c"%ld \00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %8
8: ; preds = %47, %0
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %50
12: ; preds = %8
store i32 0, i32* %4
br label %13
13: ; preds = %22, %12
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = sub nsw i32 %15, %16
%18 = sub nsw i32 %17, 2
%19 = icmp sle i32 %14, %18
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %13
25: ; preds = %13
store i32 0, i32* %4
br label %26
26: ; preds = %42, %25
%27 = load i32, i32* %4
%28 = load i32, i32* %2
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %26
%31 = load i32, i32* %2
%32 = call i32 @factorial(i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @factorial(i32 %33)
%35 = load i32, i32* %2
%36 = load i32, i32* %4
%37 = sub nsw i32 %35, %36
%38 = call i32 @factorial(i32 %37)
%39 = mul nsw i32 %34, %38
%40 = sdiv i32 %32, %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %26
45: ; preds = %26
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %45
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %8
50: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [62 x i8] c"Enter the number of rows you wish to see in pascal triangle: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [5 x i8] c"%ld \00"
@str = [27 x i8] c"The pascal's traingle is: \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %0, %34
%9 = phi i32 [ %37, %34 ], [ %6, %0 ]
%10 = phi i32 [ %39, %34 ], [ 1, %0 ]
%11 = phi i32 [ %36, %34 ], [ 0, %0 ]
%12 = sub nuw nsw i32 -2, %11
%13 = add i32 %12, %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %8, %15
%16 = phi i32 [ %18, %15 ], [ 0, %8 ]
%17 = call i32 @putchar(i32 32)
%18 = add nuw nsw i32 %16, 1
%19 = load i32, i32* %1
%20 = add i32 %12, %19
%21 = icmp slt i32 %16, %20
br i1 %21, label %15, label %22
22: ; preds = %15, %8
br label %23
23: ; preds = %22, %23
%24 = phi i32 [ %32, %23 ], [ 0, %22 ]
%25 = call i32 @factorial(i32 %11)
%26 = call i32 @factorial(i32 %24)
%27 = sub nsw i32 %11, %24
%28 = call i32 @factorial(i32 %27)
%29 = mul nsw i32 %28, %26
%30 = sdiv i32 %25, %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i32 %24, 1
%33 = icmp eq i32 %32, %10
br i1 %33, label %34, label %23
34: ; preds = %23
%35 = call i32 @putchar(i32 10)
%36 = add nuw nsw i32 %11, 1
%37 = load i32, i32* %1
%38 = icmp slt i32 %36, %37
%39 = add nuw i32 %10, 1
br i1 %38, label %8, label %40
40: ; preds = %34, %0
ret i32 0
}