#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 EOF;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *realloc(char *, size_t);
int /*<<< orphan*/ stdin;
char *linenoiseNoTTY(void) {
  char *line = NULL;
  size_t len = 0, maxlen = 0;
  while (1) {
    if (len == maxlen) {
      if (maxlen == 0)
        maxlen = 16;
      maxlen *= 2;
      char *oldval = line;
      line = realloc(line, maxlen);
      if (line == NULL) {
        free(oldval);
        return NULL;
      }
    }
    int c = fgetc(stdin);
    if (c == EOF || c == '\n') {
      if (c == EOF && len == 0) {
        free(line);
        return NULL;
      } else {
        line[len] = '\0';
        return line;
      }
    } else {
      line[len] = c;
      len++;
    }
  }
}


x86 assembly (clang, -O0):
<linenoiseNoTTY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11bc <linenoiseNoTTY+0x8c>
cmpq   $0x0,-0x20(%rbp)
jne    1171 <linenoiseNoTTY+0x41>
movq   $0x10,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <linenoiseNoTTY+0x87>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1256 <linenoiseNoTTY+0x126>
jmp    11bc <linenoiseNoTTY+0x8c>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%eax
je     11e9 <linenoiseNoTTY+0xb9>
cmpl   $0xa,-0x2c(%rbp)
jne    1235 <linenoiseNoTTY+0x105>
mov    -0x2c(%rbp),%eax
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%eax
jne    121c <linenoiseNoTTY+0xec>
cmpq   $0x0,-0x18(%rbp)
jne    121c <linenoiseNoTTY+0xec>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1256 <linenoiseNoTTY+0x126>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1256 <linenoiseNoTTY+0x126>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1150 <linenoiseNoTTY+0x20>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linenoiseNoTTY>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
mov    0x2e9b(%rip),%rbp
xor    %r12d,%r12d
xor    %ebx,%ebx
xor    %r15d,%r15d
cmp    %rbx,%r12
jne    1190 <linenoiseNoTTY+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %r12,%r12
mov    %r13,%rbx
mov    $0x20,%eax
cmove  %rax,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1193 <linenoiseNoTTY+0x63>
jmp    11d1 <linenoiseNoTTY+0xa1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%r14
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    0x0(%rbp),%ecx
cmp    $0xa,%eax
je     11c3 <linenoiseNoTTY+0x93>
cmp    %ecx,%eax
je     11c3 <linenoiseNoTTY+0x93>
mov    %al,(%r14,%r12,1)
add    $0x1,%r12
add    $0x2,%r13
mov    %r14,%r15
cmp    %rbx,%r12
jne    1190 <linenoiseNoTTY+0x60>
jmp    1160 <linenoiseNoTTY+0x30>
cmp    %ecx,%eax
jne    11de <linenoiseNoTTY+0xae>
test   %r12,%r12
jne    11de <linenoiseNoTTY+0xae>
mov    %r14,%rdi
jmp    11d4 <linenoiseNoTTY+0xa4>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
jmp    11e3 <linenoiseNoTTY+0xb3>
movb   $0x0,(%r14,%r12,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i8* @linenoiseNoTTY() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* null, i8** %2
store i64 0, i64* %3
store i64 0, i64* %4
br label %7
7: ; preds = %0, %60
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i64 16, i64* %4
br label %15
15: ; preds = %14, %11
%16 = load i64, i64* %4
%17 = mul i64 %16, 2
store i64 %17, i64* %4
%18 = load i8*, i8** %2
store i8* %18, i8** %5
%19 = load i8*, i8** %2
%20 = load i64, i64* %4
%21 = call i8* @realloc(i8* %19, i64 %20)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
store i8* null, i8** %1
br label %61
27: ; preds = %15
br label %28
28: ; preds = %27, %7
%29 = load i32, i32* @stdin
%30 = call i32 @fgetc(i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %37, label %34
34: ; preds = %28
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %52
37: ; preds = %34, %28
%38 = load i32, i32* %6
%39 = load i32, i32* @EOF
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i64, i64* %3
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8*, i8** %2
%46 = call i32 @free(i8* %45)
store i8* null, i8** %1
br label %61
47: ; preds = %41, %37
%48 = load i8*, i8** %2
%49 = load i64, i64* %3
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %2
store i8* %51, i8** %1
br label %61
52: ; preds = %34
%53 = load i32, i32* %6
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %2
%56 = load i64, i64* %3
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8 %54, i8* %57
%58 = load i64, i64* %3
%59 = add i64 %58, 1
store i64 %59, i64* %3
br label %60
60: ; preds = %52
br label %7
61: ; preds = %47, %44, %24
%62 = load i8*, i8** %1
ret i8* %62
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define noalias i8* @linenoiseNoTTY() {
br label %1
1: ; preds = %30, %0
%2 = phi i64 [ 0, %0 ], [ %33, %30 ]
%3 = phi i64 [ 0, %0 ], [ %15, %30 ]
%4 = phi i8* [ null, %0 ], [ %16, %30 ]
%5 = icmp eq i64 %2, %3
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = icmp eq i64 %2, 0
%8 = shl i64 %2, 1
%9 = select i1 %7, i64 32, i64 %8
%10 = tail call i8* @realloc(i8* %4, i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @free(i8* %4)
br label %34
14: ; preds = %6, %1
%15 = phi i64 [ %3, %1 ], [ %9, %6 ]
%16 = phi i8* [ %4, %1 ], [ %10, %6 ]
%17 = load i32, i32* @stdin
%18 = tail call i32 @fgetc(i32 %17)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
%21 = icmp eq i32 %18, 10
%22 = or i1 %21, %20
br i1 %22, label %23, label %30
23: ; preds = %14
%24 = icmp eq i64 %2, 0
%25 = select i1 %20, i1 %24, i1 false
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 @free(i8* %16)
br label %34
28: ; preds = %23
%29 = getelementptr inbounds i8, i8* %16, i64 %2
store i8 0, i8* %29
br label %34
30: ; preds = %14
%31 = trunc i32 %18 to i8
%32 = getelementptr inbounds i8, i8* %16, i64 %2
store i8 %31, i8* %32
%33 = add i64 %2, 1
br label %1
34: ; preds = %28, %26, %12
%35 = phi i8* [ null, %12 ], [ %16, %28 ], [ null, %26 ]
ret i8* %35
}