#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int *p;
  int i, tol;
  p = (int *)malloc(5 * sizeof(int));
  if (p == NULL) {
    printf("malloc error\n");
  } else {
    tol = 0;
    for (i = 0; i < 5; i++) {
      *(p + i) = i;
      printf("%d\n", p[i]);
      tol += p[i];
    }
    free(p);
  }
  printf("tol = %d\n", tol);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <main+0x3b>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d2 <main+0xa2>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11c9 <main+0x99>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <main+0x49>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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     11f8 <main+0xb8>
mov    %rax,%rbx
movl   $0x0,(%rax)
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%ebp
movl   $0x1,0x4(%rbx)
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    0x4(%rbx),%ebp
movl   $0x2,0x8(%rbx)
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    0x8(%rbx),%ebp
movl   $0x3,0xc(%rbx)
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    0xc(%rbx),%ebp
movl   $0x4,0x10(%rbx)
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    0x10(%rbx),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe18(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe0b(%rip),%rdi
call   1040 <puts@plt>

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [10 x i8] c"tol = %d\0A\00"
@str = [13 x i8] c"malloc error\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 %25, label %4
4: ; preds = %0
store i32 0, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%6 = load i32, i32* %2
%7 = getelementptr inbounds i32, i32* %2, i64 1
store i32 1, i32* %7
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
%9 = load i32, i32* %7
%10 = add nsw i32 %9, %6
%11 = getelementptr inbounds i32, i32* %2, i64 2
store i32 2, i32* %11
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%13 = load i32, i32* %11
%14 = add nsw i32 %13, %10
%15 = getelementptr inbounds i32, i32* %2, i64 3
store i32 3, i32* %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%17 = load i32, i32* %15
%18 = add nsw i32 %17, %14
%19 = getelementptr inbounds i32, i32* %2, i64 4
store i32 4, i32* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%21 = load i32, i32* %19
%22 = add nsw i32 %21, %18
%23 = tail call i32 @free(i32* %2)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %22)
ret i32 0
25: ; preds = %0
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
unreachable
}