#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 */
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
char *allocate(char *, size_t);
int /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *read1line(FILE *fp) {
  static char *line;
  static size_t len;
  size_t idx;
  int c;
  if (len == 0)
    line = allocate(0, (len = 16) * sizeof(line[0]));
  idx = 0;
  while ((c = getc(fp)) != EOF && c != '\n') {
    if (c < '\t') {
      fprintf(stderr, "remsync: control character in data file!\n");
      exit(1);
    }
    line[idx++] = c;
    if (idx == len) {
      line = allocate(line, (len *= 2) * sizeof(line[0]));
    }
  }
  if (c == EOF) {
    if (ferror(fp))
      return 0;
    if (idx == 0)
      return 0;
  }
  line[idx] = 0;
  return line;
}


x86 assembly (clang, -O0):
<read1line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2ef4(%rip)
jne    118a <read1line+0x3a>
movq   $0x10,0x2ee3(%rip)
xor    %eax,%eax
mov    %eax,%edi
mov    $0x10,%esi
call   1050 <allocate@plt>
mov    %rax,0x2ec6(%rip)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    0x2e3f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     11be <read1line+0x6e>
cmpl   $0xa,-0x1c(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11ce <read1line+0x7e>
jmp    1254 <read1line+0x104>
cmpl   $0x9,-0x1c(%rbp)
jge    11f7 <read1line+0xa7>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    0x2e4d(%rip),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
cmp    0x2e38(%rip),%rax
jne    124f <read1line+0xff>
mov    0x2e23(%rip),%rdi
mov    0x2e24(%rip),%rsi
shl    $0x1,%rsi
mov    %rsi,0x2e19(%rip)
shl    $0x0,%rsi
call   1050 <allocate@plt>
mov    %rax,0x2e01(%rip)
jmp    1192 <read1line+0x42>
mov    -0x1c(%rbp),%eax
mov    0x2d8a(%rip),%rcx
cmp    (%rcx),%eax
jne    12a3 <read1line+0x153>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1286 <read1line+0x136>
movq   $0x0,-0x8(%rbp)
jmp    12bd <read1line+0x16d>
cmpq   $0x0,-0x18(%rbp)
jne    129e <read1line+0x14e>
movq   $0x0,-0x8(%rbp)
jmp    12bd <read1line+0x16d>
jmp    12a3 <read1line+0x153>
mov    0x2da6(%rip),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2d97(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read1line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpq   $0x0,0x2ef5(%rip)
jne    1183 <read1line+0x33>
movq   $0x10,0x2ee8(%rip)
mov    $0x10,%esi
xor    %edi,%edi
call   1050 <allocate@plt>
mov    %rax,0x2ecd(%rip)
mov    %r14,%rdi
call   1070 <getc@plt>
mov    0x2e56(%rip),%r12
mov    (%r12),%ecx
xor    %r15d,%r15d
cmp    $0xa,%eax
je     11fc <read1line+0xac>
cmp    %ecx,%eax
je     11fc <read1line+0xac>
mov    $0x2,%ebx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
cmp    $0x8,%eax
jle    122f <read1line+0xdf>
mov    0x2e94(%rip),%rdi
mov    %al,(%rdi,%r15,1)
add    $0x1,%r15
cmp    0x2e8d(%rip),%r15
jne    11e3 <read1line+0x93>
mov    %rbx,0x2e84(%rip)
mov    %rbx,%rsi
call   1050 <allocate@plt>
mov    %rax,0x2e6d(%rip)
mov    %r14,%rdi
call   1070 <getc@plt>
mov    (%r12),%ecx
cmp    $0xa,%eax
je     11fc <read1line+0xac>
add    $0x2,%rbx
cmp    %ecx,%eax
jne    11b0 <read1line+0x60>
cmp    %ecx,%eax
jne    1217 <read1line+0xc7>
mov    %r14,%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1223 <read1line+0xd3>
test   %r15,%r15
je     1223 <read1line+0xd3>
mov    0x2e32(%rip),%rax
movb   $0x0,(%rax,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@read1line.line = internal global i8* null
@read1line.len = internal global i64 0
@EOF = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"remsync: control character in data file!\0A\00"
define i8* @read1line(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i64, i64* @read1line.len
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
store i64 16, i64* @read1line.len
%9 = call i8* @allocate(i8* null, i64 16)
store i8* %9, i8** @read1line.line
br label %10
10: ; preds = %8, %1
store i64 0, i64* %4
br label %11
11: ; preds = %44, %10
%12 = load i32*, i32** %3
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %5
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 10
br label %19
19: ; preds = %16, %11
%20 = phi i1 [ false, %11 ], [ %18, %16 ]
br i1 %20, label %21, label %45
21: ; preds = %19
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 9
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = load i32, i32* %5
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** @read1line.line
%32 = load i64, i64* %4
%33 = add i64 %32, 1
store i64 %33, i64* %4
%34 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 %30, i8* %34
%35 = load i64, i64* %4
%36 = load i64, i64* @read1line.len
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %28
%39 = load i8*, i8** @read1line.line
%40 = load i64, i64* @read1line.len
%41 = mul i64 %40, 2
store i64 %41, i64* @read1line.len
%42 = mul i64 %41, 1
%43 = call i8* @allocate(i8* %39, i64 %42)
store i8* %43, i8** @read1line.line
br label %44
44: ; preds = %38, %28
br label %11
45: ; preds = %19
%46 = load i32, i32* %5
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %59
49: ; preds = %45
%50 = load i32*, i32** %3
%51 = call i64 @ferror(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
store i8* null, i8** %2
br label %64
54: ; preds = %49
%55 = load i64, i64* %4
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
store i8* null, i8** %2
br label %64
58: ; preds = %54
br label %59
59: ; preds = %58, %45
%60 = load i8*, i8** @read1line.line
%61 = load i64, i64* %4
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** @read1line.line
store i8* %63, i8** %2
br label %64
64: ; preds = %59, %57, %53
%65 = load i8*, i8** %2
ret i8* %65
}

LLVM IR (-O2):
@read1line.line = internal unnamed_addr global i8* null
@read1line.len = internal unnamed_addr global i64 0
@EOF = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"remsync: control character in data file!\0A\00"
define i8* @read1line(i32* nocapture %0) {
%2 = load i64, i64* @read1line.len
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
store i64 16, i64* @read1line.len
%5 = tail call i8* @allocate(i8* null, i64 16)
store i8* %5, i8** @read1line.line
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @getc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
%10 = icmp ne i32 %7, 10
%11 = and i1 %10, %9
br i1 %11, label %12, label %36
12: ; preds = %6, %30
%13 = phi i32 [ %31, %30 ], [ %7, %6 ]
%14 = phi i64 [ %23, %30 ], [ 0, %6 ]
%15 = icmp slt i32 %13, 9
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = trunc i32 %13 to i8
%22 = load i8*, i8** @read1line.line
%23 = add i64 %14, 1
%24 = getelementptr inbounds i8, i8* %22, i64 %14
store i8 %21, i8* %24
%25 = load i64, i64* @read1line.len
%26 = icmp eq i64 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = shl i64 %23, 1
store i64 %28, i64* @read1line.len
%29 = tail call i8* @allocate(i8* %22, i64 %28)
store i8* %29, i8** @read1line.line
br label %30
30: ; preds = %27, %20
%31 = tail call i32 @getc(i32* %0)
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
%34 = icmp ne i32 %31, 10
%35 = and i1 %34, %33
br i1 %35, label %12, label %36
36: ; preds = %30, %6
%37 = phi i64 [ 0, %6 ], [ %23, %30 ]
%38 = phi i32 [ %7, %6 ], [ %31, %30 ]
%39 = phi i32 [ %8, %6 ], [ %32, %30 ]
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = tail call i64 @ferror(i32* %0)
%43 = icmp ne i64 %42, 0
%44 = icmp eq i64 %37, 0
%45 = select i1 %43, i1 true, i1 %44
br i1 %45, label %49, label %46
46: ; preds = %41, %36
%47 = load i8*, i8** @read1line.line
%48 = getelementptr inbounds i8, i8* %47, i64 %37
store i8 0, i8* %48
br label %49
49: ; preds = %41, %46
%50 = phi i8* [ %47, %46 ], [ null, %41 ]
ret i8* %50
}