#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 *);
int /*<<< orphan*/ isspace(char);
char *malloc(int);
char read_char(int /*<<< orphan*/ *, int);
char *realloc(char *, size_t);
int /*<<< orphan*/ stderr;
char *read_next(FILE *file) {
  char *string = malloc(sizeof(char) * 1);
  size_t i;
  char c = read_char(file, 1);
  string[0] = c;
  for (i = 1; !isspace(c = fgetc(file)); ++i) {
    if (c == EOF) {
      fprintf(stderr, "Unexpected EOF!\n");
      exit(1);
    }
    string = realloc(string, i + 1);
    string[i] = c;
    if (c == '"') {
      while ((c = fgetc(file)) != '"') {
        i++;
        string = realloc(string, i + 1);
        string[i] = c;
      }
      string = realloc(string, i + 1);
      string[i + 1] = '"';
    }
  }
  string[i] = '\0';
  return string;
}


x86 assembly (clang, -O0):
<read_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1080 <read_char@plt>
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movq   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d5 <read_next+0x65>
jmp    12c3 <read_next+0x153>
movsbl -0x19(%rbp),%eax
mov    0x2e08(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    120a <read_next+0x9a>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x19(%rbp),%eax
cmp    $0x22,%eax
jne    12ad <read_next+0x13d>
jmp    123f <read_next+0xcf>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x22,%eax
je     128b <read_next+0x11b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    123f <read_next+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x22,0x1(%rax,%rcx,1)
jmp    12b2 <read_next+0x142>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11ac <read_next+0x3c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_next>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x1,%esi
call   1080 <read_char@plt>
mov    %al,(%r15)
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1040 <isspace@plt>
mov    $0x1,%r12d
test   %eax,%eax
je     11ce <read_next+0x5e>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    0x2e0e(%rip),%r13
jmp    1211 <read_next+0xa1>
nopl   0x0(%rax)
mov    %r12,%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <realloc@plt>
mov    %rax,%r15
movb   $0x22,(%rax,%rbp,1)
mov    %rbp,%r12
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1040 <isspace@plt>
mov    %r12,%rbp
test   %eax,%eax
jne    11b7 <read_next+0x47>
cmp    0x0(%r13),%bl
je     126d <read_next+0xfd>
lea    0x1(%rbp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %bl,(%rax,%rbp,1)
cmp    $0x22,%bl
jne    11f8 <read_next+0x88>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0x22,%al
je     11e0 <read_next+0x70>
mov    %eax,%ebx
nop
lea    0x1(%r12),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %bl,(%rax,%r12,1)
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%r12
cmp    $0x22,%al
jne    1240 <read_next+0xd0>
jmp    11e3 <read_next+0x73>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EOF = global i8 0
@stderr = global i32 0
@.str = [17 x i8] c"Unexpected EOF!\0A\00"
define i8* @read_next(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8
store i32* %0, i32** %2
%6 = call i8* @malloc(i32 1)
store i8* %6, i8** %3
%7 = load i32*, i32** %2
%8 = call signext i8 @read_char(i32* %7, i32 1)
store i8 %8, i8* %5
%9 = load i8, i8* %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 %9, i8* %11
store i64 1, i64* %4
br label %12
12: ; preds = %67, %1
%13 = load i32*, i32** %2
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %5
%15 = call i32 @isspace(i8 signext %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %70
18: ; preds = %12
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %20, %22
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i8*, i8** %3
%30 = load i64, i64* %4
%31 = add i64 %30, 1
%32 = call i8* @realloc(i8* %29, i64 %31)
store i8* %32, i8** %3
%33 = load i8, i8* %5
%34 = load i8*, i8** %3
%35 = load i64, i64* %4
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 %33, i8* %36
%37 = load i8, i8* %5
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 34
br i1 %39, label %40, label %66
40: ; preds = %28
br label %41
41: ; preds = %46, %40
%42 = load i32*, i32** %2
%43 = call signext i8 @fgetc(i32* %42)
store i8 %43, i8* %5
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 34
br i1 %45, label %46, label %57
46: ; preds = %41
%47 = load i64, i64* %4
%48 = add i64 %47, 1
store i64 %48, i64* %4
%49 = load i8*, i8** %3
%50 = load i64, i64* %4
%51 = add i64 %50, 1
%52 = call i8* @realloc(i8* %49, i64 %51)
store i8* %52, i8** %3
%53 = load i8, i8* %5
%54 = load i8*, i8** %3
%55 = load i64, i64* %4
%56 = getelementptr inbounds i8, i8* %54, i64 %55
store i8 %53, i8* %56
br label %41
57: ; preds = %41
%58 = load i8*, i8** %3
%59 = load i64, i64* %4
%60 = add i64 %59, 1
%61 = call i8* @realloc(i8* %58, i64 %60)
store i8* %61, i8** %3
%62 = load i8*, i8** %3
%63 = load i64, i64* %4
%64 = add i64 %63, 1
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 34, i8* %65
br label %66
66: ; preds = %57, %28
br label %67
67: ; preds = %66
%68 = load i64, i64* %4
%69 = add i64 %68, 1
store i64 %69, i64* %4
br label %12
70: ; preds = %12
%71 = load i8*, i8** %3
%72 = load i64, i64* %4
%73 = getelementptr inbounds i8, i8* %71, i64 %72
store i8 0, i8* %73
%74 = load i8*, i8** %3
ret i8* %74
}

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