#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 /*<<< orphan*/ copy(char *, char *);
int /*<<< orphan*/ del_prefix(char *, unsigned int);
unsigned int getline(char *, int);
unsigned int htoi(char *);
scalar_t__ is_valid_hex(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ upper(char *);
int main(void) {
  char hex[64];
  char hex_copy[64];
  unsigned int len;
  unsigned int dec;
  printf("> ");
  while ((len = getline(hex, 64)) > 0) {
    copy(hex, hex_copy);
    upper(hex_copy);
    del_prefix(hex_copy, len);
    if (is_valid_hex(hex_copy, strlen(hex_copy))) {
      dec = htoi(hex_copy);
      printf("%u\n", dec);
    } else
      puts("It's not a hexadecimal number");
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   10b0 <getline@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jbe    1277 <main+0xe7>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <copy@plt>
lea    -0x90(%rbp),%rdi
call   1090 <upper@plt>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1040 <del_prefix@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%esi
call   10a0 <is_valid_hex@plt>
cmp    $0x0,%rax
je     1258 <main+0xc8>
lea    -0x90(%rbp),%rdi
call   1080 <htoi@plt>
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1264 <main+0xd4>
lea    0xda8(%rip),%rdi
call   1030 <puts@plt>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11b0 <main+0x20>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rdi
mov    $0x40,%esi
call   10b0 <getline@plt>
test   %eax,%eax
je     125f <main+0xcf>
mov    %eax,%ebp
mov    %rsp,%r14
lea    0x40(%rsp),%rbx
lea    0xe32(%rip),%r15
lea    0xe24(%rip),%r12
lea    0xe20(%rip),%r13
jmp    1215 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x40,%esi
call   10b0 <getline@plt>
mov    %eax,%ebp
test   %eax,%eax
je     125f <main+0xcf>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <copy@plt>
mov    %rbx,%rdi
call   1090 <upper@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <del_prefix@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10a0 <is_valid_hex@plt>
test   %rax,%rax
je     11f0 <main+0x60>
mov    %rbx,%rdi
call   1080 <htoi@plt>
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f8 <main+0x68>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [30 x i8] c"It's not a hexadecimal number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %32, %0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = call i32 @getline(i8* %8, i32 64)
store i32 %9, i32* %4
%10 = icmp ugt i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%14 = call i32 @copy(i8* %12, i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%16 = call i32 @upper(i8* %15)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @del_prefix(i8* %17, i32 %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i64 @is_valid_hex(i8* %20, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %11
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%27 = call i32 @htoi(i8* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %32
30: ; preds = %11
%31 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %7
34: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [30 x i8] c"It's not a hexadecimal number\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @getline(i8* %3, i32 64)
%7 = icmp eq i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %0, %21
%9 = phi i32 [ %23, %21 ], [ %6, %0 ]
%10 = call i32 @copy(i8* %3, i8* %4)
%11 = call i32 @upper(i8* %4)
%12 = call i32 @del_prefix(i8* %4, i32 %9)
%13 = call i32 @strlen(i8* %4)
%14 = call i64 @is_valid_hex(i8* %4, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = call i32 @htoi(i8* %4)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %8
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @getline(i8* %3, i32 64)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %8
25: ; preds = %21, %0
ret i32 0
}