#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 */
int EOF;
char *allocateMsg(int, char *);
char convertEscapedChar(int);
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *reallocateMsg(char *, int, char *);
int /*<<< orphan*/ skipWhiteSpace(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *readString(FILE *fp) {
  int ch, index;
  char *buffer;
  int size = 512;
  skipWhiteSpace(fp);
  ch = fgetc(fp);
  if (ch == EOF)
    return 0;
  buffer = allocateMsg(size, "readString");
  if (ch != '\"') {
    fprintf(stderr, "SCAN ERROR: attempt to read a string failed\n");
    fprintf(stderr, "first character was <%c>\n", ch);
    exit(4);
  }
  ch = fgetc(fp);
  index = 0;
  while (ch != '\"') {
    if (ch == EOF) {
      fprintf(stderr, "SCAN ERROR: attempt to read a string failed\n");
      fprintf(stderr, "no closing double quote\n");
      exit(6);
    }
    if (index > size - 2) {
      ++size;
      buffer = reallocateMsg(buffer, size, "readString");
    }
    if (ch == '\\') {
      ch = fgetc(fp);
      if (ch == EOF) {
        fprintf(stderr, "SCAN ERROR: attempt to read a string failed\n");
        fprintf(stderr, "escaped character missing\n");
        exit(6);
      }
      buffer[index] = convertEscapedChar(ch);
    } else
      buffer[index] = ch;
    ++index;
    ch = fgetc(fp);
  }
  buffer[index] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<readString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x200,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <skipWhiteSpace@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%eax
jne    11b7 <readString+0x47>
movq   $0x0,-0x8(%rbp)
jmp    135f <readString+0x1ef>
mov    -0x24(%rbp),%edi
lea    0xe3f(%rip),%rsi
call   1030 <allocateMsg@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x22,-0x14(%rbp)
je     120f <readString+0x9f>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x22,-0x14(%rbp)
je     134b <readString+0x1db>
mov    -0x14(%rbp),%eax
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%eax
jne    1276 <readString+0x106>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jle    12a7 <readString+0x137>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    0xd62(%rip),%rdx
call   1080 <reallocateMsg@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x5c,-0x14(%rbp)
jne    1321 <readString+0x1b1>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2d21(%rip),%rcx
cmp    (%rcx),%eax
jne    1307 <readString+0x197>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <convertEscapedChar@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1331 <readString+0x1c1>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
jmp    1222 <readString+0xb2>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <skipWhiteSpace@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2e56(%rip),%r13
cmp    0x0(%r13),%eax
jne    11a0 <readString+0x30>
xor    %r15d,%r15d
jmp    1244 <readString+0xd4>
mov    %eax,%ebx
lea    0xe57(%rip),%rsi
mov    $0x200,%edi
call   1030 <allocateMsg@plt>
cmp    $0x22,%ebx
jne    12a9 <readString+0x139>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    $0x22,%eax
jne    11d0 <readString+0x60>
xor    %eax,%eax
jmp    123f <readString+0xcf>
mov    %eax,%ebp
mov    $0x200,%ebx
xor    %r12d,%r12d
jmp    11f7 <readString+0x87>
nopl   0x0(%rax)
mov    %bpl,(%r15,%r12,1)
add    $0x1,%r12
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
cmp    $0x22,%eax
je     123c <readString+0xcc>
cmp    0x0(%r13),%ebp
je     1256 <readString+0xe6>
lea    -0x2(%rbx),%eax
cltq
cmp    %rax,%r12
jle    121e <readString+0xae>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
lea    0xdea(%rip),%rdx
call   1080 <reallocateMsg@plt>
mov    %rax,%r15
cmp    $0x5c,%ebp
jne    11e0 <readString+0x70>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%eax
je     1278 <readString+0x108>
mov    %eax,%edi
call   1040 <convertEscapedChar@plt>
mov    %eax,%ebp
jmp    11e0 <readString+0x70>
mov    %r12d,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7b(%rip),%rbx
mov    (%rbx),%edi
lea    0xda5(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xddc(%rip),%rsi
jmp    1298 <readString+0x128>
mov    0x2d59(%rip),%rbx
mov    (%rbx),%edi
lea    0xd83(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd3(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
mov    0x2d28(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd51(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd6d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [11 x i8] c"readString\00"
@stderr = global i32 0
@.str.1 = [45 x i8] c"SCAN ERROR: attempt to read a string failed\0A\00"
@.str.2 = [26 x i8] c"first character was <%c>\0A\00"
@.str.3 = [25 x i8] c"no closing double quote\0A\00"
@.str.4 = [27 x i8] c"escaped character missing\0A\00"
define i8* @readString(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %3
store i32 512, i32* %7
%8 = load i32*, i32** %3
%9 = call i32 @skipWhiteSpace(i32* %8)
%10 = load i32*, i32** %3
%11 = call i32 @fgetc(i32* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %1
store i8* null, i8** %2
br label %95
16: ; preds = %1
%17 = load i32, i32* %7
%18 = call i8* @allocateMsg(i32 %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %6
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 34
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i32, i32* %4
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = call i32 @exit(i32 4)
unreachable
28: ; preds = %16
%29 = load i32*, i32** %3
%30 = call i32 @fgetc(i32* %29)
store i32 %30, i32* %4
store i32 0, i32* %5
br label %31
31: ; preds = %84, %28
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 34
br i1 %33, label %34, label %89
34: ; preds = %31
%35 = load i32, i32* %4
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 6)
unreachable
44: ; preds = %34
%45 = load i32, i32* %5
%46 = load i32, i32* %7
%47 = sub nsw i32 %46, 2
%48 = icmp sgt i32 %45, %47
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
%52 = load i8*, i8** %6
%53 = load i32, i32* %7
%54 = call i8* @reallocateMsg(i8* %52, i32 %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %54, i8** %6
br label %55
55: ; preds = %49, %44
%56 = load i32, i32* %4
%57 = icmp eq i32 %56, 92
br i1 %57, label %58, label %77
58: ; preds = %55
%59 = load i32*, i32** %3
%60 = call i32 @fgetc(i32* %59)
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = load i32, i32* @EOF
%63 = icmp eq i32 %61, %62
br i1 %63, label %64, label %70
64: ; preds = %58
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%69 = call i32 @exit(i32 6)
unreachable
70: ; preds = %58
%71 = load i32, i32* %4
%72 = call signext i8 @convertEscapedChar(i32 %71)
%73 = load i8*, i8** %6
%74 = load i32, i32* %5
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 %72, i8* %76
br label %84
77: ; preds = %55
%78 = load i32, i32* %4
%79 = trunc i32 %78 to i8
%80 = load i8*, i8** %6
%81 = load i32, i32* %5
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 %79, i8* %83
br label %84
84: ; preds = %77, %70
%85 = load i32, i32* %5
%86 = add nsw i32 %85, 1
store i32 %86, i32* %5
%87 = load i32*, i32** %3
%88 = call i32 @fgetc(i32* %87)
store i32 %88, i32* %4
br label %31
89: ; preds = %31
%90 = load i8*, i8** %6
%91 = load i32, i32* %5
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 0, i8* %93
%94 = load i8*, i8** %6
store i8* %94, i8** %2
br label %95
95: ; preds = %89, %15
%96 = load i8*, i8** %2
ret i8* %96
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [11 x i8] c"readString\00"
@stderr = global i32 0
@.str.1 = [45 x i8] c"SCAN ERROR: attempt to read a string failed\0A\00"
@.str.2 = [26 x i8] c"first character was <%c>\0A\00"
@.str.3 = [25 x i8] c"no closing double quote\0A\00"
@.str.4 = [27 x i8] c"escaped character missing\0A\00"
define i8* @readString(i32* %0) {
%2 = tail call i32 @skipWhiteSpace(i32* %0)
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %68, label %6
6: ; preds = %1
%7 = tail call i8* @allocateMsg(i32 512, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %3, 34
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%14 = tail call i32 @exit(i32 4)
unreachable
15: ; preds = %6
%16 = tail call i32 @fgetc(i32* %0)
%17 = icmp eq i32 %16, 34
br i1 %17, label %64, label %18
18: ; preds = %15, %56
%19 = phi i64 [ %59, %56 ], [ 0, %15 ]
%20 = phi i32 [ %40, %56 ], [ 512, %15 ]
%21 = phi i8* [ %39, %56 ], [ %7, %15 ]
%22 = phi i32 [ %60, %56 ], [ %16, %15 ]
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%30 = tail call i32 @exit(i32 6)
unreachable
31: ; preds = %18
%32 = add nsw i32 %20, -2
%33 = sext i32 %32 to i64
%34 = icmp sgt i64 %19, %33
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = add nsw i32 %20, 1
%37 = tail call i8* @reallocateMsg(i8* %21, i32 %36, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %35, %31
%39 = phi i8* [ %37, %35 ], [ %21, %31 ]
%40 = phi i32 [ %36, %35 ], [ %20, %31 ]
%41 = icmp eq i32 %22, 92
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = tail call i32 @fgetc(i32* %0)
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%51 = tail call i32 @exit(i32 6)
unreachable
52: ; preds = %42
%53 = tail call signext i8 @convertEscapedChar(i32 %43)
br label %56
54: ; preds = %38
%55 = trunc i32 %22 to i8
br label %56
56: ; preds = %54, %52
%57 = phi i8 [ %55, %54 ], [ %53, %52 ]
%58 = getelementptr inbounds i8, i8* %39, i64 %19
store i8 %57, i8* %58
%59 = add nuw i64 %19, 1
%60 = tail call i32 @fgetc(i32* %0)
%61 = icmp eq i32 %60, 34
br i1 %61, label %62, label %18
62: ; preds = %56
%63 = and i64 %59, 4294967295
br label %64
64: ; preds = %62, %15
%65 = phi i64 [ 0, %15 ], [ %63, %62 ]
%66 = phi i8* [ %7, %15 ], [ %39, %62 ]
%67 = getelementptr inbounds i8, i8* %66, i64 %65
store i8 0, i8* %67
br label %68
68: ; preds = %1, %64
%69 = phi i8* [ %66, %64 ], [ null, %1 ]
ret i8* %69
}