#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 /*<<< orphan*/ scanf(char *, int *);
int sum(int x) {
  int sequence;
  int value = 0;
  if (x == 0) {
    return x;
  } else {
    for (int i = 0; i < x; i++) {
      scanf("%d", &sequence);
      value = value + sequence;
    }
    return value;
  }
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1137 <sum+0x27>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <sum+0x67>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1171 <sum+0x61>
lea    0xeaf(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <scanf@plt>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <sum+0x2e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1146 <sum+0x36>
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0xeda(%rip),%r14
lea    0x4(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <scanf@plt>
add    0x4(%rsp),%ebx
add    $0xffffffff,%ebp
jne    1130 <sum+0x20>
jmp    1148 <sum+0x38>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @sum(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %3
store i32 %10, i32* %2
br label %26
11: ; preds = %1
store i32 0, i32* %6
br label %12
12: ; preds = %21, %11
%13 = load i32, i32* %6
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = add nsw i32 %18, %19
store i32 %20, i32* %5
br label %21
21: ; preds = %16
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %12
24: ; preds = %12
%25 = load i32, i32* %5
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @sum(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %13
5: ; preds = %1, %5
%6 = phi i32 [ %11, %5 ], [ 0, %1 ]
%7 = phi i32 [ %10, %5 ], [ 0, %1 ]
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, %7
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %5
13: ; preds = %5, %1
%14 = phi i32 [ 0, %1 ], [ %10, %5 ]
ret i32 %14
}