#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*/ fatal_error(int, char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const, ...);
void check_line(int line, FILE *e, const char *str) {
  const char *p;
  int c;
  char buf[1000];
  p = str;
  while (1) {
    c = getc(e);
    if (*p == '\0') {
      if (c != '\n') {
        snprintf(buf, sizeof buf, "got '%c' when expecting newline", c);
        fatal_error(line, buf, 0);
      }
      c = getc(e);
      if (c != EOF) {
        snprintf(buf, sizeof buf, "got '%c' when expecting EOF", c);
        fatal_error(line, buf, 0);
      }
      return;
    }
    if (c != *p) {
      snprintf(buf, sizeof buf, "expected '%c', got '%c'", *p, c);
      fatal_error(line, buf, 0);
    }
    ++p;
  }
}


x86 assembly (clang, -O0):
<check_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11fd <check_line+0xcd>
cmpl   $0xa,-0x24(%rbp)
je     11a5 <check_line+0x75>
lea    -0x410(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    $0x3e8,%esi
lea    0xe76(%rip),%rdx
movsbl %al,%ecx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
xor    %edx,%edx
call   1040 <fatal_error@plt>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%eax
je     11f4 <check_line+0xc4>
lea    -0x410(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    $0x3e8,%esi
lea    0xe47(%rip),%rdx
movsbl %al,%ecx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
xor    %edx,%edx
call   1040 <fatal_error@plt>
add    $0x410,%rsp
pop    %rbp
ret
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1247 <check_line+0x117>
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    -0x24(%rbp),%r8d
mov    $0x3e8,%esi
lea    0xe10(%rip),%rdx
movsbl %al,%ecx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
xor    %edx,%edx
call   1040 <fatal_error@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <check_line+0x1e>

x86 assembly (clang, -O2):
<check_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1050 <getc@plt>
mov    0x0(%rbp),%cl
test   %cl,%cl
je     11af <check_line+0x7f>
add    $0x1,%rbp
lea    0xeda(%rip),%r15
mov    %rsp,%r12
jmp    1184 <check_line+0x54>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <getc@plt>
movzbl 0x0(%rbp),%ecx
add    $0x1,%rbp
test   %cl,%cl
je     11af <check_line+0x7f>
movsbl %cl,%ecx
cmp    %ecx,%eax
je     1170 <check_line+0x40>
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %r14d,%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1040 <fatal_error@plt>
jmp    1170 <check_line+0x40>
cmp    $0xa,%eax
je     11dd <check_line+0xad>
movsbl %al,%ecx
lea    0xe42(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1040 <fatal_error@plt>
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%eax
je     1219 <check_line+0xe9>
movsbl %al,%ecx
lea    0xe26(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <fatal_error@plt>
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"got '%c' when expecting newline\00"
@EOF = global i32 0
@.str.1 = [28 x i8] c"got '%c' when expecting EOF\00"
@.str.2 = [24 x i8] c"expected '%c', got '%c'\00"
define void @check_line(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [1000 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
store i8* %10, i8** %7
br label %11
11: ; preds = %3, %59
%12 = load i32*, i32** %5
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %8
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %44
18: ; preds = %11
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%23 = load i32, i32* %8
%24 = trunc i32 %23 to i8
%25 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %22, i32 1000, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8 signext %24)
%26 = load i32, i32* %4
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%28 = call i32 @fatal_error(i32 %26, i8* %27, i32 0)
br label %29
29: ; preds = %21, %18
%30 = load i32*, i32** %5
%31 = call i32 @getc(i32* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = load i32, i32* @EOF
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %43
35: ; preds = %29
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%37 = load i32, i32* %8
%38 = trunc i32 %37 to i8
%39 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %36, i32 1000, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8 signext %38)
%40 = load i32, i32* %4
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%42 = call i32 @fatal_error(i32 %40, i8* %41, i32 0)
br label %43
43: ; preds = %35, %29
ret void
44: ; preds = %11
%45 = load i32, i32* %8
%46 = load i8*, i8** %7
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %45, %48
br i1 %49, label %50, label %59
50: ; preds = %44
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%52 = load i8*, i8** %7
%53 = load i8, i8* %52
%54 = load i32, i32* %8
%55 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %51, i32 1000, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8 signext %53, i32 %54)
%56 = load i32, i32* %4
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%58 = call i32 @fatal_error(i32 %56, i8* %57, i32 0)
br label %59
59: ; preds = %50, %44
%60 = load i8*, i8** %7
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %7
br label %11
}

LLVM IR (-O2):
@.str = [32 x i8] c"got '%c' when expecting newline\00"
@EOF = global i32 0
@.str.1 = [28 x i8] c"got '%c' when expecting EOF\00"
@.str.2 = [24 x i8] c"expected '%c', got '%c'\00"
define void @check_line(i32 %0, i32* nocapture %1, i8* nocapture %2) {
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%6 = call i32 @getc(i32* %1)
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %34, %3
%10 = phi i32 [ %6, %3 ], [ %36, %34 ]
%11 = icmp eq i32 %10, 10
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = trunc i32 %10 to i8
%14 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %5, i32 1000, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = call i32 @fatal_error(i32 %0, i8* %5, i32 0)
br label %16
16: ; preds = %12, %9
%17 = call i32 @getc(i32* %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = trunc i32 %17 to i8
%22 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %5, i32 1000, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8 signext %21)
%23 = call i32 @fatal_error(i32 %0, i8* %5, i32 0)
br label %24
24: ; preds = %20, %16
ret void
25: ; preds = %3, %34
%26 = phi i8 [ %37, %34 ], [ %7, %3 ]
%27 = phi i32 [ %36, %34 ], [ %6, %3 ]
%28 = phi i8* [ %35, %34 ], [ %2, %3 ]
%29 = sext i8 %26 to i32
%30 = icmp eq i32 %27, %29
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %5, i32 1000, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8 signext %26, i32 %27)
%33 = call i32 @fatal_error(i32 %0, i8* %5, i32 0)
br label %34
34: ; preds = %31, %25
%35 = getelementptr inbounds i8, i8* %28, i64 1
%36 = call i32 @getc(i32* %1)
%37 = load i8, i8* %35
%38 = icmp eq i8 %37, 0
br i1 %38, label %9, label %25
}