#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*/ printf(char *, int);
int sum(int *, int, int);
int main(void) {
  int x[] = {5, 6, 7};
  int x_length = 3;
  int y[] = {};
  int y_length = 0;
  printf("%i\n", sum(x, x_length, 0));
  printf("%i\n", sum(x, x_length, 1));
  printf("%i\n", sum(y, y_length, 0));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x4(%rbp)
movl   $0x3,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
call   1040 <sum@plt>
mov    %eax,%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
lea    -0xc(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
call   1040 <sum@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
lea    -0x14(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1040 <sum@plt>
mov    %eax,%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0xedb(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xec8(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <sum@plt>
lea    0xeb4(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <sum@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <sum@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.x = [3 x i32] [i32 5, i32 6, i32 7]
@.str = [4 x i8] c"%i\0A\00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = alloca i32
%3 = alloca [0 x i32]
%4 = alloca i32
%5 = bitcast [3 x i32]* %1 to i8*
store i32 3, i32* %2
%6 = bitcast [0 x i32]* %3 to i8*
store i32 0, i32* %4
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @sum(i32* %7, i32 %8, i32 0)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @sum(i32* %11, i32 %12, i32 1)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [0 x i32], [0 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @sum(i32* %15, i32 %16, i32 0)
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
ret i32 0
}

LLVM IR (-O2):
@__const.main.x = [3 x i32] [i32 5, i32 6, i32 7]
@.str = [4 x i8] c"%i\0A\00"
define i32 @main() {
%1 = alloca [0 x i32]
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %2 to i8*
%4 = bitcast [0 x i32]* %1 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%6 = call i32 @sum(i32* %5, i32 3, i32 0)
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @sum(i32* %5, i32 3, i32 1)
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [0 x i32], [0 x i32]* %1, i64 0, i64 0
%11 = call i32 @sum(i32* %10, i32 0, i32 0)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}