#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 INT_MAX;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *const);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned int pbm_getuint(FILE *const ifP) {
  char ch, rubish[100000];
  unsigned int i;
  do {
    ch = fgetc(ifP);
    if (ch == '#')
      fgets(rubish, 100000, ifP);
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '#');
  if (ch < '0' || ch > '9') {
    fprintf(stderr, "junk in file where an unsigned integer should be\n");
    exit(-1);
  }
  i = 0;
  do {
    unsigned int const digitVal = ch - '0';
    if (i > INT_MAX / 10 - digitVal) {
      fprintf(stderr, "ASCII decimal integer in file is too             large "
                      "to be processed.\n");
      exit(-1);
    }
    i = i * 10 + digitVal;
    ch = fgetc(ifP);
  } while (ch >= '0' && ch <= '9');
  return i;
}


x86 assembly (clang, -O0):
<pbm_getuint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186d0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x23,%eax
jne    117d <pbm_getuint+0x3d>
lea    -0x186b0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x186a0,%esi
call   1040 <fgets@plt>
jmp    1182 <pbm_getuint+0x42>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x186b9(%rbp)
je     11e6 <pbm_getuint+0xa6>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x186b9(%rbp)
je     11e6 <pbm_getuint+0xa6>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x186b9(%rbp)
je     11e6 <pbm_getuint+0xa6>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x186b9(%rbp)
je     11e6 <pbm_getuint+0xa6>
movsbl -0x9(%rbp),%eax
cmp    $0x23,%eax
sete   %al
mov    %al,-0x186b9(%rbp)
mov    -0x186b9(%rbp),%al
test   $0x1,%al
jne    114f <pbm_getuint+0xf>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     120e <pbm_getuint+0xce>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jle    122d <pbm_getuint+0xed>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
movl   $0x0,-0x186b4(%rbp)
movsbl -0x9(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x186b8(%rbp)
mov    -0x186b4(%rbp),%eax
mov    %eax,-0x186c0(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x186c0(%rbp),%eax
sub    -0x186b8(%rbp),%ecx
cmp    %ecx,%eax
jbe    1296 <pbm_getuint+0x156>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
imul   $0xa,-0x186b4(%rbp),%eax
add    -0x186b8(%rbp),%eax
mov    %eax,-0x186b4(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x186c1(%rbp)
jl     12da <pbm_getuint+0x19a>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x186c1(%rbp)
mov    -0x186c1(%rbp),%al
test   $0x1,%al
jne    1237 <pbm_getuint+0xf7>
mov    -0x186b4(%rbp),%eax
add    $0x186d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbm_getuint>:
push   %r15
push   %r14
push   %rbx
sub    $0x186a0,%rsp
mov    %rdi,%r14
movabs $0x100002600,%rbx
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0x23,%al
ja     118d <pbm_getuint+0x4d>
movzbl %al,%ecx
bt     %rcx,%rbx
jb     1160 <pbm_getuint+0x20>
cmp    $0x23,%rcx
jne    118d <pbm_getuint+0x4d>
mov    %r15,%rdi
mov    $0x186a0,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
jmp    1160 <pbm_getuint+0x20>
lea    -0x3a(%rax),%ecx
cmp    $0xf6,%cl
jb     1209 <pbm_getuint+0xc9>
xor    %ebx,%ebx
mov    0x2e4a(%rip),%r15
xchg   %ax,%ax
movzbl %al,%eax
add    $0xffffffd0,%eax
movslq (%r15),%rcx
imul   $0x66666667,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebx
ja     11ea <pbm_getuint+0xaa>
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
add    $0xd0,%cl
cmp    $0xa,%cl
jb     11a0 <pbm_getuint+0x60>
mov    %ebx,%eax
add    $0x186a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
jmp    11fa <pbm_getuint+0xba>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"junk in file where an unsigned integer should be\0A\00"
@INT_MAX = global i32 0
@.str.1 = [73 x i8] c"ASCII decimal integer in file is too large to be processed.\0A\00"
define i32 @pbm_getuint(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca [100000 x i8]
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
br label %7
7: ; preds = %38, %1
%8 = load i32*, i32** %2
%9 = call signext i8 @fgetc(i32* %8)
store i8 %9, i8* %3
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 35
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = getelementptr inbounds [100000 x i8], [100000 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i32 @fgets(i8* %14, i32 100000, i32* %15)
br label %17
17: ; preds = %13, %7
br label %18
18: ; preds = %17
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 32
br i1 %21, label %38, label %22
22: ; preds = %18
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 9
br i1 %25, label %38, label %26
26: ; preds = %22
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %38, label %30
30: ; preds = %26
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 13
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i8, i8* %3
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 35
br label %38
38: ; preds = %34, %30, %26, %22, %18
%39 = phi i1 [ true, %30 ], [ true, %26 ], [ true, %22 ], [ true, %18 ], [ %37, %34 ]
br i1 %39, label %7, label %40
40: ; preds = %38
%41 = load i8, i8* %3
%42 = sext i8 %41 to i32
%43 = icmp slt i32 %42, 48
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
%47 = icmp sgt i32 %46, 57
br i1 %47, label %48, label %52
48: ; preds = %44, %40
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
52: ; preds = %44
store i32 0, i32* %5
br label %53
53: ; preds = %82, %52
%54 = load i8, i8* %3
%55 = sext i8 %54 to i32
%56 = sub nsw i32 %55, 48
store i32 %56, i32* %6
%57 = load i32, i32* %5
%58 = load i32, i32* @INT_MAX
%59 = sdiv i32 %58, 10
%60 = load i32, i32* %6
%61 = sub i32 %59, %60
%62 = icmp ugt i32 %57, %61
br i1 %62, label %63, label %67
63: ; preds = %53
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %53
%68 = load i32, i32* %5
%69 = mul i32 %68, 10
%70 = load i32, i32* %6
%71 = add i32 %69, %70
store i32 %71, i32* %5
%72 = load i32*, i32** %2
%73 = call signext i8 @fgetc(i32* %72)
store i8 %73, i8* %3
br label %74
74: ; preds = %67
%75 = load i8, i8* %3
%76 = sext i8 %75 to i32
%77 = icmp sge i32 %76, 48
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = load i8, i8* %3
%80 = sext i8 %79 to i32
%81 = icmp sle i32 %80, 57
br label %82
82: ; preds = %78, %74
%83 = phi i1 [ false, %74 ], [ %81, %78 ]
br i1 %83, label %53, label %84
84: ; preds = %82
%85 = load i32, i32* %5
ret i32 %85
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"junk in file where an unsigned integer should be\0A\00"
@INT_MAX = global i32 0
@.str.1 = [73 x i8] c"ASCII decimal integer in file is too large to be processed.\0A\00"
define i32 @pbm_getuint(i32* nocapture %0) {
%2 = alloca [100000 x i8]
%3 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %6, %1
%5 = call signext i8 @fgetc(i32* %0)
switch i8 %5, label %9 [
i8 35, label %7
i8 32, label %6
i8 13, label %6
i8 10, label %6
i8 9, label %6
]
6: ; preds = %4, %4, %4, %4, %7
br label %4
7: ; preds = %4
%8 = call i32 @fgets(i8* %3, i32 100000, i32* %0)
br label %6
9: ; preds = %4
%10 = add i8 %5, -58
%11 = icmp ult i8 %10, -10
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %9, %29
%17 = phi i32 [ %31, %29 ], [ 0, %9 ]
%18 = phi i8 [ %32, %29 ], [ %5, %9 ]
%19 = zext i8 %18 to i32
%20 = add nsw i32 %19, -48
%21 = load i32, i32* @INT_MAX
%22 = sdiv i32 %21, 10
%23 = sub nsw i32 %22, %20
%24 = icmp ugt i32 %17, %23
br i1 %24, label %25, label %29
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %16
%30 = mul i32 %17, 10
%31 = add i32 %20, %30
%32 = call signext i8 @fgetc(i32* %0)
%33 = add i8 %32, -48
%34 = icmp ult i8 %33, 10
br i1 %34, label %16, label %35
35: ; preds = %29
ret i32 %31
}