#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 /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ read_ppm_line(int /*<<< orphan*/ *);
int read_ppm_int(FILE *fp) {
  int i = 0;
  unsigned char ch;
  fread(&ch, 1, 1, fp);
  while (ch < 48 || ch > 57) {
    if (ch == '#')
      read_ppm_line(fp);
    fread(&ch, 1, 1, fp);
  }
  while (ch >= 48 && ch <= 57) {
    i = i * 10 + (ch - 48);
    fread(&ch, 1, 1, fp);
  }
  fseek(fp, -1, SEEK_CUR);
  return i;
}


x86 assembly (clang, -O0):
<read_ppm_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0xd(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
movzbl -0xd(%rbp),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0xe(%rbp)
jl     1176 <read_ppm_int+0x46>
movzbl -0xd(%rbp),%eax
cmp    $0x39,%eax
setg   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    1186 <read_ppm_int+0x56>
jmp    11b5 <read_ppm_int+0x85>
movzbl -0xd(%rbp),%eax
cmp    $0x23,%eax
jne    119c <read_ppm_int+0x6c>
mov    -0x8(%rbp),%rdi
call   1030 <read_ppm_line@plt>
mov    -0x8(%rbp),%rcx
lea    -0xd(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
jmp    1157 <read_ppm_int+0x27>
jmp    11ba <read_ppm_int+0x8a>
movzbl -0xd(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0xf(%rbp)
jl     11d9 <read_ppm_int+0xa9>
movzbl -0xd(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0xf(%rbp)
mov    -0xf(%rbp),%al
test   $0x1,%al
jne    11e9 <read_ppm_int+0xb9>
jmp    1212 <read_ppm_int+0xe2>
imul   $0xa,-0xc(%rbp),%eax
movzbl -0xd(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0xd(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
jmp    11ba <read_ppm_int+0x8a>
mov    -0x8(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ppm_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    0xf(%rsp),%al
lea    -0x3a(%rax),%ecx
cmp    $0xf5,%cl
ja     11a0 <read_ppm_int+0x70>
lea    0xf(%rsp),%rbx
jmp    1192 <read_ppm_int+0x62>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movzbl 0xf(%rsp),%eax
lea    -0x3a(%rax),%ecx
cmp    $0xf6,%cl
jae    11a0 <read_ppm_int+0x70>
cmp    $0x23,%al
jne    1170 <read_ppm_int+0x40>
mov    %r14,%rdi
call   1030 <read_ppm_line@plt>
jmp    1170 <read_ppm_int+0x40>
xor    %ebx,%ebx
lea    0xf(%rsp),%r15
nopw   0x0(%rax,%rax,1)
movzbl %al,%eax
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
add    $0xffffffd0,%ebx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movzbl 0xf(%rsp),%eax
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
jb     11b0 <read_ppm_int+0x80>
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <fseek@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @read_ppm_int(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8
store i32* %0, i32** %2
store i32 0, i32* %3
%5 = load i32*, i32** %2
%6 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %5)
br label %7
7: ; preds = %24, %1
%8 = load i8, i8* %4
%9 = zext i8 %8 to i32
%10 = icmp slt i32 %9, 48
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = icmp sgt i32 %13, 57
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ true, %7 ], [ %14, %11 ]
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 35
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32*, i32** %2
%23 = call i32 @read_ppm_line(i32* %22)
br label %24
24: ; preds = %21, %17
%25 = load i32*, i32** %2
%26 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %25)
br label %7
27: ; preds = %15
br label %28
28: ; preds = %38, %27
%29 = load i8, i8* %4
%30 = zext i8 %29 to i32
%31 = icmp sge i32 %30, 48
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8, i8* %4
%34 = zext i8 %33 to i32
%35 = icmp sle i32 %34, 57
br label %36
36: ; preds = %32, %28
%37 = phi i1 [ false, %28 ], [ %35, %32 ]
br i1 %37, label %38, label %47
38: ; preds = %36
%39 = load i32, i32* %3
%40 = mul nsw i32 %39, 10
%41 = load i8, i8* %4
%42 = zext i8 %41 to i32
%43 = sub nsw i32 %42, 48
%44 = add nsw i32 %40, %43
store i32 %44, i32* %3
%45 = load i32*, i32** %2
%46 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %45)
br label %28
47: ; preds = %36
%48 = load i32*, i32** %2
%49 = load i32, i32* @SEEK_CUR
%50 = call i32 @fseek(i32* %48, i32 -1, i32 %49)
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @read_ppm_int(i32* %0) {
%2 = alloca i8
%3 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %0)
%4 = load i8, i8* %2
%5 = add i8 %4, -58
%6 = icmp ult i8 %5, -10
br i1 %6, label %7, label %17
7: ; preds = %1, %12
%8 = phi i8 [ %14, %12 ], [ %4, %1 ]
%9 = icmp eq i8 %8, 35
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @read_ppm_line(i32* %0)
br label %12
12: ; preds = %10, %7
%13 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %0)
%14 = load i8, i8* %2
%15 = add i8 %14, -58
%16 = icmp ult i8 %15, -10
br i1 %16, label %7, label %17
17: ; preds = %12, %1
%18 = phi i8 [ %4, %1 ], [ %14, %12 ]
br label %19
19: ; preds = %17, %19
%20 = phi i8 [ %27, %19 ], [ %18, %17 ]
%21 = phi i32 [ %25, %19 ], [ 0, %17 ]
%22 = zext i8 %20 to i32
%23 = mul nsw i32 %21, 10
%24 = add i32 %23, -48
%25 = add i32 %24, %22
%26 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %0)
%27 = load i8, i8* %2
%28 = add i8 %27, -48
%29 = icmp ult i8 %28, 10
br i1 %29, label %19, label %30
30: ; preds = %19
%31 = load i32, i32* @SEEK_CUR
%32 = tail call i32 @fseek(i32* %0, i32 -1, i32 %31)
ret i32 %25
}