#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *myrealloc(char *buff, size_t *buffsize) {
  char *newbuff;
  size_t newbuffsize = *buffsize * 2;
  newbuff = (char *)malloc(sizeof(char) * newbuffsize);
  if (newbuff) {
    memcpy(newbuff, buff, *buffsize);
    free(buff);
    buff = newbuff;
    *buffsize = newbuffsize;
  }
  return buff;
}


x86 assembly (clang, -O0):
<myrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119d <myrealloc+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myrealloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%rbx
add    %rbx,%rbx
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     116f <myrealloc+0x3f>
mov    %rax,%r12
mov    (%r14),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,(%r14)
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @myrealloc(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
%7 = load i64*, i64** %4
%8 = load i64, i64* %7
%9 = mul i64 %8, 2
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = load i64*, i64** %4
%21 = load i64, i64* %20
%22 = call i32 @memcpy(i8* %18, i8* %19, i64 %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %5
store i8* %25, i8** %3
%26 = load i64, i64* %6
%27 = load i64*, i64** %4
store i64 %26, i64* %27
br label %28
28: ; preds = %17, %2
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @myrealloc(i8* %0, i64* nocapture %1) {
%3 = load i64, i64* %1
%4 = shl i64 %3, 1
%5 = trunc i64 %4 to i32
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i64, i64* %1
%11 = tail call i32 @memcpy(i8* %7, i8* %0, i64 %10)
%12 = tail call i32 @free(i8* %0)
store i64 %4, i64* %1
br label %13
13: ; preds = %9, %2
%14 = phi i8* [ %7, %9 ], [ %0, %2 ]
ret i8* %14
}