#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*/ EXIT_SUCCESS;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ errExit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ muntrace();
int *realloc(int *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int *arr;
  int *newPtr;
  mtrace();
  arr = (int *)calloc(10, sizeof(int));
  if (arr == NULL) {
    errExit("error on calloc, %s\n", strerror(errno));
  }
  newPtr = realloc(arr, 20 * sizeof(int));
  if (newPtr == NULL) {
    errExit("error on realloc, %s\n", strerror(errno));
  } else {
    arr = newPtr;
  }
  muntrace();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <mtrace@plt>
mov    $0xa,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c7 <main+0x57>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe3e(%rip),%rdi
call   1030 <errExit@plt>
mov    -0x18(%rbp),%rdi
mov    $0x50,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <main+0x95>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe1a(%rip),%rdi
call   1030 <errExit@plt>
jmp    120d <main+0x9d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <muntrace@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <mtrace@plt>
mov    $0xa,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ab <main+0x3b>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
call   1030 <errExit@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
call   1060 <realloc@plt>
test   %rax,%rax
jne    11d9 <main+0x69>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe43(%rip),%rdi
mov    %eax,%esi
call   1030 <errExit@plt>
xor    %eax,%eax
call   1040 <muntrace@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"error on calloc, %s\0A\00"
@errno = global i32 0
@.str.1 = [22 x i8] c"error on realloc, %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @mtrace()
%9 = call i64 @calloc(i32 10, i32 4)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @errExit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %2
%18 = load i32*, i32** %6
%19 = call i32* @realloc(i32* %18, i32 80)
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @errExit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %17
%27 = load i32*, i32** %7
store i32* %27, i32** %6
br label %28
28: ; preds = %26, %22
%29 = call i32 (...) @muntrace()
%30 = load i32, i32* @EXIT_SUCCESS
%31 = call i32 @exit(i32 %30)
unreachable
}

LLVM IR (-O2):
@.str = [21 x i8] c"error on calloc, %s\0A\00"
@errno = global i32 0
@.str.1 = [22 x i8] c"error on realloc, %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @mtrace()
%4 = tail call i64 @calloc(i32 10, i32 4)
%5 = inttoptr i64 %4 to i32*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @errExit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %2
%12 = tail call i32* @realloc(i32* %5, i32 80)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 @errExit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %11, %14
%19 = tail call i32 (...) @muntrace()
%20 = load i32, i32* @EXIT_SUCCESS
%21 = tail call i32 @exit(i32 %20)
unreachable
}