#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 */
scalar_t__ calloc(int, scalar_t__);
int /*<<< orphan*/ decrypt(char const *, char *, char *);
int /*<<< orphan*/ encrypt(char const *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ normalizar(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
scalar_t__ strlen(char const *);
scalar_t__ validar_clave(char const *);
int main(int argc, char const *argv[]) {
  const char *clave;
  const char *palabra;
  char *out, *out2;
  if (argc != 3) {
    printf("%s <clave> <palabra a cifrar>\n", argv[0]);
    return 1;
  }
  clave = argv[1];
  palabra = argv[2];
  out = (char *)calloc(1, strlen(palabra) + 1);
  out2 = (char *)calloc(1, strlen(palabra) + 1);
  normalizar(palabra, out2);
  if (validar_clave(clave)) {
    printf("clave: '%s' no valida\n", clave);
    return 1;
  }
  printf("Se usara la clave '%s'\n", clave);
  encrypt(clave, out2, out);
  printf("Se encripto palabra '%s' -> '%s'\n", out2, out);
  decrypt(clave, out, out2);
  printf("Se encripto palabra '%s' -> '%s'\n", out, out2);
  free(out);
  free(out2);
  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)
cmpl   $0x3,-0x8(%rbp)
je     11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <normalizar@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <validar_clave@plt>
cmp    $0x0,%rax
je     1253 <main+0xd3>
mov    -0x18(%rbp),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x14c>
mov    -0x18(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <encrypt@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <decrypt@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x3,%edi
jne    11fb <main+0x7b>
mov    0x8(%rsi),%r12
mov    0x10(%rsi),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    $0x1,%r15d
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1090 <normalizar@plt>
mov    %r12,%rdi
call   10a0 <validar_clave@plt>
test   %rax,%rax
je     1214 <main+0x94>
lea    0xe33(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    127b <main+0xfb>
mov    (%rsi),%rsi
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r15d
jmp    127b <main+0xfb>
lea    0xe1b(%rip),%rdi
xor    %r15d,%r15d
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1070 <encrypt@plt>
lea    0xe11(%rip),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1030 <decrypt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"%s <clave> <palabra a cifrar>\0A\00"
@.str.1 = [23 x i8] c"clave: '%s' no valida\0A\00"
@.str.2 = [24 x i8] c"Se usara la clave '%s'\0A\00"
@.str.3 = [34 x i8] c"Se encripto palabra '%s' -> '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %64
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = call i64 @strlen(i8* %24)
%26 = add nsw i64 %25, 1
%27 = call i64 @calloc(i32 1, i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %8
%29 = load i8*, i8** %7
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = call i64 @calloc(i32 1, i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %9
%34 = load i8*, i8** %7
%35 = load i8*, i8** %9
%36 = call i32 @normalizar(i8* %34, i8* %35)
%37 = load i8*, i8** %6
%38 = call i64 @validar_clave(i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %17
%41 = load i8*, i8** %6
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %41)
store i32 1, i32* %3
br label %64
43: ; preds = %17
%44 = load i8*, i8** %6
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %6
%47 = load i8*, i8** %9
%48 = load i8*, i8** %8
%49 = call i32 @encrypt(i8* %46, i8* %47, i8* %48)
%50 = load i8*, i8** %9
%51 = load i8*, i8** %8
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %51)
%53 = load i8*, i8** %6
%54 = load i8*, i8** %8
%55 = load i8*, i8** %9
%56 = call i32 @decrypt(i8* %53, i8* %54, i8* %55)
%57 = load i8*, i8** %8
%58 = load i8*, i8** %9
%59 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %57, i8* %58)
%60 = load i8*, i8** %8
%61 = call i32 @free(i8* %60)
%62 = load i8*, i8** %9
%63 = call i32 @free(i8* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %43, %40, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [31 x i8] c"%s <clave> <palabra a cifrar>\0A\00"
@.str.1 = [23 x i8] c"clave: '%s' no valida\0A\00"
@.str.2 = [24 x i8] c"Se usara la clave '%s'\0A\00"
@.str.3 = [34 x i8] c"Se encripto palabra '%s' -> '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
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 ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %33
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = add nsw i64 %12, 1
%14 = tail call i64 @calloc(i32 1, i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%17 = add nsw i64 %16, 1
%18 = tail call i64 @calloc(i32 1, i64 %17)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i32 @normalizar(i8* %11, i8* %19)
%21 = tail call i64 @validar_clave(i8* %9)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %7
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %33
25: ; preds = %7
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%27 = tail call i32 @encrypt(i8* %9, i8* %19, i8* %15)
%28 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %15)
%29 = tail call i32 @decrypt(i8* %9, i8* %15, i8* %19)
%30 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %19)
%31 = tail call i32 @free(i8* %15)
%32 = tail call i32 @free(i8* %19)
br label %33
33: ; preds = %25, %23, %4
%34 = phi i32 [ 1, %4 ], [ 1, %23 ], [ 0, %25 ]
ret i32 %34
}