#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 */
int EOF;
int getchar();
scalar_t__ isalpha(int);
scalar_t__ isdigit(int);
scalar_t__ islower(int);
scalar_t__ isupper(int);
int /*<<< orphan*/ printf(char *);
int htoi() {
  int int_result = 0, cr_digit = 0;
  int i = 0;
  int c = 0;
  if (!(((c = getchar()) == '0') && (((c = getchar()) == 'X') || (c == 'x')))) {
    printf("\n 1.U have a bad input! \n U should give a hexazecimal number "
           "(Example: 0x1A)!\n");
    int_result = -1;
  } else {
    while (((c = getchar()) != EOF) && (i < 30)) {
      i++;
      if (i == 30) {
        printf("\n 2.Your input is too long for my intelect!");
        int_result = -1;
      } else if (!(isalpha(c) || isdigit(c))) {
        if (c != '\n') {
          printf("\n 5.U have a bad input! \n Hexazecimal numbers contain only "
                 "digit and A,B,C,D,E,F (Example: 0x1A)!\n");
          int_result = -1;
        }
      } else {
        if (isupper(c)) {
          if (c > 'F') {
            printf("\n 3.U have a bad input! \n Hexazecimal numbers contain "
                   "only digit and A,B,C,D,E,F (Example: 0x1A)!\n");
            int_result = -1;
          } else
            cr_digit = c - 'A' + 10;
        } else if (islower(c)) {
          if (c > 'f') {
            printf("\n 4.U have a bad input! \n Hexazecimal numbers contain "
                   "only digit and a,b,c,d,e,f (Example: 0x1a)!\n");
            int_result = -1;
          } else
            cr_digit = c - 'a' + 10;
        } else
          cr_digit = c - '0';
        int_result = 16 * int_result + cr_digit;
      }
    }
  }
  return int_result;
}


x86 assembly (clang, -O0):
<htoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x30,%eax
jne    11b4 <htoi+0x54>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x58,%eax
je     11cc <htoi+0x6c>
cmpl   $0x78,-0x10(%rbp)
je     11cc <htoi+0x6c>
lea    0xe45(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132f <htoi+0x1cf>
jmp    11d1 <htoi+0x71>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e02(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     11fb <htoi+0x9b>
cmpl   $0x1e,-0xc(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    120b <htoi+0xab>
jmp    132a <htoi+0x1ca>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1e,-0xc(%rbp)
jne    1236 <htoi+0xd6>
lea    0xe2a(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <htoi+0x1c5>
mov    -0x10(%rbp),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%rax
jne    127c <htoi+0x11c>
mov    -0x10(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    127c <htoi+0x11c>
cmpl   $0xa,-0x10(%rbp)
je     1277 <htoi+0x117>
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1320 <htoi+0x1c0>
mov    -0x10(%rbp),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     12c1 <htoi+0x161>
cmpl   $0x46,-0x10(%rbp)
jle    12b0 <htoi+0x150>
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bc <htoi+0x15c>
mov    -0x10(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
jmp    1314 <htoi+0x1b4>
mov    -0x10(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     1306 <htoi+0x1a6>
cmpl   $0x66,-0x10(%rbp)
jle    12f5 <htoi+0x195>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1301 <htoi+0x1a1>
mov    -0x10(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
jmp    130f <htoi+0x1af>
mov    -0x10(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
jmp    1314 <htoi+0x1b4>
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1325 <htoi+0x1c5>
jmp    11d1 <htoi+0x71>
jmp    132f <htoi+0x1cf>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htoi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x30,%eax
jne    129b <htoi+0x12b>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
and    $0xffffffdf,%eax
cmp    $0x58,%eax
jne    129b <htoi+0x12b>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e3a(%rip),%r15
cmp    (%r15),%eax
je     12ac <htoi+0x13c>
mov    %eax,%ebp
lea    0xe40(%rip),%r14
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
cmp    $0x1d,%r12d
jne    11f0 <htoi+0x80>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1279 <htoi+0x109>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1080 <isalpha@plt>
test   %rax,%rax
jne    1208 <htoi+0x98>
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     124b <htoi+0xdb>
mov    %ebp,%edi
call   1090 <isupper@plt>
test   %rax,%rax
je     1222 <htoi+0xb2>
cmp    $0x47,%ebp
jl     1246 <htoi+0xd6>
lea    0xf1e(%rip),%rdi
jmp    123a <htoi+0xca>
mov    %ebp,%edi
call   1040 <islower@plt>
test   %rax,%rax
je     1263 <htoi+0xf3>
cmp    $0x67,%ebp
jl     1268 <htoi+0xf8>
lea    0xea2(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1273 <htoi+0x103>
add    $0xffffffc9,%ebp
jmp    1270 <htoi+0x100>
cmp    $0xa,%ebp
je     1279 <htoi+0x109>
lea    0xe23(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1279 <htoi+0x109>
add    $0xffffffd0,%ebp
jmp    1270 <htoi+0x100>
add    $0xffffffa9,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r13d
shl    $0x4,%ebx
add    %r13d,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r15),%eax
je     12ac <htoi+0x13c>
mov    %eax,%ebp
lea    0x1(%r12),%eax
cmp    $0x1d,%r12d
mov    %eax,%r12d
jb     11d0 <htoi+0x60>
jmp    12ac <htoi+0x13c>
lea    0xd8a(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [79 x i8] c"\0A 1.U have a bad input! \0A U should give a hexazecimal number (Example: 0x1A)!\0A\00"
@EOF = global i32 0
@.str.1 = [44 x i8] c"\0A 2.Your input is too long for my intelect!\00"
@.str.2 = [99 x i8] c"\0A 5.U have a bad input! \0A Hexazecimal numbers contain only digit and A,B,C,D,E,F (Example: 0x1A)!\0A\00"
@.str.3 = [99 x i8] c"\0A 3.U have a bad input! \0A Hexazecimal numbers contain only digit and A,B,C,D,E,F (Example: 0x1A)!\0A\00"
@.str.4 = [99 x i8] c"\0A 4.U have a bad input! \0A Hexazecimal numbers contain only digit and a,b,c,d,e,f (Example: 0x1a)!\0A\00"
define i32 @htoi() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (...) @getchar()
store i32 %5, i32* %4
%6 = icmp eq i32 %5, 48
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %4
%9 = icmp eq i32 %8, 88
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 120
br i1 %12, label %15, label %13
13: ; preds = %10, %0
%14 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %86
15: ; preds = %10, %7
br label %16
16: ; preds = %84, %15
%17 = call i32 (...) @getchar()
store i32 %17, i32* %4
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 30
br label %23
23: ; preds = %20, %16
%24 = phi i1 [ false, %16 ], [ %22, %20 ]
br i1 %24, label %25, label %85
25: ; preds = %23
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 30
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %84
32: ; preds = %25
%33 = load i32, i32* %4
%34 = call i64 @isalpha(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %46, label %36
36: ; preds = %32
%37 = load i32, i32* %4
%38 = call i64 @isdigit(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 10
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %45
45: ; preds = %43, %40
br label %83
46: ; preds = %36, %32
%47 = load i32, i32* %4
%48 = call i64 @isupper(i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i32, i32* %4
%52 = icmp sgt i32 %51, 70
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %59
55: ; preds = %50
%56 = load i32, i32* %4
%57 = sub nsw i32 %56, 65
%58 = add nsw i32 %57, 10
store i32 %58, i32* %2
br label %59
59: ; preds = %55, %53
br label %78
60: ; preds = %46
%61 = load i32, i32* %4
%62 = call i64 @islower(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %60
%65 = load i32, i32* %4
%66 = icmp sgt i32 %65, 102
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %73
69: ; preds = %64
%70 = load i32, i32* %4
%71 = sub nsw i32 %70, 97
%72 = add nsw i32 %71, 10
store i32 %72, i32* %2
br label %73
73: ; preds = %69, %67
br label %77
74: ; preds = %60
%75 = load i32, i32* %4
%76 = sub nsw i32 %75, 48
store i32 %76, i32* %2
br label %77
77: ; preds = %74, %73
br label %78
78: ; preds = %77, %59
%79 = load i32, i32* %1
%80 = mul nsw i32 16, %79
%81 = load i32, i32* %2
%82 = add nsw i32 %80, %81
store i32 %82, i32* %1
br label %83
83: ; preds = %78, %45
br label %84
84: ; preds = %83, %30
br label %16
85: ; preds = %23
br label %86
86: ; preds = %85, %13
%87 = load i32, i32* %1
ret i32 %87
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [44 x i8] c"\0A 2.Your input is too long for my intelect!\00"
@str = [78 x i8] c"\0A 1.U have a bad input! \0A U should give a hexazecimal number (Example: 0x1A)!\00"
@str.5 = [98 x i8] c"\0A 5.U have a bad input! \0A Hexazecimal numbers contain only digit and A,B,C,D,E,F (Example: 0x1A)!\00"
@str.6 = [98 x i8] c"\0A 4.U have a bad input! \0A Hexazecimal numbers contain only digit and a,b,c,d,e,f (Example: 0x1a)!\00"
@str.7 = [98 x i8] c"\0A 3.U have a bad input! \0A Hexazecimal numbers contain only digit and A,B,C,D,E,F (Example: 0x1A)!\00"
define i32 @htoi() {
%1 = tail call i32 (...) @getchar()
%2 = icmp eq i32 %1, 48
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = tail call i32 (...) @getchar()
%5 = and i32 %4, -33
%6 = icmp eq i32 %5, 88
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i32 (...) @getchar()
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %65, label %13
11: ; preds = %3, %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
br label %65
13: ; preds = %7, %57
%14 = phi i32 [ %60, %57 ], [ %8, %7 ]
%15 = phi i32 [ %18, %57 ], [ 0, %7 ]
%16 = phi i32 [ %59, %57 ], [ 0, %7 ]
%17 = phi i32 [ %58, %57 ], [ 0, %7 ]
%18 = add nuw nsw i32 %15, 1
%19 = icmp eq i32 %18, 30
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %57
22: ; preds = %13
%23 = tail call i64 @isalpha(i32 %14)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = tail call i64 @isdigit(i32 %14)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = icmp eq i32 %14, 10
br i1 %29, label %57, label %30
30: ; preds = %28
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str.5, i64 0, i64 0))
br label %57
32: ; preds = %25, %22
%33 = tail call i64 @isupper(i32 %14)
%34 = icmp eq i64 %33, 0
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = icmp sgt i32 %14, 70
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str.7, i64 0, i64 0))
br label %52
39: ; preds = %35
%40 = add nsw i32 %14, -55
br label %52
41: ; preds = %32
%42 = tail call i64 @islower(i32 %14)
%43 = icmp eq i64 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %41
%45 = icmp sgt i32 %14, 102
br i1 %45, label %46, label %48
46: ; preds = %44
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str.6, i64 0, i64 0))
br label %52
48: ; preds = %44
%49 = add nsw i32 %14, -87
br label %52
50: ; preds = %41
%51 = add nsw i32 %14, -48
br label %52
52: ; preds = %50, %48, %46, %37, %39
%53 = phi i32 [ -1, %37 ], [ %17, %39 ], [ -1, %46 ], [ %17, %48 ], [ %17, %50 ]
%54 = phi i32 [ %16, %37 ], [ %40, %39 ], [ %16, %46 ], [ %49, %48 ], [ %51, %50 ]
%55 = shl nsw i32 %53, 4
%56 = add nsw i32 %55, %54
br label %57
57: ; preds = %52, %30, %28, %20
%58 = phi i32 [ -1, %20 ], [ %56, %52 ], [ -1, %30 ], [ %17, %28 ]
%59 = phi i32 [ %16, %20 ], [ %54, %52 ], [ %16, %30 ], [ %16, %28 ]
%60 = tail call i32 (...) @getchar()
%61 = load i32, i32* @EOF
%62 = icmp ne i32 %60, %61
%63 = icmp ult i32 %15, 29
%64 = select i1 %62, i1 %63, i1 false
br i1 %64, label %13, label %65
65: ; preds = %57, %7, %11
%66 = phi i32 [ -1, %11 ], [ 0, %7 ], [ %58, %57 ]
ret i32 %66
}