#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int n, sum = 0, i;
  printf("Enter n to find 1! + 2! + . . . + n! : ");
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    sum = sum + fac(i);
  printf("1! + 2! + . . . + %d! = %d\n", n, sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     119d <main+0x6d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <fac@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x3b>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    1174 <main+0x44>
xor    %ebp,%ebp
xor    %ebx,%ebx
add    $0x1,%ebp
mov    %ebp,%edi
call   1030 <fac@plt>
add    %eax,%ebx
mov    0x4(%rsp),%esi
cmp    %esi,%ebp
jl     1160 <main+0x30>
lea    0xeb0(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Enter n to find 1! + 2! + . . . + n! : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"1! + 2! + . . . + %d! = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 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* %2)
store i32 1, i32* %4
br label %7
7: ; preds = %16, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = call i32 @fac(i32 %13)
%15 = add nsw i32 %12, %14
store i32 %15, i32* %3
br label %16
16: ; preds = %11
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %7
19: ; preds = %7
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [40 x i8] c"Enter n to find 1! + 2! + . . . + n! : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"1! + 2! + . . . + %d! = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 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 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %15, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %12, %7 ], [ 1, %0 ]
%9 = phi i32 [ %11, %7 ], [ 0, %0 ]
%10 = call i32 @fac(i32 %8)
%11 = add nsw i32 %10, %9
%12 = add nuw nsw i32 %8, 1
%13 = load i32, i32* %1
%14 = icmp slt i32 %8, %13
br i1 %14, label %7, label %15
15: ; preds = %7, %0
%16 = phi i32 [ 0, %0 ], [ %11, %7 ]
%17 = phi i32 [ %5, %0 ], [ %13, %7 ]
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %16)
ret i32 0
}