#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*/ pm_error(char *);
char pm_getc(int /*<<< orphan*/ *const);
unsigned int pm_getuint(FILE *const ifP) {
  char ch;
  unsigned int i;
  do {
    ch = pm_getc(ifP);
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
  if (ch < '0' || ch > '9')
    pm_error("junk in file where an unsigned integer should be");
  i = 0;
  do {
    unsigned int const digitVal = ch - '0';
    if (i > INT_MAX / 10)
      pm_error("ASCII decimal integer in file is "
               "too large to be processed.  ");
    i *= 10;
    if (i > INT_MAX - digitVal)
      pm_error("ASCII decimal integer in file is "
               "too large to be processed.  ");
    i += digitVal;
    ch = pm_getc(ifP);
  } while (ch >= '0' && ch <= '9');
  return i;
}


x86 assembly (clang, -O0):
<pm_getuint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <pm_getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x15(%rbp)
je     117b <pm_getuint+0x5b>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x15(%rbp)
je     117b <pm_getuint+0x5b>
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x15(%rbp)
je     117b <pm_getuint+0x5b>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    112c <pm_getuint+0xc>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     11a0 <pm_getuint+0x80>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jle    11ac <pm_getuint+0x8c>
lea    0xe59(%rip),%rdi
call   1040 <pm_error@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    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jbe    11ed <pm_getuint+0xcd>
lea    0xe49(%rip),%rdi
call   1040 <pm_error@plt>
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2dea(%rip),%rcx
mov    (%rcx),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jbe    1217 <pm_getuint+0xf7>
lea    0xe1f(%rip),%rdi
call   1040 <pm_error@plt>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <pm_getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x1d(%rbp)
jl     124b <pm_getuint+0x12b>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11b3 <pm_getuint+0x93>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_getuint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
movabs $0x100002600,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <pm_getc@plt>
mov    %eax,%ebx
cmp    $0x20,%al
ja     1157 <pm_getuint+0x37>
movzbl %bl,%eax
bt     %rax,%rbp
jb     1140 <pm_getuint+0x20>
lea    -0x3a(%rbx),%eax
cmp    $0xf5,%al
ja     116a <pm_getuint+0x4a>
lea    0xe9b(%rip),%rdi
call   1040 <pm_error@plt>
xor    %r13d,%r13d
mov    0x2e74(%rip),%r12
lea    0xeb6(%rip),%r14
jmp    1195 <pm_getuint+0x75>
nopl   (%rax)
add    %ebx,%ebp
mov    %r15,%rdi
call   1030 <pm_getc@plt>
mov    %eax,%ebx
add    $0xd0,%al
mov    %ebp,%r13d
cmp    $0xa,%al
jae    11dc <pm_getuint+0xbc>
movsbl %bl,%ebp
add    $0xffffffd0,%ebp
movslq (%r12),%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
cmp    %ecx,%r13d
jbe    11c4 <pm_getuint+0xa4>
mov    %r14,%rdi
call   1040 <pm_error@plt>
mov    (%r12),%eax
add    %r13d,%r13d
lea    0x0(%r13,%r13,4),%ebx
sub    %ebp,%eax
cmp    %eax,%ebx
jbe    1180 <pm_getuint+0x60>
mov    %r14,%rdi
call   1040 <pm_error@plt>
jmp    1180 <pm_getuint+0x60>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"junk in file where an unsigned integer should be\00"
@INT_MAX = global i32 0
@.str.1 = [62 x i8] c"ASCII decimal integer in file is too large to be processed. \00"
define i32 @pm_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 @pm_getc(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 %37
35: ; preds = %31, %27
%36 = call i32 @pm_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
store i32 0, i32* %4
br label %38
38: ; preds = %72, %37
%39 = load i8, i8* %3
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 48
store i32 %41, i32* %5
%42 = load i32, i32* %4
%43 = load i32, i32* @INT_MAX
%44 = sdiv i32 %43, 10
%45 = icmp ugt i32 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 @pm_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %38
%49 = load i32, i32* %4
%50 = mul i32 %49, 10
store i32 %50, i32* %4
%51 = load i32, i32* %4
%52 = load i32, i32* @INT_MAX
%53 = load i32, i32* %5
%54 = sub i32 %52, %53
%55 = icmp ugt i32 %51, %54
br i1 %55, label %56, label %58
56: ; preds = %48
%57 = call i32 @pm_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %48
%59 = load i32, i32* %5
%60 = load i32, i32* %4
%61 = add i32 %60, %59
store i32 %61, i32* %4
%62 = load i32*, i32** %2
%63 = call signext i8 @pm_getc(i32* %62)
store i8 %63, i8* %3
br label %64
64: ; preds = %58
%65 = load i8, i8* %3
%66 = sext i8 %65 to i32
%67 = icmp sge i32 %66, 48
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i8, i8* %3
%70 = sext i8 %69 to i32
%71 = icmp sle i32 %70, 57
br label %72
72: ; preds = %68, %64
%73 = phi i1 [ false, %64 ], [ %71, %68 ]
br i1 %73, label %38, label %74
74: ; preds = %72
%75 = load i32, i32* %4
ret i32 %75
}

LLVM IR (-O2):
@.str = [49 x i8] c"junk in file where an unsigned integer should be\00"
@INT_MAX = global i32 0
@.str.1 = [62 x i8] c"ASCII decimal integer in file is too large to be processed. \00"
define i32 @pm_getuint(i32* %0) {
br label %2
2: ; preds = %4, %1
%3 = tail call signext i8 @pm_getc(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 %10
8: ; preds = %5
%9 = tail call i32 @pm_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %5, %8
br label %11
11: ; preds = %10, %29
%12 = phi i32 [ %30, %29 ], [ 0, %10 ]
%13 = phi i8 [ %31, %29 ], [ %3, %10 ]
%14 = sext i8 %13 to i32
%15 = add nsw i32 %14, -48
%16 = load i32, i32* @INT_MAX
%17 = sdiv i32 %16, 10
%18 = icmp ugt i32 %12, %17
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i32 @pm_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @INT_MAX
br label %22
22: ; preds = %19, %11
%23 = phi i32 [ %21, %19 ], [ %16, %11 ]
%24 = mul i32 %12, 10
%25 = sub i32 %23, %15
%26 = icmp ugt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @pm_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = add i32 %15, %24
%31 = tail call signext i8 @pm_getc(i32* %0)
%32 = add i8 %31, -48
%33 = icmp ult i8 %32, 10
br i1 %33, label %11, label %34
34: ; preds = %29
ret i32 %30
}