#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*/ InitializeArray(int *, int);
int *MakeArray(int);
int /*<<< orphan*/ PrintArray(int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int *p = 0;
  p = (int *)malloc(sizeof(int));
  if (!p) {
    printf("Memory Allocation Error.  Your computer sucks.");
    return -1;
  }
  *p = 42;
  printf("The answer to life, the universe and everything is %d\n", *p);
  if (p)
    free(p);
  p = 0;
  p = MakeArray(1000);
  printf("Uninitialized array:\n");
  PrintArray(p, 1000);
  InitializeArray(p, 1000);
  printf("Initialized array:\n");
  PrintArray(p, 1000);
  if (p)
    free(p);
  p = 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movq   $0x0,-0x10(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11da <main+0x5a>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128b <main+0x10b>
mov    -0x10(%rbp),%rax
movl   $0x2a,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     120c <main+0x8c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    $0x3e8,%edi
call   1090 <MakeArray@plt>
mov    %rax,-0x10(%rbp)
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3e8,%esi
call   1080 <PrintArray@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3e8,%esi
call   10a0 <InitializeArray@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3e8,%esi
call   1080 <PrintArray@plt>
cmpq   $0x0,-0x10(%rbp)
je     127c <main+0xfc>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x4,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1233 <main+0xa3>
mov    %rax,%rbx
movl   $0x2a,(%rax)
lea    0xe6b(%rip),%rdi
mov    $0x2a,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x3e8,%edi
call   10a0 <MakeArray@plt>
mov    %rax,%rbx
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1090 <PrintArray@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   10b0 <InitializeArray@plt>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1090 <PrintArray@plt>
test   %rbx,%rbx
je     1247 <main+0xb7>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1247 <main+0xb7>
lea    0xdc6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Memory Allocation Error. Your computer sucks.\00"
@.str.1 = [55 x i8] c"The answer to life, the universe and everything is %d\0A\00"
@.str.2 = [22 x i8] c"Uninitialized array:\0A\00"
@.str.3 = [20 x i8] c"Initialized array:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32 @time(i32* null)
%4 = call i32 @srand(i32 %3)
store i32* null, i32** %2
%5 = call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %37
11: ; preds = %0
%12 = load i32*, i32** %2
store i32 42, i32* %12
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %2
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32*, i32** %2
%20 = call i32 @free(i32* %19)
br label %21
21: ; preds = %18, %11
store i32* null, i32** %2
%22 = call i32* @MakeArray(i32 1000)
store i32* %22, i32** %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32*, i32** %2
%25 = call i32 @PrintArray(i32* %24, i32 1000)
%26 = load i32*, i32** %2
%27 = call i32 @InitializeArray(i32* %26, i32 1000)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32*, i32** %2
%30 = call i32 @PrintArray(i32* %29, i32 1000)
%31 = load i32*, i32** %2
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = load i32*, i32** %2
%35 = call i32 @free(i32* %34)
br label %36
36: ; preds = %33, %21
store i32* null, i32** %2
store i32 0, i32* %1
br label %37
37: ; preds = %36, %9
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [47 x i8] c"Memory Allocation Error. Your computer sucks.\00"
@.str.1 = [55 x i8] c"The answer to life, the universe and everything is %d\0A\00"
@str = [21 x i8] c"Uninitialized array:\00"
@str.4 = [19 x i8] c"Initialized array:\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %0
store i32 42, i32* %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 42)
%10 = tail call i32 @free(i32* %4)
%11 = tail call i32* @MakeArray(i32 1000)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @PrintArray(i32* %11, i32 1000)
%14 = tail call i32 @InitializeArray(i32* %11, i32 1000)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
%16 = tail call i32 @PrintArray(i32* %11, i32 1000)
%17 = icmp eq i32* %11, null
br i1 %17, label %20, label %18
18: ; preds = %8
%19 = tail call i32 @free(i32* %11)
br label %20
20: ; preds = %8, %18, %6
%21 = phi i32 [ -1, %6 ], [ 0, %18 ], [ 0, %8 ]
ret i32 %21
}