#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*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ isspace(char);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
char *realloc(char *, size_t);
int /*<<< orphan*/ stderr;
char *read_line(FILE *file) {
  char *string = malloc(1 * sizeof(char));
  memset(string, '\0', 1);
  size_t i;
  char c;
  while (isspace((c = fgetc(file)))) {
  };
  string[0] = c;
  for (i = 1; (c = fgetc(file)) != '\n'; ++i) {
    if (c == ';') {
      string[i - 1] = '\0';
      while (fgetc(file) != '\n') {
      };
      return string;
    }
    string = realloc(string, i + 1);
    string[i] = c;
    if (c == '"') {
      while ((c = fgetc(file)) != '"') {
        if (c == EOF) {
          fprintf(stderr, "Unexpected EOF while reading string: %s\n", string);
          exit(1);
        } else if (c == '\n') {
          fprintf(stderr, "Unterminated string: %s\n", string);
          exit(1);
        }
        i++;
        string = realloc(string, i + 1);
        string[i] = c;
      }
      string = realloc(string, ++i + 1);
      string[i] = '\0';
    }
  }
  string[i] = '\0';
  return string;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11bd <read_line+0x4d>
jmp    119a <read_line+0x2a>
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1358 <read_line+0x1e8>
movsbl -0x21(%rbp),%eax
cmp    $0x3b,%eax
jne    122a <read_line+0xba>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     121d <read_line+0xad>
jmp    1203 <read_line+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    136c <read_line+0x1fc>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x21(%rbp),%eax
cmp    $0x22,%eax
jne    1342 <read_line+0x1d2>
jmp    125f <read_line+0xef>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0x22,%eax
je     1319 <read_line+0x1a9>
movsbl -0x21(%rbp),%eax
mov    0x2d66(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12b0 <read_line+0x140>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd5f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    12e0 <read_line+0x170>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd58(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12e5 <read_line+0x175>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    125f <read_line+0xef>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
add    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1347 <read_line+0x1d7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ce <read_line+0x5e>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <memset@plt>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    11a0 <read_line+0x30>
mov    %bl,(%r15)
mov    $0x1,%r13d
jmp    11f0 <read_line+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rbp
add    $0x2,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <realloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax,%rbp,1)
add    $0x1,%rbp
mov    %rbp,%r13
mov    %r13,%r12
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%al
je     127b <read_line+0x10b>
mov    %eax,%ebx
cmp    $0x3b,%al
je     1282 <read_line+0x112>
lea    0x1(%r12),%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <realloc@plt>
mov    %rax,%r15
mov    %bl,(%rax,%r12,1)
cmp    $0x22,%bl
jne    11f0 <read_line+0x80>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0x22,%al
je     11d0 <read_line+0x60>
mov    %eax,%ebx
mov    0x2db2(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
cmp    (%r12),%bl
je     12ae <read_line+0x13e>
cmp    $0xa,%bl
je     12c0 <read_line+0x150>
lea    0x1(%r13),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1080 <realloc@plt>
mov    %rax,%r15
mov    %bl,(%rax,%r13,1)
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%r13
cmp    $0x22,%al
jne    1240 <read_line+0xd0>
lea    -0x1(%rbp),%r12
jmp    11d3 <read_line+0x63>
movb   $0x0,(%r15,%r12,1)
jmp    129c <read_line+0x12c>
movb   $0x0,-0x1(%r12,%r15,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%al
jne    1290 <read_line+0x120>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
jmp    12d0 <read_line+0x160>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EOF = global i8 0
@stderr = global i32 0
@.str = [41 x i8] c"Unexpected EOF while reading string: %s\0A\00"
@.str.1 = [25 x i8] c"Unterminated string: %s\0A\00"
define i8* @read_line(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8
store i32* %0, i32** %3
%7 = call i8* @malloc(i32 1)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 1)
br label %10
10: ; preds = %15, %1
%11 = load i32*, i32** %3
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %6
%13 = call i64 @isspace(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
br label %10
16: ; preds = %10
%17 = load i8, i8* %6
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 %17, i8* %19
store i64 1, i64* %5
br label %20
20: ; preds = %102, %16
%21 = load i32*, i32** %3
%22 = call signext i8 @fgetc(i32* %21)
store i8 %22, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %105
25: ; preds = %20
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 59
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load i64, i64* %5
%32 = sub i64 %31, 1
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %39, %29
%35 = load i32*, i32** %3
%36 = call signext i8 @fgetc(i32* %35)
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 10
br i1 %38, label %39, label %40
39: ; preds = %34
br label %34
40: ; preds = %34
%41 = load i8*, i8** %4
store i8* %41, i8** %2
br label %110
42: ; preds = %25
%43 = load i8*, i8** %4
%44 = load i64, i64* %5
%45 = add i64 %44, 1
%46 = call i8* @realloc(i8* %43, i64 %45)
store i8* %46, i8** %4
%47 = load i8, i8* %6
%48 = load i8*, i8** %4
%49 = load i64, i64* %5
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8 %47, i8* %50
%51 = load i8, i8* %6
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 34
br i1 %53, label %54, label %101
54: ; preds = %42
br label %55
55: ; preds = %81, %54
%56 = load i32*, i32** %3
%57 = call signext i8 @fgetc(i32* %56)
store i8 %57, i8* %6
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 34
br i1 %59, label %60, label %92
60: ; preds = %55
%61 = load i8, i8* %6
%62 = sext i8 %61 to i32
%63 = load i8, i8* @EOF
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %62, %64
br i1 %65, label %66, label %71
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %4
%69 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %68)
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %60
%72 = load i8, i8* %6
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 10
br i1 %74, label %75, label %80
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %4
%78 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %71
br label %81
81: ; preds = %80
%82 = load i64, i64* %5
%83 = add i64 %82, 1
store i64 %83, i64* %5
%84 = load i8*, i8** %4
%85 = load i64, i64* %5
%86 = add i64 %85, 1
%87 = call i8* @realloc(i8* %84, i64 %86)
store i8* %87, i8** %4
%88 = load i8, i8* %6
%89 = load i8*, i8** %4
%90 = load i64, i64* %5
%91 = getelementptr inbounds i8, i8* %89, i64 %90
store i8 %88, i8* %91
br label %55
92: ; preds = %55
%93 = load i8*, i8** %4
%94 = load i64, i64* %5
%95 = add i64 %94, 1
store i64 %95, i64* %5
%96 = add i64 %95, 1
%97 = call i8* @realloc(i8* %93, i64 %96)
store i8* %97, i8** %4
%98 = load i8*, i8** %4
%99 = load i64, i64* %5
%100 = getelementptr inbounds i8, i8* %98, i64 %99
store i8 0, i8* %100
br label %101
101: ; preds = %92, %42
br label %102
102: ; preds = %101
%103 = load i64, i64* %5
%104 = add i64 %103, 1
store i64 %104, i64* %5
br label %20
105: ; preds = %20
%106 = load i8*, i8** %4
%107 = load i64, i64* %5
%108 = getelementptr inbounds i8, i8* %106, i64 %107
store i8 0, i8* %108
%109 = load i8*, i8** %4
store i8* %109, i8** %2
br label %110
110: ; preds = %105, %40
%111 = load i8*, i8** %2
ret i8* %111
}

LLVM IR (-O2):
@EOF = global i8 0
@stderr = global i32 0
@.str = [41 x i8] c"Unexpected EOF while reading string: %s\0A\00"
@.str.1 = [25 x i8] c"Unterminated string: %s\0A\00"
define i8* @read_line(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%3 = tail call i32 @memset(i8* %2, i8 signext 0, i32 1)
br label %4
4: ; preds = %4, %1
%5 = tail call signext i8 @fgetc(i32* %0)
%6 = tail call i64 @isspace(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
store i8 %5, i8* %2
br label %9
9: ; preds = %24, %8
%10 = phi i8* [ %2, %8 ], [ %25, %24 ]
%11 = phi i64 [ 1, %8 ], [ %26, %24 ]
%12 = tail call signext i8 @fgetc(i32* %0)
switch i8 %12, label %19 [
i8 10, label %63
i8 59, label %13
]
13: ; preds = %9
%14 = add i64 %11, -1
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %16, %13
%17 = tail call signext i8 @fgetc(i32* %0)
%18 = icmp eq i8 %17, 10
br i1 %18, label %65, label %16
19: ; preds = %9
%20 = add i64 %11, 1
%21 = tail call i8* @realloc(i8* %10, i64 %20)
%22 = getelementptr inbounds i8, i8* %21, i64 %11
store i8 %12, i8* %22
%23 = icmp eq i8 %12, 34
br i1 %23, label %27, label %24
24: ; preds = %19, %55
%25 = phi i8* [ %21, %19 ], [ %60, %55 ]
%26 = phi i64 [ %20, %19 ], [ %62, %55 ]
br label %9
27: ; preds = %19
%28 = tail call signext i8 @fgetc(i32* %0)
%29 = icmp eq i8 %28, 34
br i1 %29, label %55, label %30
30: ; preds = %27, %46
%31 = phi i8 [ %51, %46 ], [ %28, %27 ]
%32 = phi i64 [ %47, %46 ], [ %11, %27 ]
%33 = phi i8* [ %49, %46 ], [ %21, %27 ]
%34 = load i8, i8* @EOF
%35 = icmp eq i8 %31, %34
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %33)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = icmp eq i8 %31, 10
br i1 %41, label %42, label %46
42: ; preds = %40
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = add i64 %32, 1
%48 = add i64 %32, 2
%49 = tail call i8* @realloc(i8* %33, i64 %48)
%50 = getelementptr inbounds i8, i8* %49, i64 %47
store i8 %31, i8* %50
%51 = tail call signext i8 @fgetc(i32* %0)
%52 = icmp eq i8 %51, 34
br i1 %52, label %53, label %30
53: ; preds = %46
%54 = add i64 %32, 2
br label %55
55: ; preds = %53, %27
%56 = phi i64 [ %54, %53 ], [ %20, %27 ]
%57 = phi i8* [ %49, %53 ], [ %21, %27 ]
%58 = phi i64 [ %47, %53 ], [ %11, %27 ]
%59 = add i64 %58, 2
%60 = tail call i8* @realloc(i8* %57, i64 %59)
%61 = getelementptr inbounds i8, i8* %60, i64 %56
store i8 0, i8* %61
%62 = add i64 %56, 1
br label %24
63: ; preds = %9
%64 = getelementptr inbounds i8, i8* %10, i64 %11
store i8 0, i8* %64
br label %65
65: ; preds = %16, %63
ret i8* %10
}