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


x86 assembly (clang, -O0):
<read_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
jne    1169 <read_name+0x49>
movl   $0x0,-0x4(%rbp)
jmp    1297 <read_name+0x177>
cmpl   $0x22,-0x2c(%rbp)
je     1183 <read_name+0x63>
mov    -0x28(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1030 <errex@plt>
jmp    1188 <read_name+0x68>
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%eax
je     1280 <read_name+0x160>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x22,%eax
je     11c8 <read_name+0xa8>
jmp    11b7 <read_name+0x97>
mov    -0x34(%rbp),%eax
sub    $0x5c,%eax
je     1201 <read_name+0xe1>
jmp    1234 <read_name+0x114>
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    11e5 <read_name+0xc5>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11f5 <read_name+0xd5>
mov    -0x28(%rbp),%rsi
lea    0xe37(%rip),%rdi
call   1030 <errex@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <read_name+0x177>
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%eax
jne    122f <read_name+0x10f>
mov    -0x28(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <errex@plt>
jmp    1234 <read_name+0x114>
mov    -0x30(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1266 <read_name+0x146>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1276 <read_name+0x156>
mov    -0x28(%rbp),%rsi
lea    0xdb6(%rip),%rdi
call   1030 <errex@plt>
jmp    127b <read_name+0x15b>
jmp    1188 <read_name+0x68>
mov    -0x28(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   1030 <errex@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,(%rsp)
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
mov    %rdx,%rdi
call   1040 <getc@plt>
mov    0x2e9c(%rip),%r14
xor    %ecx,%ecx
cmp    (%r14),%eax
je     118c <read_name+0x6c>
mov    %rbx,0x8(%rsp)
cmp    $0x22,%eax
je     116d <read_name+0x4d>
lea    0xe9c(%rip),%rdi
mov    (%rsp),%rsi
call   1030 <errex@plt>
mov    %rbp,%rdi
call   1040 <getc@plt>
cmp    (%r14),%eax
jne    119d <read_name+0x7d>
lea    0xed5(%rip),%rdi
mov    (%rsp),%rsi
call   1030 <errex@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%r13
xor    %r12d,%r12d
jmp    11d0 <read_name+0xb0>
xchg   %ax,%ax
lea    0xe70(%rip),%rdi
mov    (%rsp),%rsi
call   1030 <errex@plt>
mov    %rbp,%rdi
call   1040 <getc@plt>
mov    %eax,%r15d
cmp    (%r14),%eax
je     117a <read_name+0x5a>
mov    %r12d,%ebx
cmp    $0x5c,%r15d
je     11f0 <read_name+0xd0>
cmp    $0x22,%r15d
jne    1210 <read_name+0xf0>
jmp    1224 <read_name+0x104>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <getc@plt>
mov    %eax,%r15d
cmp    (%r14),%eax
jne    1210 <read_name+0xf0>
lea    0xe4f(%rip),%rdi
mov    (%rsp),%rsi
call   1030 <errex@plt>
cmp    %rbx,%r13
jbe    11b0 <read_name+0x90>
add    $0x1,%r12d
mov    0x10(%rsp),%rax
mov    %r15b,(%rax,%rbx,1)
jmp    11c0 <read_name+0xa0>
cmp    0x8(%rsp),%rbx
jae    123e <read_name+0x11e>
mov    0x10(%rsp),%rax
movb   $0x0,(%rax,%rbx,1)
mov    $0x1,%ecx
jmp    118c <read_name+0x6c>
lea    0xde2(%rip),%rdi
mov    (%rsp),%rsi
call   1030 <errex@plt>
mov    $0x1,%ecx
jmp    118c <read_name+0x6c>

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

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