#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 /*<<< orphan*/ scanf(char *, int *);
int sum_max(int *, int);
int main() {
  int n, vet[40], i, sum;
  printf("Digite a quantidade de termos: \n");
  scanf("%d", &n);
  printf("Digite os %d termos: \n", n);
  for (i = 0; i < n; i++) {
    printf("Digite o termo[%d]: ", i + 1);
    scanf("%d", &vet[i]);
  }
  sum = sum_max(vet, n);
  printf("A soma maxima do segmento eh: %d \n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d6 <main+0xa6>
mov    -0xb4(%rbp),%esi
add    $0x1,%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0xb4(%rbp),%rax
lea    -0xb0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe64(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    117b <main+0x4b>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <sum_max@plt>
mov    %eax,-0xb8(%rbp)
mov    -0xb8(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xefd(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9f(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11c9 <main+0x89>
lea    0x10(%rsp),%r12
lea    0xe89(%rip),%r14
lea    0xe68(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
movslq 0xc(%rsp),%rsi
add    $0x4,%r12
cmp    %rsi,%rbx
jl     11a0 <main+0x60>
lea    0x10(%rsp),%rdi
call   1030 <sum_max@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Digite a quantidade de termos: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Digite os %d termos: \0A\00"
@.str.3 = [21 x i8] c"Digite o termo[%d]: \00"
@.str.4 = [35 x i8] c"A soma maxima do segmento eh: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [40 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i32 0, i32* %4
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [40 x i32], [40 x i32]* %3, i64 0, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %10
25: ; preds = %10
%26 = getelementptr inbounds [40 x i32], [40 x i32]* %3, i64 0, i64 0
%27 = load i32, i32* %2
%28 = call i32 @sum_max(i32* %26, i32 %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Digite os %d termos: \0A\00"
@.str.3 = [21 x i8] c"Digite o termo[%d]: \00"
@.str.4 = [35 x i8] c"A soma maxima do segmento eh: %d \0A\00"
@str = [32 x i8] c"Digite a quantidade de termos: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [40 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [40 x i32]* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %0, %11
%12 = phi i64 [ %13, %11 ], [ 0, %0 ]
%13 = add nuw nsw i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %13, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %0
%22 = phi i32 [ %9, %0 ], [ %18, %11 ]
%23 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 0
%24 = call i32 @sum_max(i32* %23, i32 %22)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %24)
ret i32 0
}