#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*/ memset(unsigned char *, int /*<<< orphan*/, unsigned int);
unsigned char *realloc(unsigned char *, unsigned int);
void resize_mem(unsigned char *mem, unsigned int index, unsigned int size,
                unsigned int max_index, unsigned int min_mem) {
  while (index >= size) {
    mem = realloc(mem, size * 2);
    memset(mem + size, 0, size);
    size *= 2;
  }
  if (max_index < min_mem && min_mem > 16) {
    mem = realloc(mem, min_mem);
    size = min_mem;
  }
  min_mem = size * 0.75 + 1;
  return;
}


x86 assembly (clang, -O0):
<resize_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jb     117a <resize_mem+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
shl    $0x1,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1139 <resize_mem+0x19>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11a6 <resize_mem+0x86>
cmpl   $0x10,-0x18(%rbp)
jbe    11a6 <resize_mem+0x86>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe4a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe46(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x18(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %rdi,%r13
cmp    %esi,%edx
ja     1166 <resize_mem+0x46>
mov    %edx,%ebp
mov    %esi,%r12d
nopl   (%rax)
lea    0x0(%rbp,%rbp,1),%ebx
mov    %r13,%rdi
mov    %ebx,%esi
call   1040 <realloc@plt>
mov    %rax,%r13
mov    %ebp,%edi
add    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
mov    %ebx,%ebp
cmp    %r12d,%ebx
jbe    1140 <resize_mem+0x20>
cmp    %r15d,%r14d
jae    118a <resize_mem+0x6a>
cmp    $0x11,%r15d
jb     118a <resize_mem+0x6a>
mov    %r13,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <realloc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @resize_mem(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
br label %11
11: ; preds = %15, %5
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = icmp uge i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i32, i32* %8
%18 = mul i32 %17, 2
%19 = call i8* @realloc(i8* %16, i32 %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %8
%25 = call i32 @memset(i8* %23, i32 0, i32 %24)
%26 = load i32, i32* %8
%27 = mul i32 %26, 2
store i32 %27, i32* %8
br label %11
28: ; preds = %11
%29 = load i32, i32* %9
%30 = load i32, i32* %10
%31 = icmp ult i32 %29, %30
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = load i32, i32* %10
%34 = icmp ugt i32 %33, 16
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = load i32, i32* %10
%38 = call i8* @realloc(i8* %36, i32 %37)
store i8* %38, i8** %6
%39 = load i32, i32* %10
store i32 %39, i32* %8
br label %40
40: ; preds = %35, %32, %28
%41 = load i32, i32* %8
%42 = uitofp i32 %41 to double
%43 = call double @llvm.fmuladd.f64(double %42, double 7.500000e-01, double 1.000000e+00)
%44 = fptoui double %43 to i32
store i32 %44, i32* %10
ret void
}

LLVM IR (-O2):
define void @resize_mem(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp ugt i32 %2, %1
br i1 %6, label %16, label %7
7: ; preds = %5, %7
%8 = phi i8* [ %11, %7 ], [ %0, %5 ]
%9 = phi i32 [ %10, %7 ], [ %2, %5 ]
%10 = shl i32 %9, 1
%11 = tail call i8* @realloc(i8* %8, i32 %10)
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = tail call i32 @memset(i8* %13, i32 0, i32 %9)
%15 = icmp ugt i32 %10, %1
br i1 %15, label %16, label %7
16: ; preds = %7, %5
%17 = phi i8* [ %0, %5 ], [ %11, %7 ]
%18 = icmp ult i32 %3, %4
%19 = icmp ugt i32 %4, 16
%20 = and i1 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i8* @realloc(i8* %17, i32 %4)
br label %23
23: ; preds = %21, %16
ret void
}