#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 */
char *realloc(char *, int);
void shrink_buffer(char **buffer, char **pointer, char **max) {
  if (*max - *buffer != 4096) {
    *buffer = realloc(*buffer, 4096);
    *max = *buffer + 4096;
  }
  if (*pointer != *buffer)
    *pointer = *buffer;
  **pointer = 0;
}


x86 assembly (clang, -O0):
<shrink_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
cmp    $0x1000,%rax
je     1171 <shrink_buffer+0x61>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1000,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1000,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
je     1193 <shrink_buffer+0x83>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shrink_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdx),%rax
mov    (%rdi),%rdi
sub    %rdi,%rax
cmp    $0x1000,%rax
je     1148 <shrink_buffer+0x38>
mov    %rdx,%r15
mov    $0x1000,%esi
call   1030 <realloc@plt>
mov    %rax,(%rbx)
add    $0x1000,%rax
mov    %rax,(%r15)
mov    (%rbx),%rdi
cmp    %rdi,(%r14)
je     1150 <shrink_buffer+0x40>
mov    %rdi,(%r14)
movb   $0x0,(%rdi)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @shrink_buffer(i8** %0, i8** %1, i8** %2) {
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8**
store i8** %0, i8*** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%7 = load i8**, i8*** %6
%8 = load i8*, i8** %7
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = ptrtoint i8* %8 to i64
%12 = ptrtoint i8* %10 to i64
%13 = sub i64 %11, %12
%14 = icmp ne i64 %13, 4096
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = call i8* @realloc(i8* %17, i32 4096)
%19 = load i8**, i8*** %4
store i8* %18, i8** %19
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 4096
%23 = load i8**, i8*** %6
store i8* %22, i8** %23
br label %24
24: ; preds = %15, %3
%25 = load i8**, i8*** %5
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = icmp ne i8* %26, %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
store i8* %32, i8** %33
br label %34
34: ; preds = %30, %24
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
store i8 0, i8* %36
ret void
}

LLVM IR (-O2):
define void @shrink_buffer(i8** nocapture %0, i8** nocapture %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = load i8*, i8** %0
%6 = ptrtoint i8* %4 to i64
%7 = ptrtoint i8* %5 to i64
%8 = sub i64 %6, %7
%9 = icmp eq i64 %8, 4096
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = tail call i8* @realloc(i8* %5, i32 4096)
store i8* %11, i8** %0
%12 = getelementptr inbounds i8, i8* %11, i64 4096
store i8* %12, i8** %2
%13 = load i8*, i8** %0
br label %14
14: ; preds = %10, %3
%15 = phi i8* [ %13, %10 ], [ %5, %3 ]
%16 = load i8*, i8** %1
%17 = icmp eq i8* %16, %15
br i1 %17, label %19, label %18
18: ; preds = %14
store i8* %15, i8** %1
br label %19
19: ; preds = %18, %14
store i8 0, i8* %15
ret void
}