#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 BUFSIZ;
char *malloc(size_t);
char *realloc(char *, size_t);
int strlen(char *);
char *getoutputbuffer(char *str) {
  static char *rv;
  static size_t len = 0;
  size_t req;
  req = ((2 * strlen(str) + 2) > (BUFSIZ) ? (2 * strlen(str) + 2) : (BUFSIZ));
  if (req > len) {
    if (rv)
      rv = realloc(rv, req);
    else
      rv = malloc(req);
    len = req;
  }
  return rv;
}


x86 assembly (clang, -O0):
<getoutputbuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
shl    $0x1,%eax
add    $0x2,%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
jle    1171 <getoutputbuffer+0x41>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
shl    $0x1,%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <getoutputbuffer+0x4d>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    0x2eb7(%rip),%rax
jbe    11dc <getoutputbuffer+0xac>
cmpq   $0x0,0x2ea1(%rip)
je     11c1 <getoutputbuffer+0x91>
mov    0x2e94(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,0x2e84(%rip)
jmp    11d1 <getoutputbuffer+0xa1>
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,0x2e6f(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,0x2e6c(%rip)
mov    0x2e5d(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getoutputbuffer>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%ecx
add    $0x2,%ecx
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ecx
jle    1159 <getoutputbuffer+0x29>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %eax,%eax
add    $0x2,%eax
movslq %eax,%rbx
mov    0x2edd(%rip),%rax
cmp    %rbx,0x2ede(%rip)
jae    1194 <getoutputbuffer+0x64>
test   %rax,%rax
je     117e <getoutputbuffer+0x4e>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
jmp    1186 <getoutputbuffer+0x56>
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,0x2eb3(%rip)
mov    %rbx,0x2eb4(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@getoutputbuffer.rv = internal global i8* null
@getoutputbuffer.len = internal global i64 0
@BUFSIZ = global i32 0
define i8* @getoutputbuffer(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = mul nsw i32 2, %5
%7 = add nsw i32 %6, 2
%8 = load i32, i32* @BUFSIZ
%9 = icmp sgt i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = mul nsw i32 2, %12
%14 = add nsw i32 %13, 2
br label %17
15: ; preds = %1
%16 = load i32, i32* @BUFSIZ
br label %17
17: ; preds = %15, %10
%18 = phi i32 [ %14, %10 ], [ %16, %15 ]
%19 = sext i32 %18 to i64
store i64 %19, i64* %3
%20 = load i64, i64* %3
%21 = load i64, i64* @getoutputbuffer.len
%22 = icmp ugt i64 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %17
%24 = load i8*, i8** @getoutputbuffer.rv
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** @getoutputbuffer.rv
%28 = load i64, i64* %3
%29 = call i8* @realloc(i8* %27, i64 %28)
store i8* %29, i8** @getoutputbuffer.rv
br label %33
30: ; preds = %23
%31 = load i64, i64* %3
%32 = call i8* @malloc(i64 %31)
store i8* %32, i8** @getoutputbuffer.rv
br label %33
33: ; preds = %30, %26
%34 = load i64, i64* %3
store i64 %34, i64* @getoutputbuffer.len
br label %35
35: ; preds = %33, %17
%36 = load i8*, i8** @getoutputbuffer.rv
ret i8* %36
}

LLVM IR (-O2):
@getoutputbuffer.rv = internal unnamed_addr global i8* null
@getoutputbuffer.len = internal unnamed_addr global i64 0
@BUFSIZ = global i32 0
define i8* @getoutputbuffer(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = add nsw i32 %3, 2
%5 = load i32, i32* @BUFSIZ
%6 = icmp sgt i32 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @strlen(i8* %0)
%9 = shl nsw i32 %8, 1
%10 = add nsw i32 %9, 2
br label %11
11: ; preds = %1, %7
%12 = phi i32 [ %10, %7 ], [ %5, %1 ]
%13 = sext i32 %12 to i64
%14 = load i64, i64* @getoutputbuffer.len
%15 = icmp ult i64 %14, %13
%16 = load i8*, i8** @getoutputbuffer.rv
br i1 %15, label %17, label %25
17: ; preds = %11
%18 = icmp eq i8* %16, null
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = tail call i8* @realloc(i8* %16, i64 %13)
br label %23
21: ; preds = %17
%22 = tail call i8* @malloc(i64 %13)
br label %23
23: ; preds = %21, %19
%24 = phi i8* [ %22, %21 ], [ %20, %19 ]
store i8* %24, i8** @getoutputbuffer.rv
store i64 %13, i64* @getoutputbuffer.len
br label %25
25: ; preds = %11, %23
%26 = phi i8* [ %24, %23 ], [ %16, %11 ]
ret i8* %26
}