#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 hexDec(char, char);
int hexValidos(char, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *, char *);
int main() {
  char car1;
  char car2;
  int valor;
  int valided;
  do {
    printf("Introduzca el numero hexadecimal: ");
    scanf("\n%c%c", &car1, &car2);
    if (car1 != 'q' || car2 != 'q') {
      valided = hexValidos(car1, car2);
      if (valided == 1) {
        valor = hexDec(car1, car2);
        printf("El valor decimal de 0x%c%c es %d\n", car1, car2, valor);
      } else {
        if (valided == 0) {
          printf("Invalido\n");
        }
      }
    }
  } while (car1 != 'q' || car2 != 'q');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x6(%rbp),%rdx
call   1060 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
jne    118b <main+0x4b>
movsbl -0x6(%rbp),%eax
cmp    $0x71,%eax
je     11f9 <main+0xb9>
mov    -0x5(%rbp),%al
movsbl %al,%edi
movsbl -0x6(%rbp),%esi
call   1040 <hexValidos@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11d7 <main+0x97>
mov    -0x5(%rbp),%al
movsbl %al,%edi
movsbl -0x6(%rbp),%esi
call   1030 <hexDec@plt>
mov    %eax,-0xc(%rbp)
movsbl -0x5(%rbp),%esi
movsbl -0x6(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f4 <main+0xb4>
cmpl   $0x0,-0x10(%rbp)
jne    11ef <main+0xaf>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f4 <main+0xb4>
jmp    11f9 <main+0xb9>
jmp    11fe <main+0xbe>
movsbl -0x5(%rbp),%ecx
mov    $0x1,%al
cmp    $0x71,%ecx
mov    %al,-0x11(%rbp)
jne    121d <main+0xdd>
movsbl -0x6(%rbp),%eax
cmp    $0x71,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    114f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%r14
lea    0xeba(%rip),%r15
lea    0x7(%rsp),%r12
lea    0x6(%rsp),%rbx
lea    0xed1(%rip),%r13
lea    0xea8(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <scanf@plt>
movzbl 0x7(%rsp),%eax
movzbl 0x6(%rsp),%ecx
cmp    $0x71,%al
jne    11bb <main+0x6b>
cmp    $0x71,%cl
je     1200 <main+0xb0>
movsbl %al,%edi
movsbl %cl,%esi
call   1050 <hexValidos@plt>
test   %eax,%eax
je     1210 <main+0xc0>
cmp    $0x1,%eax
jne    1200 <main+0xb0>
movsbl 0x7(%rsp),%edi
movsbl 0x6(%rsp),%esi
call   1040 <hexDec@plt>
movsbl 0x7(%rsp),%esi
movsbl 0x6(%rsp),%edx
mov    %rbp,%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x71,0x7(%rsp)
jne    1190 <main+0x40>
cmpb   $0x71,0x6(%rsp)
jne    1190 <main+0x40>
jmp    1224 <main+0xd4>
mov    %r13,%rdi
call   1030 <puts@plt>
cmpb   $0x71,0x7(%rsp)
je     1207 <main+0xb7>
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Introduzca el numero hexadecimal: \00"
@.str.1 = [6 x i8] c"\0A%c%c\00"
@.str.2 = [34 x i8] c"El valor decimal de 0x%c%c es %d\0A\00"
@.str.3 = [10 x i8] c"Invalido\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %48, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 113
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 113
br i1 %15, label %16, label %39
16: ; preds = %12, %6
%17 = load i8, i8* %2
%18 = load i8, i8* %3
%19 = call i32 @hexValidos(i8 signext %17, i8 signext %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = load i8, i8* %2
%24 = load i8, i8* %3
%25 = call i32 @hexDec(i8 signext %23, i8 signext %24)
store i32 %25, i32* %4
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = load i32, i32* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %29, i32 %30)
br label %38
32: ; preds = %16
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38, %12
br label %40
40: ; preds = %39
%41 = load i8, i8* %2
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 113
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 113
br label %48
48: ; preds = %44, %40
%49 = phi i1 [ true, %40 ], [ %47, %44 ]
br i1 %49, label %6, label %50
50: ; preds = %48
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Introduzca el numero hexadecimal: \00"
@.str.1 = [6 x i8] c"\0A%c%c\00"
@.str.2 = [34 x i8] c"El valor decimal de 0x%c%c es %d\0A\00"
@str = [9 x i8] c"Invalido\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
br label %3
3: ; preds = %24, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
%6 = load i8, i8* %1
%7 = icmp ne i8 %6, 113
%8 = load i8, i8* %2
%9 = icmp ne i8 %8, 113
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = call i32 @hexValidos(i8 signext %6, i8 signext %8)
switch i32 %12, label %24 [
i32 1, label %13
i32 0, label %22
]
13: ; preds = %11
%14 = load i8, i8* %1
%15 = load i8, i8* %2
%16 = call i32 @hexDec(i8 signext %14, i8 signext %15)
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %20, i32 %16)
br label %24
22: ; preds = %11
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %11, %3, %22, %13
%25 = load i8, i8* %1
%26 = icmp ne i8 %25, 113
%27 = load i8, i8* %2
%28 = icmp ne i8 %27, 113
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %3, label %30
30: ; preds = %24
ret i32 0
}