#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 */

/* Variables and functions */
char getchar();
int hexValue(char);
scalar_t__ isdigit(char);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
int getIntNum(char firstCharacter) {
  int num = 0;
  int value;
  char ch;
  if (firstCharacter != '0') {
    ch = firstCharacter;
    do {
      num = 10 * num + (int)(ch - '0');
      ch = getchar();
    } while (isdigit(ch));
  } else {
    ch = getchar();
    if ((ch >= '0') && (ch <= '7'))
      do {
        num = 8 * num + (int)(ch - '0');
        ch = getchar();
      } while ((ch >= '0') || (ch <= '7'));
    else if ((ch == 'X') || (ch == 'x')) {
      while ((value = hexValue(ch = getchar())) != -1)
        num = 16 * num + value;
    } else
      num = 0;
  }
  ungetc(ch, stdin);
  return num;
}


x86 assembly (clang, -O0):
<getIntNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
je     119a <getIntNum+0x5a>
mov    -0x1(%rbp),%al
mov    %al,-0xd(%rbp)
imul   $0xa,-0x8(%rbp),%eax
movsbl -0xd(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1168 <getIntNum+0x28>
jmp    1272 <getIntNum+0x132>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x30,%eax
jl     120e <getIntNum+0xce>
movsbl -0xd(%rbp),%eax
cmp    $0x37,%eax
jg     120e <getIntNum+0xce>
jmp    11c3 <getIntNum+0x83>
mov    -0x8(%rbp),%eax
shl    $0x3,%eax
movsbl -0xd(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0xe(%rbp)
jge    11fe <getIntNum+0xbe>
movsbl -0xd(%rbp),%eax
cmp    $0x37,%eax
setle  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    11c3 <getIntNum+0x83>
jmp    126d <getIntNum+0x12d>
movsbl -0xd(%rbp),%eax
cmp    $0x58,%eax
je     1228 <getIntNum+0xe8>
movsbl -0xd(%rbp),%eax
cmp    $0x78,%eax
jne    1261 <getIntNum+0x121>
jmp    122d <getIntNum+0xed>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%edi
call   1050 <hexValue@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     125c <getIntNum+0x11c>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    122d <getIntNum+0xed>
jmp    1268 <getIntNum+0x128>
movl   $0x0,-0x8(%rbp)
jmp    126d <getIntNum+0x12d>
jmp    1272 <getIntNum+0x132>
mov    -0xd(%rbp),%al
mov    0x2d6c(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <ungetc@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIntNum>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %ebx,%ebx
cmp    $0x30,%bpl
jne    1170 <getIntNum+0x30>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
and    $0xf8,%al
cmp    $0x30,%al
jne    11ae <getIntNum+0x6e>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
jmp    1160 <getIntNum+0x20>
nopl   0x0(%rax)
lea    (%rbx,%rbx,4),%eax
movsbl %bpl,%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <getIntNum+0x30>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
movsbl %bpl,%edi
call   1060 <ungetc@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%eax
and    $0xdf,%al
cmp    $0x58,%al
jne    1193 <getIntNum+0x53>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
movsbl %al,%edi
call   1050 <hexValue@plt>
cmp    $0xffffffff,%eax
je     1193 <getIntNum+0x53>
xor    %ebx,%ebx
shl    $0x4,%ebx
add    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
movsbl %al,%edi
call   1050 <hexValue@plt>
cmp    $0xffffffff,%eax
jne    11d0 <getIntNum+0x90>
jmp    1193 <getIntNum+0x53>

LLVM IR (-O0):
@stdin = global i32 0
define i32 @getIntNum(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8 %0, i8* %2
store i32 0, i32* %3
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 48
br i1 %8, label %9, label %24
9: ; preds = %1
%10 = load i8, i8* %2
store i8 %10, i8* %5
br label %11
11: ; preds = %19, %9
%12 = load i32, i32* %3
%13 = mul nsw i32 10, %12
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 48
%17 = add nsw i32 %13, %16
store i32 %17, i32* %3
%18 = call signext i8 (...) @getchar()
store i8 %18, i8* %5
br label %19
19: ; preds = %11
%20 = load i8, i8* %5
%21 = call i64 @isdigit(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %19
br label %75
24: ; preds = %1
%25 = call signext i8 (...) @getchar()
store i8 %25, i8* %5
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %53
29: ; preds = %24
%30 = load i8, i8* %5
%31 = sext i8 %30 to i32
%32 = icmp sle i32 %31, 55
br i1 %32, label %33, label %53
33: ; preds = %29
br label %34
34: ; preds = %50, %33
%35 = load i32, i32* %3
%36 = mul nsw i32 8, %35
%37 = load i8, i8* %5
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 48
%40 = add nsw i32 %36, %39
store i32 %40, i32* %3
%41 = call signext i8 (...) @getchar()
store i8 %41, i8* %5
br label %42
42: ; preds = %34
%43 = load i8, i8* %5
%44 = sext i8 %43 to i32
%45 = icmp sge i32 %44, 48
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
%49 = icmp sle i32 %48, 55
br label %50
50: ; preds = %46, %42
%51 = phi i1 [ true, %42 ], [ %49, %46 ]
br i1 %51, label %34, label %52
52: ; preds = %50
br label %74
53: ; preds = %29, %24
%54 = load i8, i8* %5
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 88
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i8, i8* %5
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 120
br i1 %60, label %61, label %72
61: ; preds = %57, %53
br label %62
62: ; preds = %66, %61
%63 = call signext i8 (...) @getchar()
store i8 %63, i8* %5
%64 = call i32 @hexValue(i8 signext %63)
store i32 %64, i32* %4
%65 = icmp ne i32 %64, -1
br i1 %65, label %66, label %71
66: ; preds = %62
%67 = load i32, i32* %3
%68 = mul nsw i32 16, %67
%69 = load i32, i32* %4
%70 = add nsw i32 %68, %69
store i32 %70, i32* %3
br label %62
71: ; preds = %62
br label %73
72: ; preds = %57
store i32 0, i32* %3
br label %73
73: ; preds = %72, %71
br label %74
74: ; preds = %73, %52
br label %75
75: ; preds = %74, %23
%76 = load i8, i8* %5
%77 = load i32, i32* @stdin
%78 = call i32 @ungetc(i8 signext %76, i32 %77)
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @getIntNum(i8 signext %0) {
%2 = icmp eq i8 %0, 48
br i1 %2, label %13, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 0, %1 ]
%5 = phi i8 [ %10, %3 ], [ %0, %1 ]
%6 = mul nsw i32 %4, 10
%7 = sext i8 %5 to i32
%8 = add i32 %6, -48
%9 = add i32 %8, %7
%10 = tail call signext i8 (...) @getchar()
%11 = tail call i64 @isdigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %34, label %3
13: ; preds = %1
%14 = tail call signext i8 (...) @getchar()
%15 = and i8 %14, -8
%16 = icmp eq i8 %15, 48
br i1 %16, label %17, label %19
17: ; preds = %13, %17
%18 = tail call signext i8 (...) @getchar()
br label %17
19: ; preds = %13
%20 = and i8 %14, -33
%21 = icmp eq i8 %20, 88
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = tail call signext i8 (...) @getchar()
%24 = tail call i32 @hexValue(i8 signext %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %34, label %26
26: ; preds = %22, %26
%27 = phi i32 [ %32, %26 ], [ %24, %22 ]
%28 = phi i32 [ %30, %26 ], [ 0, %22 ]
%29 = shl nsw i32 %28, 4
%30 = add nsw i32 %27, %29
%31 = tail call signext i8 (...) @getchar()
%32 = tail call i32 @hexValue(i8 signext %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %26
34: ; preds = %3, %26, %22, %19
%35 = phi i32 [ 0, %19 ], [ 0, %22 ], [ %30, %26 ], [ %9, %3 ]
%36 = phi i8 [ %14, %19 ], [ %23, %22 ], [ %31, %26 ], [ %10, %3 ]
%37 = load i32, i32* @stdin
%38 = tail call i32 @ungetc(i8 signext %36, i32 %37)
ret i32 %35
}