#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 *malloc(int);
char *realloc(char *, size_t);
int /*<<< orphan*/ stdin;
char *read_single_line(void) {
  char *line = malloc(100), *linep = line;
  size_t lenmax = 100, len = lenmax;
  int c;
  if (line == NULL)
    return NULL;
  for (;;) {
    c = fgetc(stdin);
    if (c == EOF)
      break;
    if (--len == 0) {
      len = lenmax;
      char *linen = realloc(linep, lenmax *= 2);
      if (linen == NULL) {
        free(linep);
        return NULL;
      }
      line = linen + (line - linep);
      linep = linen;
    }
    if ((*line++ = c) == '\n')
      break;
  }
  *line = '\0';
  return linep;
}


x86 assembly (clang, -O0):
<read_single_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x64,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <read_single_line+0x46>
movq   $0x0,-0x8(%rbp)
jmp    1262 <read_single_line+0x122>
jmp    118b <read_single_line+0x4b>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
jne    11b3 <read_single_line+0x73>
jmp    1253 <read_single_line+0x113>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1229 <read_single_line+0xe9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
shl    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
call   1060 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    120b <read_single_line+0xcb>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1262 <read_single_line+0x122>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0xa,%eax
jne    124e <read_single_line+0x10e>
jmp    1253 <read_single_line+0x113>
jmp    118b <read_single_line+0x4b>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_single_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x64,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11f7 <read_single_line+0xb7>
mov    %rax,%rcx
mov    $0x64,%eax
mov    %rax,(%rsp)
mov    0x2e77(%rip),%r15
mov    0x2e68(%rip),%r13
mov    $0x64,%r12d
mov    %rcx,%r14
mov    %rcx,%rbx
jmp    119d <read_single_line+0x5d>
cs nopw 0x0(%rax,%rax,1)
mov    %bpl,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%bpl
je     11e7 <read_single_line+0xa7>
mov    (%r15),%edi
call   1040 <fgetc@plt>
cmp    0x0(%r13),%eax
je     11e7 <read_single_line+0xa7>
mov    %eax,%ebp
add    $0xffffffffffffffff,%r12
jne    1190 <read_single_line+0x50>
mov    %r15,%r13
mov    (%rsp),%r12
lea    (%r12,%r12,1),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <realloc@plt>
test   %rax,%rax
je     11ef <read_single_line+0xaf>
sub    %r14,%rbx
add    %rax,%rbx
mov    %rax,%r14
mov    %r15,(%rsp)
mov    %r13,%r15
mov    0x2dfb(%rip),%r13
jmp    1190 <read_single_line+0x50>
movb   $0x0,(%rbx)
mov    %r14,%rax
jmp    11f9 <read_single_line+0xb9>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
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* @read_single_line() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = call i8* @malloc(i32 100)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
store i8* %9, i8** %3
store i64 100, i64* %4
%10 = load i64, i64* %4
store i64 %10, i64* %5
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %0
store i8* null, i8** %1
br label %58
14: ; preds = %0
br label %15
15: ; preds = %54, %14
%16 = load i32, i32* @stdin
%17 = call i32 @fgetc(i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
br label %55
22: ; preds = %15
%23 = load i64, i64* %5
%24 = add i64 %23, -1
store i64 %24, i64* %5
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = load i64, i64* %4
store i64 %27, i64* %5
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = mul i64 %29, 2
store i64 %30, i64* %4
%31 = call i8* @realloc(i8* %28, i64 %30)
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = call i32 @free(i8* %35)
store i8* null, i8** %1
br label %58
37: ; preds = %26
%38 = load i8*, i8** %7
%39 = load i8*, i8** %2
%40 = load i8*, i8** %3
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = getelementptr inbounds i8, i8* %38, i64 %43
store i8* %44, i8** %2
%45 = load i8*, i8** %7
store i8* %45, i8** %3
br label %46
46: ; preds = %37, %22
%47 = load i32, i32* %6
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %2
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %2
store i8 %48, i8* %49
%51 = sext i8 %48 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %54
53: ; preds = %46
br label %55
54: ; preds = %46
br label %15
55: ; preds = %53, %21
%56 = load i8*, i8** %2
store i8 0, i8* %56
%57 = load i8*, i8** %3
store i8* %57, i8** %1
br label %58
58: ; preds = %55, %34, %13
%59 = load i8*, i8** %1
ret i8* %59
}

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