#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(size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ solv_oom(int /*<<< orphan*/, size_t);
void *solv_realloc(void *old, size_t len) {
  if (old == 0)
    old = malloc(len ? len : 1);
  else
    old = realloc(old, len ? len : 1);
  if (!old)
    solv_oom(0, len);
  return old;
}


x86 assembly (clang, -O0):
<solv_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1183 <solv_realloc+0x53>
cmpq   $0x0,-0x10(%rbp)
je     1163 <solv_realloc+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <solv_realloc+0x41>
mov    $0x1,%eax
mov    %rax,-0x18(%rbp)
jmp    1171 <solv_realloc+0x41>
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11c2 <solv_realloc+0x92>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a3 <solv_realloc+0x73>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11b1 <solv_realloc+0x81>
mov    $0x1,%eax
mov    %rax,-0x28(%rbp)
jmp    11b1 <solv_realloc+0x81>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11d8 <solv_realloc+0xa8>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1030 <solv_oom@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solv_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rsi,%rsi
mov    $0x1,%esi
cmovne %r14,%rsi
test   %rdi,%rdi
je     114f <solv_realloc+0x1f>
call   1050 <realloc@plt>
jmp    1157 <solv_realloc+0x27>
mov    %rsi,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1169 <solv_realloc+0x39>
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <solv_oom@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @solv_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load i64, i64* %4
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i64, i64* %4
br label %13
12: ; preds = %7
br label %13
13: ; preds = %12, %10
%14 = phi i64 [ %11, %10 ], [ 1, %12 ]
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %3
br label %26
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i64, i64* %4
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i64, i64* %4
br label %23
22: ; preds = %16
br label %23
23: ; preds = %22, %20
%24 = phi i64 [ %21, %20 ], [ 1, %22 ]
%25 = call i8* @realloc(i8* %17, i64 %24)
store i8* %25, i8** %3
br label %26
26: ; preds = %23, %13
%27 = load i8*, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i64, i64* %4
%31 = call i32 @solv_oom(i32 0, i64 %30)
br label %32
32: ; preds = %29, %26
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @solv_realloc(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i64 %1, 0
%5 = select i1 %4, i64 1, i64 %1
br i1 %3, label %6, label %8
6: ; preds = %2
%7 = tail call i8* @malloc(i64 %5)
br label %10
8: ; preds = %2
%9 = tail call i8* @realloc(i8* %0, i64 %5)
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %7, %6 ], [ %9, %8 ]
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @solv_oom(i32 0, i64 %1)
br label %15
15: ; preds = %13, %10
ret i8* %11
}