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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11fb <main+0xbb>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c2 <main+0x82>
mov    -0xc(%rbp),%edi
call   1050 <suma@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <faktoriel@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    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1177 <main+0x37>
mov    -0x8(%rbp),%edi
call   1050 <suma@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <faktoriel@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x14(%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   1040 <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 <suma@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1030 <faktoriel@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 <suma@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <faktoriel@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 = [20 x i8] c"Nevalidna vrednost\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %40
9: ; preds = %0
store i32 0, i32* %4
store i32 1, i32* %3
br label %10
10: ; preds = %25, %9
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i32 @suma(i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = call i64 @faktoriel(i32 %17)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %4
%23 = load i32, i32* %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %14
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %10
28: ; preds = %10
%29 = load i32, i32* %2
%30 = call i32 @suma(i32 %29)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = call i64 @faktoriel(i32 %31)
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = add nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %4
%37 = load i32, i32* %5
%38 = load i32, i32* %4
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %38)
br label %42
40: ; preds = %0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %28
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 = [19 x i8] c"Nevalidna vrednost\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 i64 [ %17, %8 ], [ 0, %6 ]
%10 = phi i32 [ %15, %8 ], [ 1, %6 ]
%11 = call i32 @suma(i32 %10)
%12 = call i64 @faktoriel(i32 %11)
%13 = add nsw i64 %12, %9
%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 %10, 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 @suma(i32 %22)
%24 = call i64 @faktoriel(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 ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
ret i32 0
}