#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__ fact(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main() {
  unsigned int num, sum = 0;
  int i = 0;
  scanf("%u", &num);
  if (num <= 12) {
    for (i = num; i >= 1; i--) {
      sum += fact(i);
    }
    printf("%u\n", sum);
  } else
    printf("overflow");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0xc,-0x8(%rbp)
ja     11af <main+0x7f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     1199 <main+0x69>
mov    -0x10(%rbp),%edi
call   1040 <fact@plt>
mov    %rax,%rcx
mov    -0xc(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    116d <main+0x3d>
mov    -0xc(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bd <main+0x8d>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ebx
cmp    $0xc,%ebx
ja     1185 <main+0x55>
xor    %ebp,%ebp
test   %ebx,%ebx
je     1173 <main+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1040 <fact@plt>
add    %eax,%ebp
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
ja     1160 <main+0x30>
lea    0xe89(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1193 <main+0x63>
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [9 x i8] c"overflow\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
store i32 0, i32* %4
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp ule i32 %6, 12
br i1 %7, label %8, label %26
8: ; preds = %0
%9 = load i32, i32* %2
store i32 %9, i32* %4
br label %10
10: ; preds = %20, %8
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 1
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %4
%15 = call i64 @fact(i32 %14)
%16 = load i32, i32* %3
%17 = zext i32 %16 to i64
%18 = add nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %3
br label %20
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
br label %10
23: ; preds = %10
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [9 x i8] c"overflow\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 ult i32 %4, 13
br i1 %5, label %6, label %19
6: ; preds = %0
%7 = icmp eq i32 %4, 0
br i1 %7, label %16, label %8
8: ; preds = %6, %8
%9 = phi i32 [ %14, %8 ], [ %4, %6 ]
%10 = phi i32 [ %13, %8 ], [ 0, %6 ]
%11 = call i64 @fact(i32 %9)
%12 = trunc i64 %11 to i32
%13 = add i32 %10, %12
%14 = add nsw i32 %9, -1
%15 = icmp ugt i32 %9, 1
br i1 %15, label %8, label %16
16: ; preds = %8, %6
%17 = phi i32 [ 0, %6 ], [ %13, %8 ]
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
ret i32 0
}