#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*/ __fpurge(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main() {
  int ndni = 0;
  char dni[10];
  char letras[] = "TRWAGMYFPDXBNJZSQVHLCKE";
  do {
    system("clear");
    printf("Vamos a calcular la letra de un DNI que me des por teclado.\n");
    printf("¿Que DNI quieres calcular?: ");
    scanf("%s", dni);
    __fpurge(stdin);
  } while (strlen(dni) < 7 || strlen(dni) > 9);
  ndni = atoi(dni);
  ndni = ndni % 23;
  printf("\nLa letra del DNI %s es %c.", dni, letras[ndni]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0xe83(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe7d(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe7a(%rip),%rdi
call   1050 <system@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x12(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1070 <scanf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1030 <__fpurge@plt>
lea    -0x12(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x7,%ecx
mov    %al,-0x31(%rbp)
jl     1208 <main+0xa8>
lea    -0x12(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1197 <main+0x37>
lea    -0x12(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x17,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
lea    -0x12(%rbp),%rsi
movslq -0x8(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe93(%rip),%r14
lea    0xecf(%rip),%r15
lea    0xe8b(%rip),%r12
lea    0xea2(%rip),%r13
lea    0xe(%rsp),%rbx
mov    0x2e42(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <system@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x0(%rbp),%edi
call   1040 <__fpurge@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x7,%eax
jl     11b0 <main+0x40>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x9,%eax
jg     11b0 <main+0x40>
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
cltq
imul   $0xffffffffb21642c9,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x4,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%edx
shl    $0x3,%edx
sub    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rax
lea    0xdcf(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe03(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.letras = [24 x i8] c"TRWAGMYFPDXBNJZSQVHLCKE\00"
@.str = [6 x i8] c"clear\00"
@.str.1 = [61 x i8] c"Vamos a calcular la letra de un DNI que me des por teclado.\0A\00"
@.str.2 = [30 x i8] c"\C2\BFQue DNI quieres calcular?: \00"
@.str.3 = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.4 = [28 x i8] c"\0ALa letra del DNI %s es %c.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca [24 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%5 = bitcast [24 x i8]* %4 to i8*
br label %6
6: ; preds = %22, %0
%7 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @stdin
%13 = call i32 @__fpurge(i32 %12)
br label %14
14: ; preds = %6
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %16, 7
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = icmp sgt i32 %20, 9
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ true, %14 ], [ %21, %18 ]
br i1 %23, label %6, label %24
24: ; preds = %22
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = srem i32 %27, 23
store i32 %28, i32* %2
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [24 x i8], [24 x i8]* %4, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %29, i32 %34)
ret i32 0
}

LLVM IR (-O2):
@__const.main.letras = [24 x i8] c"TRWAGMYFPDXBNJZSQVHLCKE\00"
@.str = [6 x i8] c"clear\00"
@.str.2 = [30 x i8] c"\C2\BFQue DNI quieres calcular?: \00"
@.str.3 = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.4 = [28 x i8] c"\0ALa letra del DNI %s es %c.\00"
@str = [60 x i8] c"Vamos a calcular la letra de un DNI que me des por teclado.\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %15, %0
%4 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = load i32, i32* @stdin
%9 = call i32 @__fpurge(i32 %8)
%10 = call i32 @strlen(i8* %2)
%11 = icmp slt i32 %10, 7
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = call i32 @strlen(i8* %2)
%14 = icmp sgt i32 %13, 9
br i1 %14, label %15, label %16
15: ; preds = %12, %3
br label %3
16: ; preds = %12
%17 = call i32 @atoi(i8* %2)
%18 = srem i32 %17, 23
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [24 x i8], [24 x i8]* @__const.main.letras, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 %22)
ret i32 0
}