#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*/ cst_free(char *);
scalar_t__ cst_safe_alloc(int);
int /*<<< orphan*/ memmove(char *, char *, int);
void extend_buffer(char **buffer, int *buffer_max) {
  int new_max;
  char *new_buffer;
  new_max = (*buffer_max) + (*buffer_max) / 5;
  new_buffer = ((char *)cst_safe_alloc(sizeof(char) * (new_max)));
  memmove(new_buffer, *buffer, *buffer_max);
  cst_free(*buffer);
  *buffer = new_buffer;
  *buffer_max = new_max;
}


x86 assembly (clang, -O0):
<extend_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <cst_safe_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <cst_free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extend_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movslq (%rsi),%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rbx
add    %ecx,%ebx
add    %eax,%ebx
mov    %ebx,%edi
call   1030 <cst_safe_alloc@plt>
mov    %rax,%r12
mov    (%r15),%rsi
mov    (%r14),%edx
mov    %rax,%rdi
call   1040 <memmove@plt>
mov    (%r15),%rdi
call   1050 <cst_free@plt>
mov    %r12,(%r15)
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @extend_buffer(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = load i32*, i32** %4
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 5
%12 = add nsw i32 %8, %11
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @cst_safe_alloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = load i8**, i8*** %3
%21 = load i8*, i8** %20
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = call i32 @memmove(i8* %19, i8* %21, i32 %23)
%25 = load i8**, i8*** %3
%26 = load i8*, i8** %25
%27 = call i32 @cst_free(i8* %26)
%28 = load i8*, i8** %6
%29 = load i8**, i8*** %3
store i8* %28, i8** %29
%30 = load i32, i32* %5
%31 = load i32*, i32** %4
store i32 %30, i32* %31
ret void
}

LLVM IR (-O2):
define void @extend_buffer(i8** nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = sdiv i32 %3, 5
%5 = add nsw i32 %4, %3
%6 = tail call i64 @cst_safe_alloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i8*, i8** %0
%9 = load i32, i32* %1
%10 = tail call i32 @memmove(i8* %7, i8* %8, i32 %9)
%11 = load i8*, i8** %0
%12 = tail call i32 @cst_free(i8* %11)
store i8* %7, i8** %0
store i32 %5, i32* %1
ret void
}