#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*/ calcula_total_vendas(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int *apt = NULL;
  apt = (int *)malloc(5 * sizeof(int));
  if (apt == NULL) {
    printf("vector nulo\n");
    return -5;
  }
  apt[0] = 0x000A0501;
  apt[1] = 0x00051002;
  apt[2] = 0x000F1003;
  apt[3] = 0x00040804;
  apt[4] = 0x00020205;
  calcula_total_vendas(apt);
  int i;
  for (i = 0; i < 5; i++) {
    printf("valor %d : %x \n", i, apt[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117a <main+0x4a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    11fb <main+0xcb>
mov    -0x10(%rbp),%rax
movl   $0xa0501,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x51002,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0xf1003,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x40804,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x20205,0x10(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <calcula_total_vendas@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11f4 <main+0xc4>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <main+0x90>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x14,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d1 <main+0x91>
mov    %rax,%rbx
movaps 0xea3(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x20205,0x10(%rax)
mov    %rax,%rdi
call   1050 <calcula_total_vendas@plt>
mov    (%rbx),%edx
lea    0xe98(%rip),%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%edx
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%edx
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%edx
mov    %rbp,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%edx
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e3 <main+0xa3>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffb,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"vector nulo\0A\00"
@.str.1 = [16 x i8] c"valor %d : %x \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
%4 = call i64 @malloc(i32 20)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -5, i32* %1
br label %38
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 656641, i32* %12
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 1
store i32 331778, i32* %14
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i64 2
store i32 987139, i32* %16
%17 = load i32*, i32** %2
%18 = getelementptr inbounds i32, i32* %17, i64 3
store i32 264196, i32* %18
%19 = load i32*, i32** %2
%20 = getelementptr inbounds i32, i32* %19, i64 4
store i32 131589, i32* %20
%21 = load i32*, i32** %2
%22 = call i32 @calcula_total_vendas(i32* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %34, %10
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 5
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i32, i32* %3
%28 = load i32*, i32** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %23
37: ; preds = %23
store i32 0, i32* %1
br label %38
38: ; preds = %37, %8
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"valor %d : %x \0A\00"
@str = [12 x i8] c"vector nulo\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 20)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %23
6: ; preds = %0
%7 = getelementptr inbounds i32, i32* %2, i64 1
%8 = getelementptr inbounds i32, i32* %2, i64 2
%9 = getelementptr inbounds i32, i32* %2, i64 3
%10 = inttoptr i64 %1 to <4 x i32>*
store <4 x i32> <i32 656641, i32 331778, i32 987139, i32 264196>, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %2, i64 4
store i32 131589, i32* %11
%12 = tail call i32 @calcula_total_vendas(i32* %2)
%13 = load i32, i32* %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %13)
%15 = load i32, i32* %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %15)
%17 = load i32, i32* %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %17)
%19 = load i32, i32* %9
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %19)
%21 = load i32, i32* %11
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %21)
br label %23
23: ; preds = %6, %4
%24 = phi i32 [ -5, %4 ], [ 0, %6 ]
ret i32 %24
}