#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned int pgm_getuint(FILE *const ifP) {
  char ch;
  unsigned int i;
  do {
    ch = fgetc(ifP);
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
  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):
<pgm_getuint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x15(%rbp)
je     118b <pgm_getuint+0x5b>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x15(%rbp)
je     118b <pgm_getuint+0x5b>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x15(%rbp)
je     118b <pgm_getuint+0x5b>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    113c <pgm_getuint+0xc>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     11b0 <pgm_getuint+0x80>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jle    11cf <pgm_getuint+0x9f>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
movsbl -0x9(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jbe    1226 <pgm_getuint+0xf6>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
imul   $0xa,-0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x10(%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,-0x1d(%rbp)
jl     125b <pgm_getuint+0x12b>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11d6 <pgm_getuint+0xa6>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgm_getuint>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movabs $0x100002600,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0x20,%al
ja     1165 <pgm_getuint+0x35>
movzbl %al,%ecx
bt     %rcx,%rbx
jb     1150 <pgm_getuint+0x20>
lea    -0x3a(%rax),%ecx
cmp    $0xf6,%cl
jb     11e2 <pgm_getuint+0xb2>
xor    %ebx,%ebx
mov    0x2e72(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
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     11c3 <pgm_getuint+0x93>
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     1180 <pgm_getuint+0x50>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
jmp    11d3 <pgm_getuint+0xa3>

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

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 = [61 x i8] c"ASCII decimal integer in file is too large to be processed.\0A\00"
define i32 @pgm_getuint(i32* nocapture %0) {
br label %2
2: ; preds = %4, %1
%3 = tail call signext i8 @fgetc(i32* %0)
switch i8 %3, label %5 [
i8 32, label %4
i8 13, label %4
i8 10, label %4
i8 9, label %4
]
4: ; preds = %2, %2, %2, %2
br label %2
5: ; preds = %2
%6 = add i8 %3, -58
%7 = icmp ult i8 %6, -10
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %5, %25
%13 = phi i32 [ %27, %25 ], [ 0, %5 ]
%14 = phi i8 [ %28, %25 ], [ %3, %5 ]
%15 = zext i8 %14 to i32
%16 = add nsw i32 %15, -48
%17 = load i32, i32* @INT_MAX
%18 = sdiv i32 %17, 10
%19 = sub nsw i32 %18, %16
%20 = icmp ugt i32 %13, %19
br i1 %20, label %21, label %25
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %12
%26 = mul i32 %13, 10
%27 = add i32 %16, %26
%28 = tail call signext i8 @fgetc(i32* %0)
%29 = add i8 %28, -48
%30 = icmp ult i8 %29, 10
br i1 %30, label %12, label %31
31: ; preds = %25
ret i32 %27
}