#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 *av_realloc(void *, unsigned int);
void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) {
  if (min_size < *size)
    return ptr;
  *size = ((17 * min_size / 16 + 32) > (min_size) ? (17 * min_size / 16 + 32)
                                                  : (min_size));
  ptr = av_realloc(ptr, *size);
  if (!ptr)
    *size = 0;
  return ptr;
}


x86 assembly (clang, -O0):
<av_fast_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jae    113f <av_fast_realloc+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <av_fast_realloc+0x93>
imul   $0x11,-0x1c(%rbp),%eax
shr    $0x4,%eax
add    $0x20,%eax
cmp    -0x1c(%rbp),%eax
jbe    1164 <av_fast_realloc+0x54>
imul   $0x11,-0x1c(%rbp),%eax
shr    $0x4,%eax
add    $0x20,%eax
mov    %eax,-0x20(%rbp)
jmp    116a <av_fast_realloc+0x5a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <av_realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <av_fast_realloc+0x8b>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<av_fast_realloc>:
push   %rbx
mov    %rdi,%rax
cmp    %edx,(%rsi)
ja     113c <av_fast_realloc+0x2c>
mov    %rsi,%rbx
mov    %edx,%esi
shl    $0x4,%esi
add    %edx,%esi
shr    $0x4,%esi
add    $0x20,%esi
cmp    %edx,%esi
cmovbe %edx,%esi
mov    %esi,(%rbx)
mov    %rax,%rdi
call   1030 <av_realloc@plt>
test   %rax,%rax
je     113e <av_fast_realloc+0x2e>
pop    %rbx
ret
movl   $0x0,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @av_fast_realloc(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = load i32*, i32** %6
%10 = load i32, i32* %9
%11 = icmp ult i32 %8, %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i8*, i8** %5
store i8* %13, i8** %4
br label %41
14: ; preds = %3
%15 = load i32, i32* %7
%16 = mul i32 17, %15
%17 = udiv i32 %16, 16
%18 = add i32 %17, 32
%19 = load i32, i32* %7
%20 = icmp ugt i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i32, i32* %7
%23 = mul i32 17, %22
%24 = udiv i32 %23, 16
%25 = add i32 %24, 32
br label %28
26: ; preds = %14
%27 = load i32, i32* %7
br label %28
28: ; preds = %26, %21
%29 = phi i32 [ %25, %21 ], [ %27, %26 ]
%30 = load i32*, i32** %6
store i32 %29, i32* %30
%31 = load i8*, i8** %5
%32 = load i32*, i32** %6
%33 = load i32, i32* %32
%34 = call i8* @av_realloc(i8* %31, i32 %33)
store i8* %34, i8** %5
%35 = load i8*, i8** %5
%36 = icmp ne i8* %35, null
br i1 %36, label %39, label %37
37: ; preds = %28
%38 = load i32*, i32** %6
store i32 0, i32* %38
br label %39
39: ; preds = %37, %28
%40 = load i8*, i8** %5
store i8* %40, i8** %4
br label %41
41: ; preds = %39, %12
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
define i8* @av_fast_realloc(i8* %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = icmp ugt i32 %4, %2
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = mul i32 %2, 17
%8 = lshr i32 %7, 4
%9 = add nuw nsw i32 %8, 32
%10 = icmp ugt i32 %9, %2
%11 = select i1 %10, i32 %9, i32 %2
store i32 %11, i32* %1
%12 = tail call i8* @av_realloc(i8* %0, i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %6
store i32 0, i32* %1
br label %15
15: ; preds = %6, %14, %3
%16 = phi i8* [ %0, %3 ], [ null, %14 ], [ %12, %6 ]
ret i8* %16
}