#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 */
scalar_t__ factorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int sum(int);
int main() {
  int i, n, result = 0;
  scanf("%d", &n);
  if (n > 0) {
    for (i = 1; i < n; i++) {
      int s = sum(i);
      result += factorial(s);
      printf("%d! + ", s);
    }
    int s = sum(n);
    result += factorial(s);
    printf("%d! = %d\n", s, result);
  } else
    printf("Wrong input\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11fb <main+0xbb>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c2 <main+0x82>
mov    -0x8(%rbp),%edi
call   1050 <sum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <factorial@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1177 <main+0x37>
mov    -0xc(%rbp),%edi
call   1050 <sum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <factorial@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1209 <main+0xc9>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1184 <main+0x34>
cmp    $0x1,%eax
jne    1192 <main+0x42>
mov    $0x1,%edi
xor    %r15d,%r15d
jmp    11e2 <main+0x92>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
jmp    1206 <main+0xb6>
mov    $0x1,%ebp
lea    0xe65(%rip),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1060 <sum@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1040 <factorial@plt>
mov    %rax,%rbx
add    %r15d,%ebx
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
movslq %ebx,%r15
mov    0xc(%rsp),%edi
cmp    %edi,%ebp
jl     11b0 <main+0x60>
call   1060 <sum@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <factorial@plt>
add    %eax,%r15d
lea    0xe10(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d! + \00"
@.str.2 = [10 x i8] c"%d! = %d\0A\00"
@.str.3 = [13 x i8] c"Wrong input\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %41
10: ; preds = %0
store i32 1, i32* %2
br label %11
11: ; preds = %26, %10
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i32, i32* %2
%17 = call i32 @sum(i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = call i64 @factorial(i32 %18)
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %4
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %15
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %11
29: ; preds = %11
%30 = load i32, i32* %3
%31 = call i32 @sum(i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = call i64 @factorial(i32 %32)
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %4
%38 = load i32, i32* %6
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %39)
br label %43
41: ; preds = %0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %29
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d! + \00"
@.str.2 = [10 x i8] c"%d! = %d\0A\00"
@str = [12 x i8] c"Wrong input\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %28
6: ; preds = %0
%7 = icmp eq i32 %4, 1
br i1 %7, label %20, label %8
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ 1, %6 ]
%10 = phi i64 [ %17, %8 ], [ 0, %6 ]
%11 = call i32 @sum(i32 %9)
%12 = call i64 @factorial(i32 %11)
%13 = add nsw i64 %12, %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%15 = add nuw nsw i32 %9, 1
%16 = shl i64 %13, 32
%17 = ashr exact i64 %16, 32
%18 = load i32, i32* %1
%19 = icmp slt i32 %15, %18
br i1 %19, label %8, label %20
20: ; preds = %8, %6
%21 = phi i64 [ 0, %6 ], [ %17, %8 ]
%22 = phi i32 [ 1, %6 ], [ %18, %8 ]
%23 = call i32 @sum(i32 %22)
%24 = call i64 @factorial(i32 %23)
%25 = add nsw i64 %24, %21
%26 = trunc i64 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %26)
br label %30
28: ; preds = %0
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
ret i32 0
}