#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 convHex(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *, char *, char *, char *);
int validos(char, char, char, char);
int main() {
  char car1;
  char car2;
  char car3;
  char car4;
  int valor1;
  int valor2;
  int valor3;
  int valor4;
  int valido;
  int resultado;
  int error = 0;
  while (!(car1 == 'q' && car2 == 'q' && car3 == 'q' && car4 == 'q')) {
    printf("Introduzca cuatro carácteres hexadecimales:");
    scanf("\n%c%c%c%c", &car1, &car2, &car3, &car4);
    valido = validos(car1, car2, car3, car4);
    valor1 = convHex(car1);
    if (valor1 == -1)
      error = 1;
    valor2 = convHex(car2);
    if (valor2 == -1)
      error = 1;
    valor3 = convHex(car3);
    if (valor3 == -1)
      error = 1;
    valor4 = convHex(car4);
    if (valor4 == -1)
      error = 1;
    if (error == 0) {
      resultado = 4096 * valor1 + 256 * valor2 + 16 * valor3 + valor4;
      printf("El valor decimal de 0x%c%c%c%c es %d\n", car1, car2, car3, car4,
             resultado);
    } else {
      printf("Uno de los 4 valores introducidos no es hexadecimal.\n");
      error = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0x25(%rbp)
jne    1199 <main+0x59>
movsbl -0x6(%rbp),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0x25(%rbp)
jne    1199 <main+0x59>
movsbl -0x7(%rbp),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0x25(%rbp)
jne    1199 <main+0x59>
movsbl -0x8(%rbp),%eax
cmp    $0x71,%eax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    11ab <main+0x6b>
jmp    12cf <main+0x18f>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6d(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x6(%rbp),%rdx
lea    -0x7(%rbp),%rcx
lea    -0x8(%rbp),%r8
call   1060 <scanf@plt>
mov    -0x5(%rbp),%dl
mov    -0x6(%rbp),%cl
mov    -0x7(%rbp),%al
movsbl %dl,%edi
movsbl %cl,%esi
movsbl %al,%edx
movsbl -0x8(%rbp),%ecx
call   1050 <validos@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <convHex@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1210 <main+0xd0>
movl   $0x1,-0x24(%rbp)
movsbl -0x6(%rbp),%edi
call   1040 <convHex@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    122d <main+0xed>
movl   $0x1,-0x24(%rbp)
movsbl -0x7(%rbp),%edi
call   1040 <convHex@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    124a <main+0x10a>
movl   $0x1,-0x24(%rbp)
movsbl -0x8(%rbp),%edi
call   1040 <convHex@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1267 <main+0x127>
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12b5 <main+0x175>
mov    -0xc(%rbp),%eax
shl    $0xc,%eax
mov    -0x10(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x14(%rbp),%ecx
shl    $0x4,%ecx
add    %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsbl -0x5(%rbp),%esi
movsbl -0x6(%rbp),%edx
movsbl -0x7(%rbp),%ecx
movsbl -0x8(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ca <main+0x18a>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x6(%rsp),%r13
lea    0x5(%rsp),%rbx
lea    0x4(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    0x7(%rsp),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   1070 <scanf@plt>
movsbl 0x7(%rsp),%edi
movsbl 0x6(%rsp),%esi
movsbl 0x5(%rsp),%edx
movsbl 0x4(%rsp),%ecx
call   1060 <validos@plt>
movsbl 0x7(%rsp),%edi
call   1050 <convHex@plt>
mov    %eax,%r15d
movsbl 0x6(%rsp),%edi
call   1050 <convHex@plt>
mov    %eax,%r12d
movsbl 0x5(%rsp),%edi
call   1050 <convHex@plt>
mov    %eax,%r14d
movsbl 0x4(%rsp),%edi
call   1050 <convHex@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0xf0>
cmp    $0xffffffff,%r14d
je     1240 <main+0xf0>
cmp    $0xffffffff,%r12d
je     1240 <main+0xf0>
cmp    $0xffffffff,%r15d
je     1240 <main+0xf0>
shl    $0xc,%r15d
shl    $0x8,%r12d
add    %r15d,%r12d
shl    $0x4,%r14d
add    %r12d,%r14d
add    %eax,%r14d
movsbl 0x7(%rsp),%esi
movsbl 0x6(%rsp),%edx
movsbl 0x5(%rsp),%ecx
movsbl 0x4(%rsp),%r8d
lea    0xe0d(%rip),%rdi
mov    %r14d,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0x71,0x7(%rsp)
je     1257 <main+0x107>
jmp    1170 <main+0x20>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x71,0x7(%rsp)
jne    1170 <main+0x20>
cmpb   $0x71,0x6(%rsp)
jne    1170 <main+0x20>
cmpb   $0x71,0x5(%rsp)
jne    1170 <main+0x20>
cmpb   $0x71,0x4(%rsp)
jne    1170 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [45 x i8] c"Introduzca cuatro car\C3\A1cteres 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 = [53 x i8] c"Uno de los 4 valores introducidos no es hexadecimal.\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
br label %5
5: ; preds = %0, %46
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 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 = load i8, i8* %2
%10 = load i8, i8* %3
%11 = load i8, i8* %4
%12 = call i32 @validos(i8 signext %8, i8 signext %9, i8 signext %10, i8 signext %11)
%13 = load i8, i8* %1
%14 = call i32 @convHex(i8 signext %13)
%15 = icmp ne i32 %14, -1
%16 = load i8, i8* %2
%17 = call i32 @convHex(i8 signext %16)
%18 = icmp ne i32 %17, -1
%19 = load i8, i8* %3
%20 = call i32 @convHex(i8 signext %19)
%21 = icmp ne i32 %20, -1
%22 = load i8, i8* %4
%23 = call i32 @convHex(i8 signext %22)
%24 = icmp ne i32 %23, -1
%25 = select i1 %24, i1 %21, i1 false
%26 = select i1 %25, i1 %18, i1 false
%27 = select i1 %26, i1 %15, i1 false
br i1 %27, label %28, label %44
28: ; preds = %5
%29 = shl nsw i32 %14, 12
%30 = shl nsw i32 %17, 8
%31 = add nsw i32 %30, %29
%32 = shl nsw i32 %20, 4
%33 = add nsw i32 %31, %32
%34 = add nsw i32 %33, %23
%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 %46
44: ; preds = %5
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %44, %28
%47 = load i8, i8* %1
%48 = icmp eq i8 %47, 113
%49 = load i8, i8* %2
%50 = icmp eq i8 %49, 113
%51 = select i1 %48, i1 %50, i1 false
%52 = load i8, i8* %3
%53 = icmp eq i8 %52, 113
%54 = select i1 %51, i1 %53, i1 false
%55 = load i8, i8* %4
%56 = icmp eq i8 %55, 113
%57 = select i1 %54, i1 %56, i1 false
br i1 %57, label %58, label %5
58: ; preds = %46
ret i32 0
}