#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*/ sqlite3FailedMalloc();
void *sqlite3GenericRealloc(void *, int);
void *sqlite3Malloc(int, int);
scalar_t__ sqlite3MallocFailed();
void *sqlite3Realloc(void *p, int n) {
  if (sqlite3MallocFailed()) {
    return 0;
  }
  if (!p) {
    return sqlite3Malloc(n, 1);
  } else {
    void *np = 0;
    if (1) {
      while ((np = sqlite3GenericRealloc(p, n)) == 0 && 0) {
      }
      if (!np) {
        sqlite3FailedMalloc();
        ;
      } else {
        ;
      }
    }
    return np;
  }
}


x86 assembly (clang, -O0):
<sqlite3Realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1030 <sqlite3MallocFailed@plt>
cmp    $0x0,%rax
je     116d <sqlite3Realloc+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    11fb <sqlite3Realloc+0xbb>
cmpq   $0x0,-0x10(%rbp)
jne    118e <sqlite3Realloc+0x4e>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1060 <sqlite3Malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11fb <sqlite3Realloc+0xbb>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <sqlite3GenericRealloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    11c2 <sqlite3Realloc+0x82>
xor    %eax,%eax
mov    %al,-0x21(%rbp)
jmp    11c2 <sqlite3Realloc+0x82>
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11d2 <sqlite3Realloc+0x92>
jmp    11d7 <sqlite3Realloc+0x97>
jmp    1196 <sqlite3Realloc+0x56>
cmpq   $0x0,-0x20(%rbp)
jne    11ee <sqlite3Realloc+0xae>
mov    $0x0,%al
call   1040 <sqlite3FailedMalloc@plt>
jmp    11f3 <sqlite3Realloc+0xb3>
jmp    11f3 <sqlite3Realloc+0xb3>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3Realloc>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <sqlite3MallocFailed@plt>
test   %rax,%rax
je     1160 <sqlite3Realloc+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %rbp,%rbp
je     1183 <sqlite3Realloc+0x43>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <sqlite3GenericRealloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1158 <sqlite3Realloc+0x18>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <sqlite3FailedMalloc@plt>
jmp    1158 <sqlite3Realloc+0x18>
mov    %r14d,%edi
mov    $0x1,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <sqlite3Malloc@plt>

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

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