#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 getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int pnm_fget_char(FILE *stream) {
  int ch = getc(stream);
  if (ch == '#') {
    do {
      ch = getc(stream);
    } while (ch != EOF && ch != '\n' && ch != '\r');
  }
  if (ch == '\r') {
    ch = getc(stream);
    if (ch != '\n') {
      ungetc(ch, stream);
      ch = '\n';
    }
  }
  return ch;
}


x86 assembly (clang, -O0):
<pnm_fget_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x23,-0xc(%rbp)
jne    1193 <pnm_fget_char+0x73>
jmp    1147 <pnm_fget_char+0x27>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    0x2e89(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xd(%rbp)
je     1183 <pnm_fget_char+0x63>
xor    %eax,%eax
cmpl   $0xa,-0xc(%rbp)
mov    %al,-0xd(%rbp)
je     1183 <pnm_fget_char+0x63>
cmpl   $0xd,-0xc(%rbp)
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1147 <pnm_fget_char+0x27>
jmp    1193 <pnm_fget_char+0x73>
cmpl   $0xd,-0xc(%rbp)
jne    11cb <pnm_fget_char+0xab>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
je     11c6 <pnm_fget_char+0xa6>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <ungetc@plt>
movl   $0xa,-0xc(%rbp)
jmp    11cb <pnm_fget_char+0xab>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pnm_fget_char>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <getc@plt>
mov    %eax,%ebp
cmp    $0x23,%eax
jne    1159 <pnm_fget_char+0x39>
mov    0x2eae(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
je     1159 <pnm_fget_char+0x39>
cmp    $0xd,%ebp
je     1159 <pnm_fget_char+0x39>
cmp    $0xa,%ebp
jne    1140 <pnm_fget_char+0x20>
cmp    $0xd,%ebp
jne    117a <pnm_fget_char+0x5a>
mov    %rbx,%rdi
call   1040 <getc@plt>
mov    $0xa,%ebp
cmp    $0xa,%eax
je     117a <pnm_fget_char+0x5a>
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <ungetc@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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