#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void reallocMsg(void **mem, size_t size) {
  void *temp;
  if (mem != NULL) {
    if (size) {
      temp = realloc(*mem, size);
      if (temp == NULL) {
        fputs("TDB_MALLOC_FAILED3", stderr);
        exit(EXIT_FAILURE);
      }
      *mem = temp;
    } else {
      free(*mem);
      *mem = NULL;
    }
  } else {
    fputs("TDB_INVALID_REALLOC", stderr);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<reallocMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d4 <reallocMsg+0x94>
cmpq   $0x0,-0x10(%rbp)
je     11b8 <reallocMsg+0x78>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <reallocMsg+0x68>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11cf <reallocMsg+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    11f7 <reallocMsg+0xb7>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reallocMsg>:
push   %rbx
test   %rdi,%rdi
je     1179 <reallocMsg+0x39>
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rsi,%rsi
je     116d <reallocMsg+0x2d>
call   1050 <realloc@plt>
test   %rax,%rax
jne    1174 <reallocMsg+0x34>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
jmp    1189 <reallocMsg+0x49>
call   1030 <free@plt>
xor    %eax,%eax
mov    %rax,(%rbx)
pop    %rbx
ret
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"TDB_MALLOC_FAILED3\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"TDB_INVALID_REALLOC\00"
define void @reallocMsg(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i8*
store i8** %0, i8*** %3
store i64 %1, i64* %4
%6 = load i8**, i8*** %3
%7 = icmp ne i8** %6, null
br i1 %7, label %8, label %32
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = load i64, i64* %4
%15 = call i8* @realloc(i8* %13, i64 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %11
%24 = load i8*, i8** %5
%25 = load i8**, i8*** %3
store i8* %24, i8** %25
br label %31
26: ; preds = %8
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = call i32 @free(i8* %28)
%30 = load i8**, i8*** %3
store i8* null, i8** %30
br label %31
31: ; preds = %26, %23
br label %37
32: ; preds = %2
%33 = load i32, i32* @stderr
%34 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %31
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"TDB_MALLOC_FAILED3\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"TDB_INVALID_REALLOC\00"
define void @reallocMsg(i8** %0, i64 %1) {
%3 = icmp eq i8** %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = icmp eq i64 %1, 0
%6 = load i8*, i8** %0
br i1 %5, label %15, label %7
7: ; preds = %4
%8 = tail call i8* @realloc(i8* %6, i64 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %4
%16 = tail call i32 @free(i8* %6)
br label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %7, %15
%23 = phi i8* [ null, %15 ], [ %8, %7 ]
store i8* %23, i8** %0
ret void
}