#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(char *, char const *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fskip_comments(int /*<<< orphan*/ *, char);
char getc(int /*<<< orphan*/ *);
int fscanf_pnm_header(FILE *in, const char *filename, int *magic, int *width,
                      int *height, int *maxval) {
  static const char *fieldname[] = {"magic-number", "width", "height",
                                    "max-value", "first pixel"};
  int *arg[4], i, c;
  arg[0] = magic, arg[1] = width, arg[2] = height, arg[3] = maxval;
  for (i = 0; i < 4; i++) {
    fskip_comments(in, '#');
    if (i == 0 && getc(in) != 'P')
      goto badformat;
    if (fscanf(in, "%d", arg[i]) != 1)
      goto badformat;
  }
  do {
    if ((c = getc(in)) == EOF)
      goto badformat;
  } while (c != '\n');
  if (*magic <= 0 || *magic >= 10 || *width < 0 || *height < 0 || *maxval < 1) {
    fatal("PNM image file `%s': garbage in header", filename);
    return EOF;
  }
  return 0;
badformat:
  fatal("PNM file `%s': can't read %s", filename, fieldname[i]);
  return EOF;
}


x86 assembly (clang, -O0):
<fscanf_pnm_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jge    11fd <fscanf_pnm_header+0xbd>
mov    -0x10(%rbp),%rdi
mov    $0x23,%esi
call   1030 <fskip_comments@plt>
cmpl   $0x0,-0x64(%rbp)
jne    11c3 <fscanf_pnm_header+0x83>
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
movsbl %al,%eax
cmp    $0x50,%eax
je     11c3 <fscanf_pnm_header+0x83>
jmp    12a4 <fscanf_pnm_header+0x164>
mov    -0x10(%rbp),%rdi
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11ea <fscanf_pnm_header+0xaa>
jmp    12a4 <fscanf_pnm_header+0x164>
jmp    11ef <fscanf_pnm_header+0xaf>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1187 <fscanf_pnm_header+0x47>
jmp    1202 <fscanf_pnm_header+0xc2>
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
movsbl %al,%eax
mov    %eax,-0x68(%rbp)
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%eax
jne    1225 <fscanf_pnm_header+0xe5>
jmp    12a4 <fscanf_pnm_header+0x164>
jmp    122a <fscanf_pnm_header+0xea>
cmpl   $0xa,-0x68(%rbp)
jne    1202 <fscanf_pnm_header+0xc2>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    1275 <fscanf_pnm_header+0x135>
mov    -0x20(%rbp),%rax
cmpl   $0xa,(%rax)
jge    1275 <fscanf_pnm_header+0x135>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jl     1275 <fscanf_pnm_header+0x135>
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
jl     1275 <fscanf_pnm_header+0x135>
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1298 <fscanf_pnm_header+0x158>
mov    -0x18(%rbp),%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d1 <fscanf_pnm_header+0x191>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <fscanf_pnm_header+0x191>
mov    -0x18(%rbp),%rsi
movslq -0x64(%rbp),%rcx
lea    0x2d9d(%rip),%rax
mov    (%rax,%rcx,8),%rdx
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fscanf_pnm_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%rbp
mov    $0x23,%esi
call   1030 <fskip_comments@plt>
mov    %rbp,%rdi
call   1060 <getc@plt>
cmp    $0x50,%al
jne    126c <fscanf_pnm_header+0x12c>
lea    0xec6(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    126c <fscanf_pnm_header+0x12c>
mov    %rbp,%rdi
mov    $0x23,%esi
call   1030 <fskip_comments@plt>
lea    0xe9e(%rip),%rsi
mov    %rbp,%rdi
mov    %r12,%rdx
call   1040 <fscanf@plt>
mov    $0x1,%ecx
cmp    $0x1,%eax
jne    126e <fscanf_pnm_header+0x12e>
mov    %rbp,%rdi
mov    $0x23,%esi
call   1030 <fskip_comments@plt>
lea    0xe71(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
call   1040 <fscanf@plt>
mov    $0x2,%ecx
cmp    $0x1,%eax
jne    126e <fscanf_pnm_header+0x12e>
mov    %rbp,%rdi
mov    $0x23,%esi
call   1030 <fskip_comments@plt>
lea    0xe44(%rip),%rsi
mov    %rbp,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    $0x3,%ecx
cmp    $0x1,%eax
jne    126e <fscanf_pnm_header+0x12e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1060 <getc@plt>
movsbl %al,%ecx
mov    0x2db6(%rip),%rdx
cmp    %ecx,(%rdx)
je     12a5 <fscanf_pnm_header+0x165>
cmp    $0xa,%al
jne    1220 <fscanf_pnm_header+0xe0>
mov    (%rbx),%eax
add    $0xfffffff6,%eax
cmp    $0xfffffff7,%eax
jb     1259 <fscanf_pnm_header+0x119>
cmpl   $0x0,(%r12)
js     1259 <fscanf_pnm_header+0x119>
cmpl   $0x0,(%r15)
js     1259 <fscanf_pnm_header+0x119>
xor    %eax,%eax
cmpl   $0x0,(%r14)
jg     1296 <fscanf_pnm_header+0x156>
lea    0xde7(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <fatal@plt>
jmp    128d <fscanf_pnm_header+0x14d>
xor    %ecx,%ecx
lea    0xd8b(%rip),%rax
movslq (%rax,%rcx,4),%rdx
add    %rax,%rdx
lea    0xdeb(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <fatal@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x4,%ecx
jmp    126e <fscanf_pnm_header+0x12e>

LLVM IR (-O0):
@fscanf_pnm_header.fieldname = internal global [5 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0)]
@.str = [13 x i8] c"magic-number\00"
@.str.1 = [6 x i8] c"width\00"
@.str.2 = [7 x i8] c"height\00"
@.str.3 = [10 x i8] c"max-value\00"
@.str.4 = [12 x i8] c"first pixel\00"
@.str.5 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.6 = [39 x i8] c"PNM image file `%s': garbage in header\00"
@.str.7 = [29 x i8] c"PNM file `%s': can't read %s\00"
define i32 @fscanf_pnm_header(i32* %0, i8* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca [4 x i32*]
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%17 = load i32*, i32** %10
%18 = getelementptr inbounds [4 x i32*], [4 x i32*]* %14, i64 0, i64 0
store i32* %17, i32** %18
%19 = load i32*, i32** %11
%20 = getelementptr inbounds [4 x i32*], [4 x i32*]* %14, i64 0, i64 1
store i32* %19, i32** %20
%21 = load i32*, i32** %12
%22 = getelementptr inbounds [4 x i32*], [4 x i32*]* %14, i64 0, i64 2
store i32* %21, i32** %22
%23 = load i32*, i32** %13
%24 = getelementptr inbounds [4 x i32*], [4 x i32*]* %14, i64 0, i64 3
store i32* %23, i32** %24
store i32 0, i32* %15
br label %25
25: ; preds = %49, %6
%26 = load i32, i32* %15
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %52
28: ; preds = %25
%29 = load i32*, i32** %8
%30 = call i32 @fskip_comments(i32* %29, i8 signext 35)
%31 = load i32, i32* %15
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = load i32*, i32** %8
%35 = call signext i8 @getc(i32* %34)
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 80
br i1 %37, label %38, label %39
38: ; preds = %33
br label %89
39: ; preds = %33, %28
%40 = load i32*, i32** %8
%41 = load i32, i32* %15
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4 x i32*], [4 x i32*]* %14, i64 0, i64 %42
%44 = load i32*, i32** %43
%45 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %44)
%46 = icmp ne i32 %45, 1
br i1 %46, label %47, label %48
47: ; preds = %39
br label %89
48: ; preds = %39
br label %49
49: ; preds = %48
%50 = load i32, i32* %15
%51 = add nsw i32 %50, 1
store i32 %51, i32* %15
br label %25
52: ; preds = %25
br label %53
53: ; preds = %61, %52
%54 = load i32*, i32** %8
%55 = call signext i8 @getc(i32* %54)
%56 = sext i8 %55 to i32
store i32 %56, i32* %16
%57 = load i32, i32* @EOF
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %53
br label %89
60: ; preds = %53
br label %61
61: ; preds = %60
%62 = load i32, i32* %16
%63 = icmp ne i32 %62, 10
br i1 %63, label %53, label %64
64: ; preds = %61
%65 = load i32*, i32** %10
%66 = load i32, i32* %65
%67 = icmp sle i32 %66, 0
br i1 %67, label %84, label %68
68: ; preds = %64
%69 = load i32*, i32** %10
%70 = load i32, i32* %69
%71 = icmp sge i32 %70, 10
br i1 %71, label %84, label %72
72: ; preds = %68
%73 = load i32*, i32** %11
%74 = load i32, i32* %73
%75 = icmp slt i32 %74, 0
br i1 %75, label %84, label %76
76: ; preds = %72
%77 = load i32*, i32** %12
%78 = load i32, i32* %77
%79 = icmp slt i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %76
%81 = load i32*, i32** %13
%82 = load i32, i32* %81
%83 = icmp slt i32 %82, 1
br i1 %83, label %84, label %88
84: ; preds = %80, %76, %72, %68, %64
%85 = load i8*, i8** %9
%86 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %85)
%87 = load i32, i32* @EOF
store i32 %87, i32* %7
br label %97
88: ; preds = %80
store i32 0, i32* %7
br label %97
89: ; preds = %59, %47, %38
%90 = load i8*, i8** %9
%91 = load i32, i32* %15
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [5 x i8*], [5 x i8*]* @fscanf_pnm_header.fieldname, i64 0, i64 %92
%94 = load i8*, i8** %93
%95 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %90, i8* %94)
%96 = load i32, i32* @EOF
store i32 %96, i32* %7
br label %97
97: ; preds = %89, %88, %84
%98 = load i32, i32* %7
ret i32 %98
}

LLVM IR (-O2):
@reltable.fscanf_pnm_header = internal unnamed_addr constant [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.fscanf_pnm_header to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.fscanf_pnm_header to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.fscanf_pnm_header to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.fscanf_pnm_header to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.fscanf_pnm_header to i64)) to i32)]
@.str = [13 x i8] c"magic-number\00"
@.str.1 = [6 x i8] c"width\00"
@.str.2 = [7 x i8] c"height\00"
@.str.3 = [10 x i8] c"max-value\00"
@.str.4 = [12 x i8] c"first pixel\00"
@.str.5 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.6 = [39 x i8] c"PNM image file `%s': garbage in header\00"
@.str.7 = [29 x i8] c"PNM file `%s': can't read %s\00"
define i32 @fscanf_pnm_header(i32* %0, i8* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = tail call i32 @fskip_comments(i32* %0, i8 signext 35)
%8 = tail call signext i8 @getc(i32* %0)
%9 = icmp eq i8 %8, 80
br i1 %9, label %10, label %48
10: ; preds = %6
%11 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %48
13: ; preds = %10
%14 = tail call i32 @fskip_comments(i32* %0, i8 signext 35)
%15 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %48
17: ; preds = %13
%18 = tail call i32 @fskip_comments(i32* %0, i8 signext 35)
%19 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = tail call i32 @fskip_comments(i32* %0, i8 signext 35)
%23 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %48
25: ; preds = %21, %30
%26 = tail call signext i8 @getc(i32* %0)
%27 = sext i8 %26 to i32
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %28, %27
br i1 %29, label %48, label %30
30: ; preds = %25
%31 = icmp eq i8 %26, 10
br i1 %31, label %32, label %25
32: ; preds = %30
%33 = load i32, i32* %2
%34 = add i32 %33, -10
%35 = icmp ult i32 %34, -9
br i1 %35, label %45, label %36
36: ; preds = %32
%37 = load i32, i32* %3
%38 = icmp slt i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 1
br i1 %44, label %45, label %54
45: ; preds = %42, %39, %36, %32
%46 = tail call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%47 = load i32, i32* @EOF
br label %54
48: ; preds = %25, %10, %6, %13, %17, %21
%49 = phi i64 [ 0, %6 ], [ 0, %10 ], [ 1, %13 ], [ 2, %17 ], [ 3, %21 ], [ 4, %25 ]
%50 = shl i64 %49, 2
%51 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.fscanf_pnm_header to i8*), i64 %50)
%52 = tail call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %1, i8* %51)
%53 = load i32, i32* @EOF
br label %54
54: ; preds = %42, %48, %45
%55 = phi i32 [ %53, %48 ], [ %47, %45 ], [ 0, %42 ]
ret i32 %55
}