#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int getint(FILE *fd) {
  int c, i;
  char dummy[10000];
  c = getc(fd);
  while (1) {
    if (c == '#')
      fgets(dummy, 9000, fd);
    if (c == EOF) {
      fprintf(stderr, "Image %s not binary PGM.\n", "is");
      exit(0);
    };
    if (c >= '0' && c <= '9')
      break;
    c = getc(fd);
  }
  i = 0;
  while (1) {
    i = (i * 10) + (c - '0');
    c = getc(fd);
    if (c == EOF)
      return (i);
    if (c < '0' || c > '9')
      break;
  }
  return (i);
}


x86 assembly (clang, -O0):
<getint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x23,-0x14(%rbp)
jne    117a <getint+0x3a>
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2328,%esi
call   1030 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%eax
jne    11af <getint+0x6f>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
lea    0xe77(%rip),%rdx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
cmpl   $0x30,-0x14(%rbp)
jl     11c8 <getint+0x88>
cmpl   $0x39,-0x14(%rbp)
jg     11c8 <getint+0x88>
jmp    11d9 <getint+0x99>
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
jmp    115b <getint+0x1b>
movl   $0x0,-0x18(%rbp)
imul   $0xa,-0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%eax
jne    1218 <getint+0xd8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123c <getint+0xfc>
cmpl   $0x30,-0x14(%rbp)
jl     122c <getint+0xec>
cmpl   $0x39,-0x14(%rbp)
jle    1231 <getint+0xf1>
jmp    1236 <getint+0xf6>
jmp    11e0 <getint+0xa0>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getint>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2718,%rsp
mov    %rdi,%r14
call   1060 <getc@plt>
mov    %eax,%ebx
mov    %rsp,%r15
mov    0x2e86(%rip),%r12
cmp    $0x23,%ebx
jne    1180 <getint+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x2328,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
cmp    (%r12),%ebx
je     11e6 <getint+0xa6>
lea    -0x30(%rbx),%eax
cmp    $0x9,%eax
jbe    119f <getint+0x5f>
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %eax,%ebx
cmp    $0x23,%ebx
je     1170 <getint+0x30>
jmp    1180 <getint+0x40>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r15,%r15,4),%eax
lea    (%rbx,%rax,2),%r15d
add    $0xffffffd0,%r15d
mov    %r14,%rdi
call   1060 <getc@plt>
cmp    (%r12),%eax
je     11d4 <getint+0x94>
mov    %eax,%ebx
add    $0xffffffc6,%eax
cmp    $0xfffffff5,%eax
ja     11b0 <getint+0x70>
mov    %r15d,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
lea    0xe1d(%rip),%rdx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"Image %s not binary PGM.\0A\00"
@.str.1 = [3 x i8] c"is\00"
define i32 @getint(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10000 x i8]
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @getc(i32* %7)
store i32 %8, i32* %4
br label %9
9: ; preds = %1, %31
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 35
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32 @fgets(i8* %13, i32 9000, i32* %14)
br label %16
16: ; preds = %12, %9
%17 = load i32, i32* %4
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = load i32, i32* %4
%26 = icmp sge i32 %25, 48
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp sle i32 %28, 57
br i1 %29, label %30, label %31
30: ; preds = %27
br label %34
31: ; preds = %27, %24
%32 = load i32*, i32** %3
%33 = call i32 @getc(i32* %32)
store i32 %33, i32* %4
br label %9
34: ; preds = %30
store i32 0, i32* %5
br label %35
35: ; preds = %34, %55
%36 = load i32, i32* %5
%37 = mul nsw i32 %36, 10
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 48
%40 = add nsw i32 %37, %39
store i32 %40, i32* %5
%41 = load i32*, i32** %3
%42 = call i32 @getc(i32* %41)
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %35
%47 = load i32, i32* %5
store i32 %47, i32* %2
br label %58
48: ; preds = %35
%49 = load i32, i32* %4
%50 = icmp slt i32 %49, 48
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* %4
%53 = icmp sgt i32 %52, 57
br i1 %53, label %54, label %55
54: ; preds = %51, %48
br label %56
55: ; preds = %51
br label %35
56: ; preds = %54
%57 = load i32, i32* %5
store i32 %57, i32* %2
br label %58
58: ; preds = %56, %46
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"Image %s not binary PGM.\0A\00"
@.str.1 = [3 x i8] c"is\00"
define i32 @getint(i32* nocapture %0) {
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @getc(i32* %0)
br label %5
5: ; preds = %20, %1
%6 = phi i32 [ %4, %1 ], [ %21, %20 ]
%7 = icmp eq i32 %6, 35
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @fgets(i8* %3, i32 9000, i32* %0)
br label %10
10: ; preds = %8, %5
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %6, %11
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %10
%18 = add i32 %6, -48
%19 = icmp ult i32 %18, 10
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @getc(i32* %0)
br label %5
22: ; preds = %17, %22
%23 = phi i32 [ %28, %22 ], [ %6, %17 ]
%24 = phi i32 [ %27, %22 ], [ 0, %17 ]
%25 = mul nsw i32 %24, 10
%26 = add nsw i32 %23, -48
%27 = add nsw i32 %26, %25
%28 = call i32 @getc(i32* %0)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
%31 = add i32 %28, -58
%32 = icmp ult i32 %31, -10
%33 = or i1 %30, %32
br i1 %33, label %34, label %22
34: ; preds = %22
ret i32 %27
}