#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int strlen(char *);
int main(void) {
  FILE *f, *g;
  char abc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  char mensaje[10000];
  int longitud;
  int clave;
  int codif;
  int i, j;
  int longclave;
  printf("Este programa codifica un mensaje con el cifrado del Cesar. \n");
  printf("Introduce el mensaje: \n");
  gets(mensaje);
  printf("Introduce clave de codificacion k: ");
  scanf("%d", &clave);
  longitud = strlen(mensaje);
  longclave = strlen(abc);
  f = fopen("info.txt", "w");
  g = fopen("cod_cesar.txt", "w");
  fprintf(
      f, "Texto plano: \n%s \n\nClave k = %d \n\nNumero de caracteres: %d \n\n",
      mensaje, clave, longitud);
  for (i = 0; i < longitud; i++) {
    codif = 0;
    j = 0;
    while (codif == 0) {
      if (mensaje[i] == abc[j]) {
        mensaje[i] = abc[(j + clave) % longclave];
        codif = 1;
      } else
        j++;
    }
  }
  fprintf(f, "Mensaje codificado: \n%s \n\nLongitud: %d", mensaje,
          strlen(mensaje));
  fprintf(g, "%s", mensaje);
  printf("Mensaje codificado, pulsa intro");
  getchar();
  getchar();
  fclose(g);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2780,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe61(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe5e(%rip),%ax
mov    %ax,-0x28(%rbp)
mov    0xe56(%rip),%al
mov    %al,-0x26(%rbp)
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
lea    -0x2750(%rbp),%rdi
call   1080 <gets@plt>
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
lea    0xf12(%rip),%rdi
lea    -0x2758(%rbp),%rsi
call   1090 <scanf@plt>
lea    -0x2750(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2754(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2768(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2750(%rbp),%rdx
mov    -0x2758(%rbp),%ecx
mov    -0x2754(%rbp),%r8d
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x2760(%rbp)
mov    -0x2760(%rbp),%eax
cmp    -0x2754(%rbp),%eax
jge    1343 <main+0x1c3>
movl   $0x0,-0x275c(%rbp)
movl   $0x0,-0x2764(%rbp)
cmpl   $0x0,-0x275c(%rbp)
jne    132a <main+0x1aa>
movslq -0x2760(%rbp),%rax
movsbl -0x2750(%rbp,%rax,1),%eax
ff
movslq -0x2764(%rbp),%rcx
movsbl -0x40(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1316 <main+0x196>
mov    -0x2764(%rbp),%eax
add    -0x2758(%rbp),%eax
cltd
idivl  -0x2768(%rbp)
movslq %edx,%rax
mov    -0x40(%rbp,%rax,1),%cl
movslq -0x2760(%rbp),%rax
mov    %cl,-0x2750(%rbp,%rax,1)
movl   $0x1,-0x275c(%rbp)
jmp    1325 <main+0x1a5>
mov    -0x2764(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2764(%rbp)
jmp    12af <main+0x12f>
jmp    132f <main+0x1af>
mov    -0x2760(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2760(%rbp)
jmp    1289 <main+0x109>
mov    -0x10(%rbp),%rax
mov    %rax,-0x2778(%rbp)
lea    -0x2750(%rbp),%rax
mov    %rax,-0x2770(%rbp)
lea    -0x2750(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2778(%rbp),%rdi
mov    -0x2770(%rbp),%rdx
mov    %eax,%ecx
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x2750(%rbp),%rdx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xd70(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x2780,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2748,%rsp
movups 0xe53(%rip),%xmm0
movups %xmm0,0x1b(%rsp)
movaps 0xe3c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf3e(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <gets@plt>
lea    0xe26(%rip),%rdi
call   1060 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0xe12(%rip),%rdi
lea    0xe14(%rip),%r14
mov    %r14,%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbp
lea    0xe04(%rip),%rdi
mov    %r14,%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    0x4(%rsp),%ecx
lea    0xdfc(%rip),%rsi
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r13d,%r8d
xor    %eax,%eax
call   1090 <fprintf@plt>
test   %r13d,%r13d
jle    12c6 <main+0x126>
mov    0x4(%rsp),%ecx
mov    %r13d,%esi
add    $0xffffffff,%ecx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x30(%rsp,%rdi,1),%dl
mov    %r12,%rbx
mov    %ecx,%eax
nopl   0x0(%rax)
add    $0x1,%eax
lea    0x1(%rbx),%rbp
cmp    (%rbx),%dl
mov    %rbp,%rbx
jne    12a0 <main+0x100>
cltd
idiv   %r15d
movslq %edx,%rax
mov    0x10(%rsp,%rax,1),%al
mov    %al,0x30(%rsp,%rdi,1)
add    $0x1,%rdi
cmp    %rsi,%rdi
jne    1290 <main+0xf0>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xdbc(%rip),%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fputs@plt>
lea    0xdbd(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2748,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.abc = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str = [62 x i8] c"Este programa codifica un mensaje con el cifrado del Cesar. \0A\00"
@.str.1 = [24 x i8] c"Introduce el mensaje: \0A\00"
@.str.2 = [36 x i8] c"Introduce clave de codificacion k: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [9 x i8] c"info.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [14 x i8] c"cod_cesar.txt\00"
@.str.7 = [62 x i8] c"Texto plano: \0A%s \0A\0AClave k = %d \0A\0ANumero de caracteres: %d \0A\0A\00"
@.str.8 = [39 x i8] c"Mensaje codificado: \0A%s \0A\0ALongitud: %d\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [32 x i8] c"Mensaje codificado, pulsa intro\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [27 x i8]
%5 = alloca [10000 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = bitcast [27 x i8]* %4 to i8*
%13 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%16 = call i32 @gets(i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%19 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
%21 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %11
%23 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %23, i32** %2
%24 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %24, i32** %3
%25 = load i32*, i32** %2
%26 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.7, i64 0, i64 0), i8* %26, i32 %27, i32 %28)
store i32 0, i32* %9
br label %30
30: ; preds = %67, %0
%31 = load i32, i32* %9
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %70
34: ; preds = %30
store i32 0, i32* %8
store i32 0, i32* %10
br label %35
35: ; preds = %65, %34
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %66
38: ; preds = %35
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %43, %48
br i1 %49, label %50, label %62
50: ; preds = %38
%51 = load i32, i32* %10
%52 = load i32, i32* %7
%53 = add nsw i32 %51, %52
%54 = load i32, i32* %11
%55 = srem i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %60
store i8 %58, i8* %61
store i32 1, i32* %8
br label %65
62: ; preds = %38
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %65
65: ; preds = %62, %50
br label %35
66: ; preds = %35
br label %67
67: ; preds = %66
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %30
70: ; preds = %30
%71 = load i32*, i32** %2
%72 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%73 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%74 = call i32 @strlen(i8* %73)
%75 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %72, i32 %74)
%76 = load i32*, i32** %3
%77 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%78 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %77)
%79 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
%80 = call i32 (...) @getchar()
%81 = call i32 (...) @getchar()
%82 = load i32*, i32** %3
%83 = call i32 @fclose(i32* %82)
%84 = load i32*, i32** %2
%85 = call i32 @fclose(i32* %84)
ret i32 0
}

LLVM IR (-O2):
@__const.main.abc = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.2 = [36 x i8] c"Introduce clave de codificacion k: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [9 x i8] c"info.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [14 x i8] c"cod_cesar.txt\00"
@.str.7 = [62 x i8] c"Texto plano: \0A%s \0A\0AClave k = %d \0A\0ANumero de caracteres: %d \0A\0A\00"
@.str.8 = [39 x i8] c"Mensaje codificado: \0A%s \0A\0ALongitud: %d\00"
@.str.10 = [32 x i8] c"Mensaje codificado, pulsa intro\00"
@str = [61 x i8] c"Este programa codifica un mensaje con el cifrado del Cesar. \00"
@str.11 = [23 x i8] c"Introduce el mensaje: \00"
define i32 @main() {
%1 = alloca [27 x i8]
%2 = alloca [10000 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
%9 = call i32 @gets(i8* %5)
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%12 = call i32 @strlen(i8* %5)
%13 = call i32 @strlen(i8* %4)
%14 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.7, i64 0, i64 0), i8* %5, i32 %16, i32 %12)
%18 = icmp sgt i32 %12, 0
br i1 %18, label %19, label %41
19: ; preds = %0
%20 = load i32, i32* %3
%21 = zext i32 %12 to i64
br label %22
22: ; preds = %19, %33
%23 = phi i64 [ 0, %19 ], [ %39, %33 ]
%24 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
br label %26
26: ; preds = %26, %22
%27 = phi i32 [ 0, %22 ], [ %32, %26 ]
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %25, %30
%32 = add nuw nsw i32 %27, 1
br i1 %31, label %33, label %26
33: ; preds = %26
%34 = add nsw i32 %20, %27
%35 = srem i32 %34, %13
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %24
%39 = add nuw nsw i64 %23, 1
%40 = icmp eq i64 %39, %21
br i1 %40, label %41, label %22
41: ; preds = %33, %0
%42 = call i32 @strlen(i8* %5)
%43 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %5, i32 %42)
%44 = call i32 @fputs(i8* %5, i32* %15)
%45 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
%46 = call i32 (...) @getchar()
%47 = call i32 (...) @getchar()
%48 = call i32 @fclose(i32* %15)
%49 = call i32 @fclose(i32* %14)
ret i32 0
}