#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;
int /*<<< orphan*/ error(char *, size_t);
int getc(int /*<<< orphan*/ *);
int read_name(int c, char *buf, size_t bufsize, FILE *fin, size_t lineno) {
  unsigned i = 0;
  if (c != '"')
    error("Name doesn't start with \" at line %lu\n", lineno);
  while ((c = getc(fin)) != EOF)
    switch (c) {
    case '"':
      if (i < bufsize)
        buf[i] = '\0';
      else {
        error("Buffer overflow when reading name at line %lu\n", lineno);
        return EOF;
      }
      return getc(fin);
    case '\\':
      c = getc(fin);
      if (c == EOF) {
        error("Unexpected end-of-file at line %lu when reading name\n", lineno);
        return EOF;
      }
    default:
      if (i < bufsize - 1)
        buf[i++] = c;
      else {
        error("Buffer overflow when reading name at line %lu\n", lineno);
        return EOF;
      }
    }
  error("Unexpected end-of-file at line %lu when reading name\n", lineno);
  return EOF;
}


x86 assembly (clang, -O0):
<read_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x22,-0x8(%rbp)
je     115c <read_name+0x3c>
mov    -0x28(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <error@plt>
jmp    1161 <read_name+0x41>
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%eax
je     1291 <read_name+0x171>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x22,%eax
je     11a1 <read_name+0x81>
jmp    1190 <read_name+0x70>
mov    -0x30(%rbp),%eax
sub    $0x5c,%eax
je     11f0 <read_name+0xd0>
jmp    1234 <read_name+0x114>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    11be <read_name+0x9e>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11df <read_name+0xbf>
mov    -0x28(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1030 <error@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ad <read_name+0x18d>
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x4(%rbp)
jmp    12ad <read_name+0x18d>
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%eax
jne    122f <read_name+0x10f>
mov    -0x28(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1030 <error@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ad <read_name+0x18d>
jmp    1234 <read_name+0x114>
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1266 <read_name+0x146>
mov    -0x8(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1287 <read_name+0x167>
mov    -0x28(%rbp),%rsi
lea    0xdb6(%rip),%rdi
call   1030 <error@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ad <read_name+0x18d>
jmp    128c <read_name+0x16c>
jmp    1161 <read_name+0x41>
mov    -0x28(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1030 <error@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,(%rsp)
mov    %rsi,%r15
cmp    $0x22,%edi
je     114c <read_name+0x2c>
lea    0xebc(%rip),%rdi
mov    %r14,%rsi
call   1030 <error@plt>
mov    %rbx,%rdi
call   1040 <getc@plt>
mov    0x2e8d(%rip),%r13
cmp    0x0(%r13),%eax
je     11aa <read_name+0x8a>
mov    (%rsp),%rcx
lea    -0x1(%rcx),%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
cmp    $0x5c,%eax
je     1180 <read_name+0x60>
cmp    $0x22,%eax
jne    118e <read_name+0x6e>
jmp    11b3 <read_name+0x93>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
je     11aa <read_name+0x8a>
mov    %ebp,%ecx
cmp    %rcx,%r12
jbe    11d6 <read_name+0xb6>
add    $0x1,%ebp
mov    %al,(%r15,%rcx,1)
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
jne    1170 <read_name+0x50>
lea    0xea5(%rip),%rdi
jmp    11dd <read_name+0xbd>
mov    %ebp,%eax
cmp    (%rsp),%rax
jae    11d6 <read_name+0xb6>
movb   $0x0,(%r15,%rax,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <getc@plt>
lea    0xe4a(%rip),%rdi
mov    %r14,%rsi
call   1030 <error@plt>
mov    0x0(%r13),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Name doesn't start with \22 at line %lu\0A\00"
@EOF = global i32 0
@.str.1 = [47 x i8] c"Buffer overflow when reading name at line %lu\0A\00"
@.str.2 = [54 x i8] c"Unexpected end-of-file at line %lu when reading name\0A\00"
define i32 @read_name(i32 %0, i8* %1, i64 %2, i32* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32* %3, i32** %10
store i64 %4, i64* %11
store i32 0, i32* %12
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 34
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i64, i64* %11
%17 = call i32 @error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %16)
br label %18
18: ; preds = %15, %5
br label %19
19: ; preds = %73, %18
%20 = load i32*, i32** %10
%21 = call i32 @getc(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %74
24: ; preds = %19
%25 = load i32, i32* %7
switch i32 %25, label %54 [
i32 34, label %26
i32 92, label %43
]
26: ; preds = %24
%27 = load i32, i32* %12
%28 = zext i32 %27 to i64
%29 = load i64, i64* %9
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i8*, i8** %8
%33 = load i32, i32* %12
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
br label %40
36: ; preds = %26
%37 = load i64, i64* %11
%38 = call i32 @error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %37)
%39 = load i32, i32* @EOF
store i32 %39, i32* %6
br label %78
40: ; preds = %31
%41 = load i32*, i32** %10
%42 = call i32 @getc(i32* %41)
store i32 %42, i32* %6
br label %78
43: ; preds = %24
%44 = load i32*, i32** %10
%45 = call i32 @getc(i32* %44)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = load i64, i64* %11
%51 = call i32 @error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64 %50)
%52 = load i32, i32* @EOF
store i32 %52, i32* %6
br label %78
53: ; preds = %43
br label %54
54: ; preds = %24, %53
%55 = load i32, i32* %12
%56 = zext i32 %55 to i64
%57 = load i64, i64* %9
%58 = sub i64 %57, 1
%59 = icmp ult i64 %56, %58
br i1 %59, label %60, label %68
60: ; preds = %54
%61 = load i32, i32* %7
%62 = trunc i32 %61 to i8
%63 = load i8*, i8** %8
%64 = load i32, i32* %12
%65 = add i32 %64, 1
store i32 %65, i32* %12
%66 = zext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 %62, i8* %67
br label %72
68: ; preds = %54
%69 = load i64, i64* %11
%70 = call i32 @error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %69)
%71 = load i32, i32* @EOF
store i32 %71, i32* %6
br label %78
72: ; preds = %60
br label %73
73: ; preds = %72
br label %19
74: ; preds = %19
%75 = load i64, i64* %11
%76 = call i32 @error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64 %75)
%77 = load i32, i32* @EOF
store i32 %77, i32* %6
br label %78
78: ; preds = %74, %68, %49, %40, %36
%79 = load i32, i32* %6
ret i32 %79
}

LLVM IR (-O2):
@.str = [39 x i8] c"Name doesn't start with \22 at line %lu\0A\00"
@EOF = global i32 0
@.str.1 = [47 x i8] c"Buffer overflow when reading name at line %lu\0A\00"
@.str.2 = [54 x i8] c"Unexpected end-of-file at line %lu when reading name\0A\00"
define i32 @read_name(i32 %0, i8* nocapture writeonly %1, i64 %2, i32* nocapture %3, i64 %4) {
%6 = icmp eq i32 %0, 34
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %4)
br label %9
9: ; preds = %7, %5
%10 = tail call i32 @getc(i32* %3)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %48, label %13
13: ; preds = %9
%14 = add i64 %2, -1
br label %15
15: ; preds = %13, %38
%16 = phi i32 [ %10, %13 ], [ %42, %38 ]
%17 = phi i32 [ 0, %13 ], [ %40, %38 ]
switch i32 %16, label %34 [
i32 34, label %18
i32 92, label %27
]
18: ; preds = %15
%19 = zext i32 %17 to i64
%20 = icmp ult i64 %19, %2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 0, i8* %22
%23 = tail call i32 @getc(i32* %3)
br label %51
24: ; preds = %18
%25 = tail call i32 @error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%26 = load i32, i32* @EOF
br label %51
27: ; preds = %15
%28 = tail call i32 @getc(i32* %3)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = tail call i32 @error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64 %4)
%33 = load i32, i32* @EOF
br label %51
34: ; preds = %27, %15
%35 = phi i32 [ %16, %15 ], [ %28, %27 ]
%36 = zext i32 %17 to i64
%37 = icmp ugt i64 %14, %36
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = trunc i32 %35 to i8
%40 = add i32 %17, 1
%41 = getelementptr inbounds i8, i8* %1, i64 %36
store i8 %39, i8* %41
%42 = tail call i32 @getc(i32* %3)
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %48, label %15
45: ; preds = %34
%46 = tail call i32 @error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%47 = load i32, i32* @EOF
br label %51
48: ; preds = %38, %9
%49 = tail call i32 @error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64 %4)
%50 = load i32, i32* @EOF
br label %51
51: ; preds = %48, %45, %31, %21, %24
%52 = phi i32 [ %47, %45 ], [ %33, %31 ], [ %23, %21 ], [ %26, %24 ], [ %50, %48 ]
ret i32 %52
}