#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(char *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  size_t mem_size = ((long)2 << 30);
  printf("Malloc %zu bytes.\n", mem_size);
  char *mem_area = malloc(mem_size);
  if (!mem_area) {
    printf("Malloc failed.\n");
    return 1;
  }
  size_t i;
  for (i = 0; i < mem_size; i++)
    *(mem_area + i) = '+';
  free(mem_area);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x80000000,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1193 <main+0x63>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d6 <main+0xa6>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11c6 <main+0x96>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x2b,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    119b <main+0x6b>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
xor    %ebp,%ebp
mov    $0x80000000,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x80000000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1196 <main+0x46>
mov    %rax,%rbx
mov    $0x80000000,%edx
mov    %rax,%rdi
mov    $0x2b,%esi
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11a7 <main+0x57>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Malloc %zu bytes.\0A\00"
@.str.1 = [16 x i8] c"Malloc failed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 2147483648, i64* %6
%9 = load i64, i64* %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = load i64, i64* %6
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %32
17: ; preds = %2
store i64 0, i64* %8
br label %18
18: ; preds = %26, %17
%19 = load i64, i64* %8
%20 = load i64, i64* %6
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 43, i8* %25
br label %26
26: ; preds = %22
%27 = load i64, i64* %8
%28 = add i64 %27, 1
store i64 %28, i64* %8
br label %18
29: ; preds = %18
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
store i32 0, i32* %3
br label %32
32: ; preds = %29, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [19 x i8] c"Malloc %zu bytes.\0A\00"
@str = [15 x i8] c"Malloc failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 2147483648)
%4 = tail call dereferenceable_or_null(2147483648) i8* @malloc(i64 2147483648)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @free(i8* %4)
br label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %6, %8
%11 = phi i32 [ 0, %6 ], [ 1, %8 ]
ret i32 %11
}