#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*/ *realloc(char *, int);
int ap_str_fix_buf_size(char **dst_buf, int *dst_buf_size, int *dst_buf_pos,
                        int need_bytes) {
  int n;
  if (*dst_buf_size - *dst_buf_pos < need_bytes) {
    n = *dst_buf_size + need_bytes - (*dst_buf_size - *dst_buf_pos);
    if (NULL == realloc(*dst_buf, n))
      return 0;
    *dst_buf_size = n;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ap_str_fix_buf_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%eax
cmp    -0x24(%rbp),%eax
jge    1188 <ap_str_fix_buf_size+0x78>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
mov    -0x20(%rbp),%rdx
sub    (%rdx),%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    117f <ap_str_fix_buf_size+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    118f <ap_str_fix_buf_size+0x7f>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ap_str_fix_buf_size>:
push   %rbp
push   %r14
push   %rbx
mov    (%rsi),%ebp
mov    %ebp,%eax
sub    (%rdx),%eax
mov    $0x1,%r14d
cmp    %ecx,%eax
jge    1141 <ap_str_fix_buf_size+0x31>
mov    %rsi,%rbx
add    %ecx,%ebp
sub    %eax,%ebp
mov    (%rdi),%rdi
mov    %ebp,%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     113e <ap_str_fix_buf_size+0x2e>
mov    %ebp,(%rbx)
jmp    1141 <ap_str_fix_buf_size+0x31>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ap_str_fix_buf_size(i8** %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%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
%11 = load i32*, i32** %7
%12 = load i32, i32* %11
%13 = load i32*, i32** %8
%14 = load i32, i32* %13
%15 = sub nsw i32 %12, %14
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %38
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = load i32, i32* %9
%22 = add nsw i32 %20, %21
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = load i32*, i32** %8
%26 = load i32, i32* %25
%27 = sub nsw i32 %24, %26
%28 = sub nsw i32 %22, %27
store i32 %28, i32* %10
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
%31 = load i32, i32* %10
%32 = call i32* @realloc(i8* %30, i32 %31)
%33 = icmp eq i32* null, %32
br i1 %33, label %34, label %35
34: ; preds = %18
store i32 0, i32* %5
br label %39
35: ; preds = %18
%36 = load i32, i32* %10
%37 = load i32*, i32** %7
store i32 %36, i32* %37
br label %38
38: ; preds = %35, %4
store i32 1, i32* %5
br label %39
39: ; preds = %38, %34
%40 = load i32, i32* %5
ret i32 %40
}

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