#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 fgetc(int /*<<< orphan*/ *);
int putc(int, int /*<<< orphan*/ *);
int parse_header(FILE *input, FILE *output) {
  int previous = 0, letter;
  int CR = '\r';
  int LF = '\n';
  while ((letter = fgetc(input)) != EOF) {
    if (putc(letter, output) == EOF)
      return 2;
    if (letter == CR)
      continue;
    if (previous == LF && letter == LF)
      return 0;
    previous = letter;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xd,-0x24(%rbp)
movl   $0xa,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%eax
je     11c7 <parse_header+0xa7>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <putc@plt>
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%eax
jne    1187 <parse_header+0x67>
movl   $0x2,-0x4(%rbp)
jmp    11ce <parse_header+0xae>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1198 <parse_header+0x78>
jmp    1145 <parse_header+0x25>
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    11bc <parse_header+0x9c>
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    11bc <parse_header+0x9c>
movl   $0x0,-0x4(%rbp)
jmp    11ce <parse_header+0xae>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <parse_header+0x25>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r12d,%r12d
mov    0x2eb0(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%eax
je     1178 <parse_header+0x58>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
cmp    (%r15),%eax
je     117f <parse_header+0x5f>
cmp    $0xd,%ebp
je     1140 <parse_header+0x20>
cmp    $0xa,%r12d
mov    %ebp,%r12d
jne    1140 <parse_header+0x20>
mov    %ebp,%r12d
cmp    $0xa,%ebp
jne    1140 <parse_header+0x20>
xor    %eax,%eax
jmp    1184 <parse_header+0x64>
mov    $0x1,%eax
jmp    1184 <parse_header+0x64>
mov    $0x2,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @parse_header(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 13, i32* %8
store i32 10, i32* %9
br label %10
10: ; preds = %36, %26, %2
%11 = load i32*, i32** %4
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %7
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %10
%16 = load i32, i32* %7
%17 = load i32*, i32** %5
%18 = call i32 @putc(i32 %16, i32* %17)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 2, i32* %3
br label %39
22: ; preds = %15
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
br label %10
27: ; preds = %22
%28 = load i32, i32* %6
%29 = load i32, i32* %9
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* %7
%33 = load i32, i32* %9
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 0, i32* %3
br label %39
36: ; preds = %31, %27
%37 = load i32, i32* %7
store i32 %37, i32* %6
br label %10
38: ; preds = %10
store i32 1, i32* %3
br label %39
39: ; preds = %38, %35, %21
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @parse_header(i32* nocapture %0, i32* nocapture %1) {
br label %3
3: ; preds = %15, %2
%4 = phi i32 [ %6, %15 ], [ 0, %2 ]
br label %5
5: ; preds = %3, %13
%6 = tail call i32 @fgetc(i32* %0)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %19, label %9
9: ; preds = %5
%10 = tail call i32 @putc(i32 %6, i32* %1)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = icmp eq i32 %6, 13
br i1 %14, label %5, label %15
15: ; preds = %13
%16 = icmp eq i32 %4, 10
%17 = icmp eq i32 %6, 10
%18 = and i1 %16, %17
br i1 %18, label %19, label %3
19: ; preds = %15, %5, %9
%20 = phi i32 [ 1, %5 ], [ 2, %9 ], [ 0, %15 ]
ret i32 %20
}