#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*/ fill_array(int *, int);
char *int_to_string(int);
int /*<<< orphan*/ print(char *);
int /*<<< orphan*/ readStr();
int str_to_int(int /*<<< orphan*/);
int sum_array(int *, int);
void sum() {
  print("\nHow many numbers: ");
  int n = str_to_int(readStr());
  int i = 0;
  print("\n");
  int arr[n];
  fill_array(arr, n);
  int s = sum_array(arr, n);
  print("Result: ");
  print(int_to_string(s));
  print("\n");
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1050 <print@plt>
xor    %eax,%eax
call   1070 <readStr@plt>
mov    %eax,%edi
call   1040 <str_to_int@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe81(%rip),%rdi
call   1050 <print@plt>
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%esi
call   1060 <fill_array@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <sum_array@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe39(%rip),%rdi
call   1050 <print@plt>
mov    -0x1c(%rbp),%edi
call   1080 <int_to_string@plt>
mov    %rax,%rdi
call   1050 <print@plt>
lea    0xe1b(%rip),%rdi
call   1050 <print@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe8f(%rip),%rdi
call   1050 <print@plt>
xor    %eax,%eax
call   1070 <readStr@plt>
mov    %eax,%edi
call   1040 <str_to_int@plt>
mov    %eax,%r15d
lea    0xe86(%rip),%r14
mov    %r14,%rdi
call   1050 <print@plt>
mov    %r15d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <fill_array@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <sum_array@plt>
mov    %eax,%ebx
lea    0xe49(%rip),%rdi
call   1050 <print@plt>
mov    %ebx,%edi
call   1080 <int_to_string@plt>
mov    %rax,%rdi
call   1050 <print@plt>
mov    %r14,%rdi
call   1050 <print@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"\0AHow many numbers: \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [9 x i8] c"Result: \00"
define void @sum() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = call i32 @print(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @readStr()
%8 = call i32 @str_to_int(i32 %7)
store i32 %8, i32* %1
store i32 0, i32* %2
%9 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i32, i64 %11
store i64 %11, i64* %4
%14 = load i32, i32* %1
%15 = call i32 @fill_array(i32* %13, i32 %14)
%16 = load i32, i32* %1
%17 = call i32 @sum_array(i32* %13, i32 %16)
store i32 %17, i32* %5
%18 = call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %5
%20 = call i8* @int_to_string(i32 %19)
%21 = call i32 @print(i8* %20)
%22 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"\0AHow many numbers: \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [9 x i8] c"Result: \00"
define void @sum() {
%1 = tail call i32 @print(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @readStr()
%3 = tail call i32 @str_to_int(i32 %2)
%4 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = zext i32 %3 to i64
%6 = alloca i32, i64 %5
%7 = call i32 @fill_array(i32* %6, i32 %3)
%8 = call i32 @sum_array(i32* %6, i32 %3)
%9 = call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = call i8* @int_to_string(i32 %8)
%11 = call i32 @print(i8* %10)
%12 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}