#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 hexDec1(char, char);
int hexDec2(char, char);
int hexValidos(char, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *, char *, char *, char *);
int main() {
  char car1;
  char car2;
  char car3;
  char car4;
  int valor;
  int valorpar1;
  int valorpar2;
  int validedpar1;
  int validedpar2;
  do {
    printf("Introduzca cuatro caracteres hexadecimales:");
    scanf("\n%c%c%c%c", &car1, &car2, &car3, &car4);
    if (car1 != 'q' || car2 != 'q' || car3 != 'q' || car4 != 'q') {
      validedpar1 = hexValidos(car1, car2);
      validedpar2 = hexValidos(car3, car4);
      if (validedpar1 == 1 && validedpar2 == 1) {
        valorpar1 = hexDec2(car1, car2);
        valorpar2 = hexDec1(car3, car4);
        valor = valorpar1 + valorpar2;
        printf("El valor decimal de 0x%c%c%C%c es %d\n", car1, car2, car3, car4,
               valor);
      } else {
        if (validedpar1 == 0 || validedpar2 == 0) {
          printf("Invalido\n");
        }
      }
    }
  } while (car1 != 'q' || car2 != 'q' || car3 != 'q' || car4 != 'q');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x6(%rbp),%rdx
lea    -0x7(%rbp),%rcx
lea    -0x8(%rbp),%r8
call   1060 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
jne    11bd <main+0x6d>
movsbl -0x6(%rbp),%eax
cmp    $0x71,%eax
jne    11bd <main+0x6d>
movsbl -0x7(%rbp),%eax
cmp    $0x71,%eax
jne    11bd <main+0x6d>
movsbl -0x8(%rbp),%eax
cmp    $0x71,%eax
je     1276 <main+0x126>
mov    -0x5(%rbp),%al
movsbl %al,%edi
movsbl -0x6(%rbp),%esi
call   1030 <hexValidos@plt>
mov    %eax,-0x18(%rbp)
mov    -0x7(%rbp),%al
movsbl %al,%edi
movsbl -0x8(%rbp),%esi
call   1030 <hexValidos@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    124a <main+0xfa>
cmpl   $0x1,-0x1c(%rbp)
jne    124a <main+0xfa>
mov    -0x5(%rbp),%al
movsbl %al,%edi
movsbl -0x6(%rbp),%esi
call   1070 <hexDec2@plt>
mov    %eax,-0x10(%rbp)
mov    -0x7(%rbp),%al
movsbl %al,%edi
movsbl -0x8(%rbp),%esi
call   1050 <hexDec1@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
movsbl -0x5(%rbp),%esi
movsbl -0x6(%rbp),%edx
movsbl -0x7(%rbp),%ecx
movsbl -0x8(%rbp),%r8d
mov    -0xc(%rbp),%r9d
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1271 <main+0x121>
cmpl   $0x0,-0x18(%rbp)
je     125e <main+0x10e>
cmpl   $0x0,-0x1c(%rbp)
jne    126c <main+0x11c>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1271 <main+0x121>
jmp    1276 <main+0x126>
jmp    127b <main+0x12b>
movsbl -0x5(%rbp),%ecx
mov    $0x1,%al
cmp    $0x71,%ecx
mov    %al,-0x1d(%rbp)
jne    12be <main+0x16e>
movsbl -0x6(%rbp),%ecx
mov    $0x1,%al
cmp    $0x71,%ecx
mov    %al,-0x1d(%rbp)
jne    12be <main+0x16e>
movsbl -0x7(%rbp),%ecx
mov    $0x1,%al
cmp    $0x71,%ecx
mov    %al,-0x1d(%rbp)
jne    12be <main+0x16e>
movsbl -0x8(%rbp),%eax
cmp    $0x71,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115f <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    0xeba(%rip),%r12
lea    0x7(%rsp),%r15
lea    0x6(%rsp),%r14
lea    0x5(%rsp),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1070 <scanf@plt>
movzbl 0x7(%rsp),%eax
movzbl 0x6(%rsp),%ecx
cmp    $0x71,%al
jne    11d7 <main+0x77>
cmp    $0x71,%cl
jne    11d7 <main+0x77>
cmpb   $0x71,0x5(%rsp)
jne    11d7 <main+0x77>
cmpb   $0x71,0x4(%rsp)
je     1280 <main+0x120>
mov    %r14,%rbp
movsbl %al,%edi
movsbl %cl,%esi
call   1040 <hexValidos@plt>
mov    %eax,%r14d
movsbl 0x5(%rsp),%edi
movsbl 0x4(%rsp),%esi
call   1040 <hexValidos@plt>
cmp    $0x1,%r14d
jne    1260 <main+0x100>
cmp    $0x1,%eax
jne    1260 <main+0x100>
movsbl 0x7(%rsp),%edi
movsbl 0x6(%rsp),%esi
call   1080 <hexDec2@plt>
mov    %eax,%ebx
movsbl 0x5(%rsp),%edi
movsbl 0x4(%rsp),%esi
call   1060 <hexDec1@plt>
add    %eax,%ebx
movsbl 0x7(%rsp),%esi
movsbl 0x6(%rsp),%edx
movsbl 0x5(%rsp),%ecx
movsbl 0x4(%rsp),%r8d
lea    0xdf6(%rip),%rdi
mov    %ebx,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%r14
lea    0x4(%rsp),%rbp
jmp    1280 <main+0x120>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r14d,%r14d
mov    %rbp,%r14
lea    0x4(%rsp),%rbp
je     1271 <main+0x111>
test   %eax,%eax
jne    1280 <main+0x120>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
nopl   (%rax)
cmpb   $0x71,0x7(%rsp)
jne    1190 <main+0x30>
cmpb   $0x71,0x6(%rsp)
jne    1190 <main+0x30>
cmpb   $0x71,0x5(%rsp)
jne    1190 <main+0x30>
cmpb   $0x71,0x4(%rsp)
jne    1190 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Introduzca cuatro caracteres hexadecimales:\00"
@.str.1 = [10 x i8] c"\0A%c%c%c%c\00"
@.str.2 = [38 x i8] c"El valor decimal de 0x%c%c%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 i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
br label %11
11: ; preds = %88, %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3, i8* %4, i8* %5)
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 113
br i1 %16, label %29, label %17
17: ; preds = %11
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 113
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 113
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 113
br i1 %28, label %29, label %71
29: ; preds = %25, %21, %17, %11
%30 = load i8, i8* %2
%31 = load i8, i8* %3
%32 = call i32 @hexValidos(i8 signext %30, i8 signext %31)
store i32 %32, i32* %9
%33 = load i8, i8* %4
%34 = load i8, i8* %5
%35 = call i32 @hexValidos(i8 signext %33, i8 signext %34)
store i32 %35, i32* %10
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %61
38: ; preds = %29
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %61
41: ; preds = %38
%42 = load i8, i8* %2
%43 = load i8, i8* %3
%44 = call i32 @hexDec2(i8 signext %42, i8 signext %43)
store i32 %44, i32* %7
%45 = load i8, i8* %4
%46 = load i8, i8* %5
%47 = call i32 @hexDec1(i8 signext %45, i8 signext %46)
store i32 %47, i32* %8
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = add nsw i32 %48, %49
store i32 %50, i32* %6
%51 = load i8, i8* %2
%52 = sext i8 %51 to i32
%53 = load i8, i8* %3
%54 = sext i8 %53 to i32
%55 = load i8, i8* %4
%56 = sext i8 %55 to i32
%57 = load i8, i8* %5
%58 = sext i8 %57 to i32
%59 = load i32, i32* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %52, i32 %54, i32 %56, i32 %58, i32 %59)
br label %70
61: ; preds = %38, %29
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = load i32, i32* %10
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64, %61
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
br label %70
70: ; preds = %69, %41
br label %71
71: ; preds = %70, %25
br label %72
72: ; preds = %71
%73 = load i8, i8* %2
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 113
br i1 %75, label %88, label %76
76: ; preds = %72
%77 = load i8, i8* %3
%78 = sext i8 %77 to i32
%79 = icmp ne i32 %78, 113
br i1 %79, label %88, label %80
80: ; preds = %76
%81 = load i8, i8* %4
%82 = sext i8 %81 to i32
%83 = icmp ne i32 %82, 113
br i1 %83, label %88, label %84
84: ; preds = %80
%85 = load i8, i8* %5
%86 = sext i8 %85 to i32
%87 = icmp ne i32 %86, 113
br label %88
88: ; preds = %84, %80, %76, %72
%89 = phi i1 [ true, %80 ], [ true, %76 ], [ true, %72 ], [ %87, %84 ]
br i1 %89, label %11, label %90
90: ; preds = %88
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"Introduzca cuatro caracteres hexadecimales:\00"
@.str.1 = [10 x i8] c"\0A%c%c%c%c\00"
@.str.2 = [38 x i8] c"El valor decimal de 0x%c%c%C%c es %d\0A\00"
@str = [9 x i8] c"Invalido\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
br label %5
5: ; preds = %50, %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2, i8* %3, i8* %4)
%8 = load i8, i8* %1
%9 = icmp ne i8 %8, 113
%10 = load i8, i8* %2
%11 = icmp ne i8 %10, 113
%12 = select i1 %9, i1 true, i1 %11
%13 = load i8, i8* %3
%14 = icmp ne i8 %13, 113
%15 = select i1 %12, i1 true, i1 %14
%16 = load i8, i8* %4
%17 = icmp ne i8 %16, 113
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %50
19: ; preds = %5
%20 = call i32 @hexValidos(i8 signext %8, i8 signext %10)
%21 = load i8, i8* %3
%22 = load i8, i8* %4
%23 = call i32 @hexValidos(i8 signext %21, i8 signext %22)
%24 = icmp eq i32 %20, 1
%25 = icmp eq i32 %23, 1
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %44
27: ; preds = %19
%28 = load i8, i8* %1
%29 = load i8, i8* %2
%30 = call i32 @hexDec2(i8 signext %28, i8 signext %29)
%31 = load i8, i8* %3
%32 = load i8, i8* %4
%33 = call i32 @hexDec1(i8 signext %31, i8 signext %32)
%34 = add nsw i32 %33, %30
%35 = load i8, i8* %1
%36 = sext i8 %35 to i32
%37 = load i8, i8* %2
%38 = sext i8 %37 to i32
%39 = load i8, i8* %3
%40 = sext i8 %39 to i32
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %38, i32 %40, i32 %42, i32 %34)
br label %50
44: ; preds = %19
%45 = icmp eq i32 %20, 0
%46 = icmp eq i32 %23, 0
%47 = select i1 %45, i1 true, i1 %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %5, %48, %44, %27
%51 = load i8, i8* %1
%52 = icmp ne i8 %51, 113
%53 = load i8, i8* %2
%54 = icmp ne i8 %53, 113
%55 = select i1 %52, i1 true, i1 %54
%56 = load i8, i8* %3
%57 = icmp ne i8 %56, 113
%58 = select i1 %55, i1 true, i1 %57
%59 = load i8, i8* %4
%60 = icmp ne i8 %59, 113
%61 = select i1 %58, i1 true, i1 %60
br i1 %61, label %5, label %62
62: ; preds = %50
ret i32 0
}