#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int htoi(char s[]);
  int c, i, flag, flag1;
  char t[1000];
  i = 0;
  flag = 0;
  flag1 = 1;
  printf("input a HEX number:");
  while ((c = getchar()) != '\0' && i < 1000 && flag1) {
    if (c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') {
      flag = 1;
      t[i++] = c;
    } else if (flag) {
      t[i] = '\0';
      printf("decimal  number %d\n", htoi(t));
      printf("continue or not?");
      c = getchar();
      if (c == 'N' || c == 'n')
        flag1 = 0;
      else {
        flag = 0;
        i = 0;
        printf("\ninput a HEX number:");
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x401(%rbp)
je     11a4 <main+0x74>
xor    %eax,%eax
cmpl   $0x3e8,-0xc(%rbp)
mov    %al,-0x401(%rbp)
jge    11a4 <main+0x74>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x401(%rbp)
mov    -0x401(%rbp),%al
test   $0x1,%al
jne    11b7 <main+0x87>
jmp    12ad <main+0x17d>
cmpl   $0x30,-0x8(%rbp)
jl     11cb <main+0x9b>
cmpl   $0x39,-0x8(%rbp)
jle    11f3 <main+0xc3>
cmpl   $0x61,-0x8(%rbp)
jl     11df <main+0xaf>
cmpl   $0x66,-0x8(%rbp)
jle    11f3 <main+0xc3>
cmpl   $0x41,-0x8(%rbp)
jl     1218 <main+0xe8>
cmpl   $0x46,-0x8(%rbp)
jg     1218 <main+0xe8>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cltq
mov    %cl,-0x400(%rbp,%rax,1)
jmp    12a8 <main+0x178>
cmpl   $0x0,-0x10(%rbp)
je     12a3 <main+0x173>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
call   1050 <htoi@plt>
mov    %eax,%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x4e,-0x8(%rbp)
je     1276 <main+0x146>
cmpl   $0x6e,-0x8(%rbp)
jne    1282 <main+0x152>
movl   $0x0,-0x14(%rbp)
jmp    129e <main+0x16e>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a3 <main+0x173>
jmp    12a8 <main+0x178>
jmp    1165 <main+0x35>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
test   %eax,%eax
je     121c <main+0xec>
lea    0xe9b(%rip),%r15
lea    0xea8(%rip),%r13
movabs $0x3f0000003f,%rbx
xor    %r12d,%r12d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jb     1196 <main+0x66>
lea    -0x41(%rax),%ecx
cmp    $0x25,%ecx
ja     11c2 <main+0x92>
bt     %rcx,%rbx
jae    11c2 <main+0x92>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rsp,%rcx,1)
mov    $0x1,%r14b
mov    $0x1,%r12d
xor    %eax,%eax
call   1040 <getchar@plt>
test   %r14b,%r14b
je     121c <main+0xec>
test   %eax,%eax
je     121c <main+0xec>
cmp    $0x3e8,%ebp
jl     1180 <main+0x50>
jmp    121c <main+0xec>
test   %r12d,%r12d
je     1214 <main+0xe4>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1050 <htoi@plt>
xor    %r14d,%r14d
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
and    $0xffffffdf,%eax
mov    $0x1,%r12d
cmp    $0x4e,%eax
je     11a8 <main+0x78>
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebp,%ebp
xor    %r12d,%r12d
mov    $0x1,%r14b
jmp    11a8 <main+0x78>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"input a HEX number:\00"
@.str.1 = [20 x i8] c"decimal number %d\0A\00"
@.str.2 = [17 x i8] c"continue or not?\00"
@.str.3 = [21 x i8] c"\0Ainput a HEX number:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %66, %0
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %14, %11, %8
%18 = phi i1 [ false, %11 ], [ false, %8 ], [ %16, %14 ]
br i1 %18, label %19, label %67
19: ; preds = %17
%20 = load i32, i32* %2
%21 = icmp sge i32 %20, 48
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %2
%24 = icmp sle i32 %23, 57
br i1 %24, label %37, label %25
25: ; preds = %22, %19
%26 = load i32, i32* %2
%27 = icmp sge i32 %26, 97
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %2
%30 = icmp sle i32 %29, 102
br i1 %30, label %37, label %31
31: ; preds = %28, %25
%32 = load i32, i32* %2
%33 = icmp sge i32 %32, 65
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i32, i32* %2
%36 = icmp sle i32 %35, 70
br i1 %36, label %37, label %44
37: ; preds = %34, %28, %22
store i32 1, i32* %4
%38 = load i32, i32* %2
%39 = trunc i32 %38 to i8
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 %42
store i8 %39, i8* %43
br label %66
44: ; preds = %34, %31
%45 = load i32, i32* %4
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %65
47: ; preds = %44
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 %49
store i8 0, i8* %50
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%52 = call i32 @htoi(i8* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%55 = call i32 (...) @getchar()
store i32 %55, i32* %2
%56 = load i32, i32* %2
%57 = icmp eq i32 %56, 78
br i1 %57, label %61, label %58
58: ; preds = %47
%59 = load i32, i32* %2
%60 = icmp eq i32 %59, 110
br i1 %60, label %61, label %62
61: ; preds = %58, %47
store i32 0, i32* %5
br label %64
62: ; preds = %58
store i32 0, i32* %4
store i32 0, i32* %3
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %62, %61
br label %65
65: ; preds = %64, %44
br label %66
66: ; preds = %65, %37
br label %8
67: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"input a HEX number:\00"
@.str.1 = [20 x i8] c"decimal number %d\0A\00"
@.str.2 = [17 x i8] c"continue or not?\00"
@.str.3 = [21 x i8] c"\0Ainput a HEX number:\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (...) @getchar()
%5 = icmp eq i32 %4, 0
br i1 %5, label %40, label %6
6: ; preds = %0, %31
%7 = phi i32 [ %35, %31 ], [ %4, %0 ]
%8 = phi i32 [ %33, %31 ], [ 0, %0 ]
%9 = phi i32 [ %32, %31 ], [ 0, %0 ]
%10 = add i32 %7, -48
%11 = icmp ult i32 %10, 10
br i1 %11, label %13, label %12
12: ; preds = %6
switch i32 %7, label %18 [
i32 102, label %13
i32 101, label %13
i32 100, label %13
i32 99, label %13
i32 98, label %13
i32 97, label %13
i32 70, label %13
i32 69, label %13
i32 68, label %13
i32 67, label %13
i32 66, label %13
i32 65, label %13
]
13: ; preds = %12, %12, %12, %12, %12, %12, %12, %12, %12, %12, %12, %12, %6
%14 = trunc i32 %7 to i8
%15 = add nsw i32 %9, 1
%16 = sext i32 %9 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %16
store i8 %14, i8* %17
br label %31
18: ; preds = %12
%19 = icmp eq i32 %8, 0
br i1 %19, label %31, label %20
20: ; preds = %18
%21 = sext i32 %9 to i64
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @htoi(i8* %2)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (...) @getchar()
%27 = and i32 %26, -33
%28 = icmp eq i32 %27, 78
br i1 %28, label %31, label %29
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %20, %18, %29, %13
%32 = phi i32 [ %15, %13 ], [ 0, %29 ], [ %9, %18 ], [ %9, %20 ]
%33 = phi i32 [ 1, %13 ], [ 0, %29 ], [ 0, %18 ], [ 1, %20 ]
%34 = phi i1 [ true, %13 ], [ true, %29 ], [ true, %18 ], [ false, %20 ]
%35 = call i32 (...) @getchar()
%36 = icmp ne i32 %35, 0
%37 = icmp slt i32 %32, 1000
%38 = select i1 %36, i1 %37, i1 false
%39 = and i1 %34, %38
br i1 %39, label %6, label %40
40: ; preds = %31, %0
ret i32 0
}