#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, unsigned int);
int strlen(char const *);
void al_resize_char_buffer(char **dest, const char *buf, unsigned int *destlen,
                           int step) {
  if ((strlen(*dest) + strlen(buf) + 1) > *destlen) {
    *destlen = *destlen + step;
    char *newbuf = realloc(*dest, *destlen);
    if (newbuf == NULL) {
      perror("ERROR: can't allocate larger prompt buffer");
      free(*dest);
      exit(EXIT_FAILURE);
    } else {
      *dest = newbuf;
    }
  }
}


x86 assembly (clang, -O0):
<al_resize_char_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jbe    11fb <al_resize_char_buffer+0xab>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11eb <al_resize_char_buffer+0x9b>
lea    0xe34(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11fb <al_resize_char_buffer+0xab>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<al_resize_char_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
mov    (%r12),%esi
cmp    %esi,%eax
jbe    119a <al_resize_char_buffer+0x4a>
add    %r15d,%esi
mov    %esi,(%r12)
mov    (%r14),%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11a3 <al_resize_char_buffer+0x53>
mov    %rax,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe56(%rip),%rdi
call   1060 <perror@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"ERROR: can't allocate larger prompt buffer\00"
@EXIT_FAILURE = global i32 0
define void @al_resize_char_buffer(i8** %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = add nsw i32 %15, 1
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = icmp ugt i32 %16, %18
br i1 %19, label %20, label %44
20: ; preds = %4
%21 = load i32*, i32** %7
%22 = load i32, i32* %21
%23 = load i32, i32* %8
%24 = add i32 %22, %23
%25 = load i32*, i32** %7
store i32 %24, i32* %25
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = call i8* @realloc(i8* %27, i32 %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %40
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %20
%41 = load i8*, i8** %9
%42 = load i8**, i8*** %5
store i8* %41, i8** %42
br label %43
43: ; preds = %40
br label %44
44: ; preds = %43, %4
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"ERROR: can't allocate larger prompt buffer\00"
@EXIT_FAILURE = global i32 0
define void @al_resize_char_buffer(i8** nocapture %0, i8* %1, i32* nocapture %2, i32 %3) {
%5 = load i8*, i8** %0
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i32 @strlen(i8* %1)
%8 = add i32 %6, 1
%9 = add i32 %8, %7
%10 = load i32, i32* %2
%11 = icmp ugt i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %4
%13 = add i32 %10, %3
store i32 %13, i32* %2
%14 = load i8*, i8** %0
%15 = tail call i8* @realloc(i8* %14, i32 %13)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %0
%20 = tail call i32 @free(i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
store i8* %15, i8** %0
br label %24
24: ; preds = %23, %4
ret void
}