#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 *, size_t);
int add_byte(int c, char **lineptr, size_t slen, size_t *n) {
  char *nline;
  size_t new_size = slen + 1;
  if (new_size > *n) {
    new_size += 16 - 1;
    new_size *= 2;
    nline = realloc(*lineptr, new_size);
    if (!nline) {
      return -1;
    }
    *lineptr = nline;
    *n = new_size;
  }
  (*lineptr)[slen] = c;
  return 0;
}


x86 assembly (clang, -O0):
<add_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jbe    119d <add_byte+0x8d>
mov    -0x30(%rbp),%rax
add    $0xf,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1187 <add_byte+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <add_byte+0xa7>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_byte>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0x1(%rdx),%rax
cmp    (%rcx),%rax
jbe    114f <add_byte+0x3f>
mov    %rcx,%r15
lea    (%rbx,%rbx,1),%r12
add    $0x20,%r12
mov    0x0(%rbp),%rdi
mov    %r12,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     115b <add_byte+0x4b>
mov    %rax,0x0(%rbp)
mov    %r12,(%r15)
jmp    1153 <add_byte+0x43>
mov    0x0(%rbp),%rax
mov    %r14b,(%rax,%rbx,1)
xor    %eax,%eax
jmp    1160 <add_byte+0x50>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @add_byte(i32 %0, i8** %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i64
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i64 %2, i64* %8
store i64* %3, i64** %9
%12 = load i64, i64* %8
%13 = add i64 %12, 1
store i64 %13, i64* %11
%14 = load i64, i64* %11
%15 = load i64*, i64** %9
%16 = load i64, i64* %15
%17 = icmp ugt i64 %14, %16
br i1 %17, label %18, label %35
18: ; preds = %4
%19 = load i64, i64* %11
%20 = add i64 %19, 15
store i64 %20, i64* %11
%21 = load i64, i64* %11
%22 = mul i64 %21, 2
store i64 %22, i64* %11
%23 = load i8**, i8*** %7
%24 = load i8*, i8** %23
%25 = load i64, i64* %11
%26 = call i8* @realloc(i8* %24, i64 %25)
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %18
store i32 -1, i32* %5
br label %42
30: ; preds = %18
%31 = load i8*, i8** %10
%32 = load i8**, i8*** %7
store i8* %31, i8** %32
%33 = load i64, i64* %11
%34 = load i64*, i64** %9
store i64 %33, i64* %34
br label %35
35: ; preds = %30, %4
%36 = load i32, i32* %6
%37 = trunc i32 %36 to i8
%38 = load i8**, i8*** %7
%39 = load i8*, i8** %38
%40 = load i64, i64* %8
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %37, i8* %41
store i32 0, i32* %5
br label %42
42: ; preds = %35, %29
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
define i32 @add_byte(i32 %0, i8** nocapture %1, i64 %2, i64* nocapture %3) {
%5 = add i64 %2, 1
%6 = load i64, i64* %3
%7 = icmp ugt i64 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = load i8*, i8** %1
br label %17
10: ; preds = %4
%11 = shl i64 %2, 1
%12 = add i64 %11, 32
%13 = load i8*, i8** %1
%14 = tail call i8* @realloc(i8* %13, i64 %12)
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %10
store i8* %14, i8** %1
store i64 %12, i64* %3
br label %17
17: ; preds = %8, %16
%18 = phi i8* [ %9, %8 ], [ %14, %16 ]
%19 = trunc i32 %0 to i8
%20 = getelementptr inbounds i8, i8* %18, i64 %2
store i8 %19, i8* %20
br label %21
21: ; preds = %10, %17
%22 = phi i32 [ 0, %17 ], [ -1, %10 ]
ret i32 %22
}