#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
void *realloc(int /*<<< orphan*/ *, unsigned int);
unsigned RangeCoderWriteRealloc(__attribute__((unused)) void *user,
                                uint8_t **data, unsigned *size) {
  void *tmp;
  unsigned n;
  n = *size;
  if ((tmp = realloc(*data, n + 8192))) {
    *data = tmp;
    *size = n + 4096;
    return n;
  }
  return n - 1;
}


x86 assembly (clang, -O0):
<RangeCoderWriteRealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x2c(%rbp),%esi
add    $0x2000,%esi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1175 <RangeCoderWriteRealloc+0x65>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%ecx
add    $0x1000,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117e <RangeCoderWriteRealloc+0x6e>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RangeCoderWriteRealloc>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    (%rdx),%ebx
mov    (%rsi),%rdi
lea    0x2000(%rbx),%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     113e <RangeCoderWriteRealloc+0x2e>
mov    %rax,(%r15)
lea    0x1000(%rbx),%eax
mov    %eax,(%r14)
jmp    1141 <RangeCoderWriteRealloc+0x31>
add    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @RangeCoderWriteRealloc(i8* %0, i32** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
%10 = load i32*, i32** %7
%11 = load i32, i32* %10
store i32 %11, i32* %9
%12 = load i32**, i32*** %6
%13 = load i32*, i32** %12
%14 = load i32, i32* %9
%15 = add i32 %14, 8192
%16 = call i8* @realloc(i32* %13, i32 %15)
store i8* %16, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %26
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = bitcast i8* %19 to i32*
%21 = load i32**, i32*** %6
store i32* %20, i32** %21
%22 = load i32, i32* %9
%23 = add i32 %22, 4096
%24 = load i32*, i32** %7
store i32 %23, i32* %24
%25 = load i32, i32* %9
store i32 %25, i32* %4
br label %29
26: ; preds = %3
%27 = load i32, i32* %9
%28 = sub i32 %27, 1
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %18
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @RangeCoderWriteRealloc(i8* nocapture readnone %0, i32** nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = load i32*, i32** %1
%6 = add i32 %4, 8192
%7 = tail call i8* @realloc(i32* %5, i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = bitcast i32** %1 to i8**
store i8* %7, i8** %10
%11 = add i32 %4, 4096
store i32 %11, i32* %2
br label %14
12: ; preds = %3
%13 = add i32 %4, -1
br label %14
14: ; preds = %12, %9
%15 = phi i32 [ %4, %9 ], [ %13, %12 ]
ret i32 %15
}