#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 atoi(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int dni;
  char letra[] = "TRWAGMYFPDXBNJZSQVHLCKE";
  if (argc != 2) {
    printf("Uso: %s <DNI>\n", argv[0]);
  } else {
    if (strlen(argv[1]) != 8) {
      puts("DNI no valido.");
    } else {
      dni = atoi(argv[1]);
      dni %= 23;
      printf("%s-%c\n", argv[1], letra[dni]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119b <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1204 <main+0xc4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
je     11c2 <main+0x82>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
jmp    11ff <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x17,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
movslq -0x14(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%edx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1204 <main+0xc4>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11a7 <main+0x67>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jne    11ba <main+0x7a>
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1060 <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    0xe70(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe9b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c6 <main+0x86>
mov    (%rbx),%rsi
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c6 <main+0x86>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.letra = [24 x i8] c"TRWAGMYFPDXBNJZSQVHLCKE\00"
@.str = [15 x i8] c"Uso: %s <DNI>\0A\00"
@.str.1 = [15 x i8] c"DNI no valido.\00"
@.str.2 = [7 x i8] c"%s-%c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [24 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [24 x i8]* %7 to i8*
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %41
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = icmp ne i32 %20, 8
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %40
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = srem i32 %29, 23
store i32 %30, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %38)
br label %40
40: ; preds = %24, %22
br label %41
41: ; preds = %40, %11
ret i32 0
}

LLVM IR (-O2):
@__const.main.letra = [24 x i8] c"TRWAGMYFPDXBNJZSQVHLCKE\00"
@.str = [15 x i8] c"Uso: %s <DNI>\0A\00"
@.str.1 = [15 x i8] c"DNI no valido.\00"
@.str.2 = [7 x i8] c"%s-%c\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %23
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = icmp eq i32 %10, 8
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
14: ; preds = %7
%15 = load i8*, i8** %8
%16 = tail call i32 @atoi(i8* %15)
%17 = srem i32 %16, 23
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [24 x i8], [24 x i8]* @__const.main.letra, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %21)
br label %23
23: ; preds = %12, %14, %4
ret i32 0
}