#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 *mycalloc(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int *p = NULL;
  int i = 0;
  p = mycalloc(100, sizeof *p);
  if (NULL == p) {
    printf("mycalloc returned NULL.\n");
  } 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    $0x64,%edi
mov    $0x4,%esi
call   1040 <mycalloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1180 <main+0x50>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f6 <main+0xc6>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11df <main+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    11cc <main+0x9c>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d1 <main+0xa1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <main+0x57>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <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    $0x64,%edi
mov    $0x4,%esi
call   1050 <mycalloc@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    %rax,%r15
lea    0xe8d(%rip),%r14
xor    %ebx,%ebx
jmp    118a <main+0x3a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x64,%rbx
je     11ac <main+0x5c>
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0x7,%al
jne    1180 <main+0x30>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1180 <main+0x30>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11cc <main+0x7c>
lea    0xe3f(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"mycalloc returned NULL.\0A\00"
@.str.1 = [6 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* @mycalloc(i32 100, i32 4)
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 ([25 x i8], [25 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 slt 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 ([6 x i8], [6 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.1 = [6 x i8] c"%08X \00"
@str = [24 x i8] c"mycalloc returned NULL.\00"
define i32 @main() {
%1 = tail call i32* @mycalloc(i32 100, i32 4)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 ([6 x i8], [6 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, 100
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
}