#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 *);
int *mymalloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int *p = NULL;
  int i = 0;
  p = mymalloc(1000);
  if (NULL == p) {
    printf("mymalloc returned NULL");
  } else {
    for (i = 0; i <= 100; i++) {
      printf("%08X", p[i]);
      if (i % 8 == 7) {
        printf("\n");
      }
    }
    printf("\n");
    free(p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x3e8,%edi
call   1050 <mymalloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    117b <main+0x4b>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f1 <main+0xc1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jg     11da <main+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    11c7 <main+0x97>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cc <main+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <main+0x52>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x3e8,%edi
call   1060 <mymalloc@plt>
test   %rax,%rax
je     11b0 <main+0x70>
mov    %rax,%r15
lea    0xeb9(%rip),%r14
xor    %ebx,%ebx
jmp    117a <main+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    $0x65,%rbx
je     119c <main+0x5c>
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0x7,%al
jne    1170 <main+0x30>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1170 <main+0x30>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11be <main+0x7e>
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"mymalloc returned NULL\00"
@.str.1 = [5 x i8] c"%08X\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %3
%4 = call i32* @mymalloc(i32 1000)
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* null, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %33
9: ; preds = %0
store i32 0, i32* %3
br label %10
10: ; preds = %26, %9
%11 = load i32, i32* %3
%12 = icmp sle i32 %11, 100
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = srem i32 %20, 8
%22 = icmp eq i32 %21, 7
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %10
29: ; preds = %10
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32*, i32** %2
%32 = call i32 @free(i32* %31)
br label %33
33: ; preds = %29, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"mymalloc returned NULL\00"
@.str.1 = [5 x i8] c"%08X\00"
define i32 @main() {
%1 = tail call i32* @mymalloc(i32 1000)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %20
5: ; preds = %0, %14
%6 = phi i64 [ %15, %14 ], [ 0, %0 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = and i64 %6, 7
%11 = icmp eq i64 %10, 7
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 @putchar(i32 10)
br label %14
14: ; preds = %5, %12
%15 = add nuw nsw i64 %6, 1
%16 = icmp eq i64 %15, 101
br i1 %16, label %17, label %5
17: ; preds = %14
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @free(i32* %1)
br label %20
20: ; preds = %17, %3
ret i32 0
}