#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*/ abort();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int *arr[4];
  for (int i = 0; i < 4; i++) {
    arr[i] = (int *)malloc(5 * sizeof(int));
    if (arr[i] == NULL) {
      printf("Malloc failed for arr[%d], aborting...", i);
      abort();
    }
  }
  (void)arr;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    119f <main+0x6f>
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
movslq -0x34(%rbp),%rax
cmpq   $0x0,-0x30(%rbp,%rax,8)
jne    118c <main+0x5c>
mov    -0x34(%rbp),%esi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1191 <main+0x61>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x14,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1171 <main+0x41>
mov    $0x14,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1175 <main+0x45>
mov    $0x14,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117c <main+0x4c>
mov    $0x14,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1183 <main+0x53>
xor    %eax,%eax
pop    %rcx
ret
xor    %esi,%esi
jmp    1188 <main+0x58>
mov    $0x1,%esi
jmp    1188 <main+0x58>
mov    $0x2,%esi
jmp    1188 <main+0x58>
mov    $0x3,%esi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Malloc failed for arr[%d], aborting...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32*]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %23, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 4
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = call i64 @malloc(i32 20)
%9 = inttoptr i64 %8 to i32*
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 %11
store i32* %9, i32** %12
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 %14
%16 = load i32*, i32** %15
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %7
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %7
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %4
26: ; preds = %4
%27 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 0
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Malloc failed for arr[%d], aborting...\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 20)
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %13, %10, %7, %0
%4 = phi i32 [ 0, %0 ], [ 1, %7 ], [ 2, %10 ], [ 3, %13 ]
%5 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 (...) @abort()
unreachable
7: ; preds = %0
%8 = tail call i64 @malloc(i32 20)
%9 = icmp eq i64 %8, 0
br i1 %9, label %3, label %10
10: ; preds = %7
%11 = tail call i64 @malloc(i32 20)
%12 = icmp eq i64 %11, 0
br i1 %12, label %3, label %13
13: ; preds = %10
%14 = tail call i64 @malloc(i32 20)
%15 = icmp eq i64 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %13
ret i32 0
}