#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 */
void *malloc(int);
int /*<<< orphan*/ mes_aux(int, char *, int);
void *realloc(void *, int);
int ighmm_realloc(void **mem, int bytes) {
  void *res;
  if (bytes <= 0)
    bytes = 1;
  if (!mem)
    return (-1);
  if (!*mem)
    res = malloc(bytes);
  else
    res = realloc(*mem, bytes);
  if (res) {
    *mem = res;
    return (0);
  } else
    mes_aux((1 | 16 | 4), "realloc: could not reallocate %d bytes\n", bytes);
  return (-1);
}


x86 assembly (clang, -O0):
<ighmm_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1150 <ighmm_realloc+0x20>
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1167 <ighmm_realloc+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <ighmm_realloc+0xa6>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1186 <ighmm_realloc+0x56>
mov    -0x14(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
jmp    1199 <ighmm_realloc+0x69>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11bb <ighmm_realloc+0x8b>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d6 <ighmm_realloc+0xa6>
mov    -0x14(%rbp),%edx
mov    $0x15,%edi
lea    0xe36(%rip),%rsi
call   1050 <mes_aux@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ighmm_realloc>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
mov    $0x1,%ebp
cmovg  %esi,%ebp
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1187 <ighmm_realloc+0x57>
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1168 <ighmm_realloc+0x38>
mov    %ebp,%esi
call   1040 <realloc@plt>
test   %rax,%rax
je     1174 <ighmm_realloc+0x44>
mov    %rax,(%rbx)
xor    %r14d,%r14d
jmp    1187 <ighmm_realloc+0x57>
mov    %ebp,%edi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1160 <ighmm_realloc+0x30>
lea    0xe85(%rip),%rsi
mov    $0x15,%edi
mov    %ebp,%edx
call   1050 <mes_aux@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"realloc: could not reallocate %d bytes\0A\00"
define i32 @ighmm_realloc(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %5
br label %10
10: ; preds = %9, %2
%11 = load i8**, i8*** %4
%12 = icmp ne i8** %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i32 -1, i32* %3
br label %36
14: ; preds = %10
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* %5
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %6
br label %26
21: ; preds = %14
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i32, i32* %5
%25 = call i8* @realloc(i8* %23, i32 %24)
store i8* %25, i8** %6
br label %26
26: ; preds = %21, %18
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %6
%31 = load i8**, i8*** %4
store i8* %30, i8** %31
store i32 0, i32* %3
br label %36
32: ; preds = %26
%33 = load i32, i32* %5
%34 = call i32 @mes_aux(i32 21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %29, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [40 x i8] c"realloc: could not reallocate %d bytes\0A\00"
define i32 @ighmm_realloc(i8** %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
%4 = select i1 %3, i32 %1, i32 1
%5 = icmp eq i8** %0, null
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = load i8*, i8** %0
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i8* @malloc(i32 %4)
br label %13
11: ; preds = %6
%12 = tail call i8* @realloc(i8* %7, i32 %4)
br label %13
13: ; preds = %11, %9
%14 = phi i8* [ %12, %11 ], [ %10, %9 ]
%15 = icmp eq i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13
store i8* %14, i8** %0
br label %19
17: ; preds = %13
%18 = tail call i32 @mes_aux(i32 21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %19
19: ; preds = %2, %17, %16
%20 = phi i32 [ 0, %16 ], [ -1, %17 ], [ -1, %2 ]
ret i32 %20
}