#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 */
scalar_t__ realloc(void *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *AddLine(char *line) {
  static int nCharAllocated = 0;
  static int nCharInUse = 0;
  static char *szResult;
  int nCharAvailable, nCharRequested, nCharAdditional;
  if (line == NULL) {
    nCharInUse = 0;
    return (NULL);
  }
  nCharAvailable = nCharAllocated - nCharInUse - 1;
  nCharRequested = strlen(line);
  if (nCharRequested == 0)
    return (szResult);
  nCharRequested += 1;
  if (nCharAvailable < nCharRequested) {
    nCharAdditional = (nCharRequested > 250) ? nCharRequested : 250;
    szResult =
        (char *)realloc((void *)szResult, nCharAllocated + nCharAdditional);
    nCharAllocated += 250;
  }
  if (szResult != NULL) {
    if (nCharInUse == 0)
      strcpy(szResult, line);
    else
      strcat(szResult, line);
    strcat(szResult, " ");
    nCharInUse += nCharRequested;
  }
  return (szResult);
}


x86 assembly (clang, -O0):
<AddLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <AddLine+0x2e>
movl   $0x0,0x2eeb(%rip)
movq   $0x0,-0x8(%rbp)
jmp    1280 <AddLine+0x140>
mov    0x2ed4(%rip),%eax
sub    0x2ed2(%rip),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a6 <AddLine+0x66>
mov    0x2eb3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1280 <AddLine+0x140>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1213 <AddLine+0xd3>
cmpl   $0xfa,-0x18(%rbp)
jle    11d3 <AddLine+0x93>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11e0 <AddLine+0xa0>
mov    $0xfa,%eax
mov    %eax,-0x20(%rbp)
jmp    11e0 <AddLine+0xa0>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e63(%rip),%rdi
mov    0x2e55(%rip),%esi
add    -0x1c(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,0x2e4e(%rip)
mov    0x2e40(%rip),%eax
add    $0xfa,%eax
mov    %eax,0x2e35(%rip)
cmpq   $0x0,0x2e35(%rip)
je     1275 <AddLine+0x135>
cmpl   $0x0,0x2e24(%rip)
jne    1243 <AddLine+0x103>
mov    0x2e1b(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1253 <AddLine+0x113>
mov    0x2e06(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    0x2df6(%rip),%rdi
lea    0xd9f(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%eax
add    0x2ddd(%rip),%eax
mov    %eax,0x2dd7(%rip)
mov    0x2dd4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AddLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1193 <AddLine+0x53>
mov    %rdi,%r15
mov    0x2ef3(%rip),%ebp
mov    0x2ef1(%rip),%ebx
call   1040 <strlen@plt>
test   %eax,%eax
je     1202 <AddLine+0xc2>
not    %ebx
add    %ebx,%ebp
lea    0x1(%rax),%r14d
cmp    %eax,%ebp
jle    11a1 <AddLine+0x61>
mov    0x2ed5(%rip),%rdi
test   %rdi,%rdi
je     11dc <AddLine+0x9c>
cmpl   $0x0,0x2ec5(%rip)
je     11e0 <AddLine+0xa0>
mov    %r15,%rsi
call   1060 <strcat@plt>
jmp    11e8 <AddLine+0xa8>
movl   $0x0,0x2eaf(%rip)
xor    %eax,%eax
jmp    1209 <AddLine+0xc9>
cmp    $0xfb,%r14d
mov    $0xfa,%esi
cmovge %r14d,%esi
mov    0x2e98(%rip),%rdi
add    0x2e8a(%rip),%esi
call   1050 <realloc@plt>
mov    %rax,%rdi
mov    %rax,0x2e83(%rip)
addl   $0xfa,0x2e71(%rip)
test   %rdi,%rdi
jne    1180 <AddLine+0x40>
xor    %eax,%eax
jmp    1209 <AddLine+0xc9>
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    0x2e61(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   1060 <strcat@plt>
add    %r14d,0x2e4a(%rip)
mov    0x2e47(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AddLine.nCharAllocated = internal global i32 0
@AddLine.nCharInUse = internal global i32 0
@AddLine.szResult = internal global i8* null
@.str = [2 x i8] c" \00"
define i8* @AddLine(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* @AddLine.nCharInUse
store i8* null, i8** %2
br label %65
10: ; preds = %1
%11 = load i32, i32* @AddLine.nCharAllocated
%12 = load i32, i32* @AddLine.nCharInUse
%13 = sub nsw i32 %11, %12
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %4
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = load i8*, i8** @AddLine.szResult
store i8* %20, i8** %2
br label %65
21: ; preds = %10
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %21
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 250
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* %5
br label %33
32: ; preds = %27
br label %33
33: ; preds = %32, %30
%34 = phi i32 [ %31, %30 ], [ 250, %32 ]
store i32 %34, i32* %6
%35 = load i8*, i8** @AddLine.szResult
%36 = load i32, i32* @AddLine.nCharAllocated
%37 = load i32, i32* %6
%38 = add nsw i32 %36, %37
%39 = call i64 @realloc(i8* %35, i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** @AddLine.szResult
%41 = load i32, i32* @AddLine.nCharAllocated
%42 = add nsw i32 %41, 250
store i32 %42, i32* @AddLine.nCharAllocated
br label %43
43: ; preds = %33, %21
%44 = load i8*, i8** @AddLine.szResult
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %63
46: ; preds = %43
%47 = load i32, i32* @AddLine.nCharInUse
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i8*, i8** @AddLine.szResult
%51 = load i8*, i8** %3
%52 = call i32 @strcpy(i8* %50, i8* %51)
br label %57
53: ; preds = %46
%54 = load i8*, i8** @AddLine.szResult
%55 = load i8*, i8** %3
%56 = call i32 @strcat(i8* %54, i8* %55)
br label %57
57: ; preds = %53, %49
%58 = load i8*, i8** @AddLine.szResult
%59 = call i32 @strcat(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%60 = load i32, i32* %5
%61 = load i32, i32* @AddLine.nCharInUse
%62 = add nsw i32 %61, %60
store i32 %62, i32* @AddLine.nCharInUse
br label %63
63: ; preds = %57, %43
%64 = load i8*, i8** @AddLine.szResult
store i8* %64, i8** %2
br label %65
65: ; preds = %63, %19, %9
%66 = load i8*, i8** %2
ret i8* %66
}

LLVM IR (-O2):
@AddLine.nCharAllocated = internal unnamed_addr global i32 0
@AddLine.nCharInUse = internal unnamed_addr global i32 0
@AddLine.szResult = internal unnamed_addr global i8* null
@.str = [2 x i8] c" \00"
define i8* @AddLine(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %4
3: ; preds = %1
store i32 0, i32* @AddLine.nCharInUse
br label %44
4: ; preds = %1
%5 = load i32, i32* @AddLine.nCharAllocated
%6 = load i32, i32* @AddLine.nCharInUse
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = load i8*, i8** @AddLine.szResult
br label %44
11: ; preds = %4
%12 = xor i32 %6, -1
%13 = add i32 %5, %12
%14 = add nsw i32 %7, 1
%15 = icmp sgt i32 %13, %7
br i1 %15, label %26, label %16
16: ; preds = %11
%17 = icmp sgt i32 %14, 250
%18 = select i1 %17, i32 %14, i32 250
%19 = load i8*, i8** @AddLine.szResult
%20 = load i32, i32* @AddLine.nCharAllocated
%21 = add nsw i32 %20, %18
%22 = tail call i64 @realloc(i8* %19, i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** @AddLine.szResult
%24 = load i32, i32* @AddLine.nCharAllocated
%25 = add nsw i32 %24, 250
store i32 %25, i32* @AddLine.nCharAllocated
br label %28
26: ; preds = %11
%27 = load i8*, i8** @AddLine.szResult
br label %28
28: ; preds = %26, %16
%29 = phi i8* [ %27, %26 ], [ %23, %16 ]
%30 = icmp eq i8* %29, null
br i1 %30, label %44, label %31
31: ; preds = %28
%32 = load i32, i32* @AddLine.nCharInUse
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @strcpy(i8* %29, i8* %0)
br label %38
36: ; preds = %31
%37 = tail call i32 @strcat(i8* %29, i8* %0)
br label %38
38: ; preds = %36, %34
%39 = load i8*, i8** @AddLine.szResult
%40 = tail call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* @AddLine.nCharInUse
%42 = add nsw i32 %41, %14
store i32 %42, i32* @AddLine.nCharInUse
%43 = load i8*, i8** @AddLine.szResult
br label %44
44: ; preds = %28, %38, %9, %3
%45 = phi i8* [ null, %3 ], [ %10, %9 ], [ %43, %38 ], [ null, %28 ]
ret i8* %45
}