#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) {
        if (oldval)
          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    11c7 <linenoiseNoTTY+0x97>
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    11c2 <linenoiseNoTTY+0x92>
cmpq   $0x0,-0x28(%rbp)
je     11b5 <linenoiseNoTTY+0x85>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1261 <linenoiseNoTTY+0x131>
jmp    11c7 <linenoiseNoTTY+0x97>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%eax
je     11f4 <linenoiseNoTTY+0xc4>
cmpl   $0xa,-0x2c(%rbp)
jne    1240 <linenoiseNoTTY+0x110>
mov    -0x2c(%rbp),%eax
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%eax
jne    1227 <linenoiseNoTTY+0xf7>
cmpq   $0x0,-0x18(%rbp)
jne    1227 <linenoiseNoTTY+0xf7>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1261 <linenoiseNoTTY+0x131>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1261 <linenoiseNoTTY+0x131>
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
je     1170 <linenoiseNoTTY+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%r14
jmp    1192 <linenoiseNoTTY+0x62>
cs nopw 0x0(%rax,%rax,1)
nop
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
je     11d0 <linenoiseNoTTY+0xa0>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    0x0(%rbp),%ecx
cmp    $0xa,%eax
je     11c2 <linenoiseNoTTY+0x92>
cmp    %ecx,%eax
je     11c2 <linenoiseNoTTY+0x92>
mov    %al,(%r14,%r12,1)
add    $0x1,%r12
add    $0x2,%r13
mov    %r14,%r15
cmp    %rbx,%r12
jne    1160 <linenoiseNoTTY+0x30>
jmp    1170 <linenoiseNoTTY+0x40>
cmp    %ecx,%eax
jne    11e2 <linenoiseNoTTY+0xb2>
test   %r12,%r12
jne    11e2 <linenoiseNoTTY+0xb2>
mov    %r14,%rdi
jmp    11d8 <linenoiseNoTTY+0xa8>
test   %r15,%r15
je     11dd <linenoiseNoTTY+0xad>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
jmp    11e7 <linenoiseNoTTY+0xb7>
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, %64
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %32
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 %31
24: ; preds = %15
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %27, %24
store i8* null, i8** %1
br label %65
31: ; preds = %15
br label %32
32: ; preds = %31, %7
%33 = load i32, i32* @stdin
%34 = call i32 @fgetc(i32 %33)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %41, label %38
38: ; preds = %32
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %56
41: ; preds = %38, %32
%42 = load i32, i32* %6
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i64, i64* %3
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i8*, i8** %2
%50 = call i32 @free(i8* %49)
store i8* null, i8** %1
br label %65
51: ; preds = %45, %41
%52 = load i8*, i8** %2
%53 = load i64, i64* %3
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %2
store i8* %55, i8** %1
br label %65
56: ; preds = %38
%57 = load i32, i32* %6
%58 = trunc i32 %57 to i8
%59 = load i8*, i8** %2
%60 = load i64, i64* %3
%61 = getelementptr inbounds i8, i8* %59, i64 %60
store i8 %58, i8* %61
%62 = load i64, i64* %3
%63 = add i64 %62, 1
store i64 %63, i64* %3
br label %64
64: ; preds = %56
br label %7
65: ; preds = %51, %48, %30
%66 = load i8*, i8** %1
ret i8* %66
}

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