#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 decrypt(char, int);
int encrypt(char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int key, i, m;
  char text[2048];
  while (1) {
    printf("> Decrypt(0), Encrypt(1), Exit(*): ");
    scanf("%d", &m);
    if (m < 0 || 1 < m)
      break;
    printf("> %stext: ", m ? "Plain" : "Cipher");
    scanf(" %[^\n]s", text);
    printf("\n");
    for (key = 0; key < 26; key++, printf("\n")) {
      printf("%2d - ", key);
      for (i = 0; text[i]; i++)
        printf("%c", m ? encrypt(text[i], key) : decrypt(text[i], key));
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jl     118a <main+0x4a>
mov    $0x1,%eax
cmp    -0x10(%rbp),%eax
jge    118f <main+0x4f>
jmp    12b0 <main+0x170>
mov    -0x10(%rbp),%ecx
lea    0xe9f(%rip),%rsi
lea    0xe92(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x810(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1a,-0x8(%rbp)
jge    129d <main+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmpb   $0x0,-0x810(%rbp,%rax,1)
je     127c <main+0x13c>
cmpl   $0x0,-0x10(%rbp)
je     123e <main+0xfe>
movslq -0xc(%rbp),%rax
mov    -0x810(%rbp,%rax,1),%al
mov    -0x8(%rbp),%esi
movsbl %al,%edi
call   1050 <encrypt@plt>
mov    %eax,-0x814(%rbp)
jmp    125a <main+0x11a>
movslq -0xc(%rbp),%rax
mov    -0x810(%rbp,%rax,1),%al
mov    -0x8(%rbp),%esi
movsbl %al,%edi
call   1030 <decrypt@plt>
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1201 <main+0xc1>
jmp    1281 <main+0x141>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11df <main+0x9f>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1152 <main+0x12>
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
jbe    119f <main+0x4f>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x11(%rsp),%r13
lea    0xe9c(%rip),%rbx
lea    0xe72(%rip),%rbp
lea    0xc(%rsp),%r14
jmp    11ee <main+0x9e>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jae    118b <main+0x3b>
test   %eax,%eax
lea    0xe3b(%rip),%rsi
lea    0xe3a(%rip),%rax
cmove  %rax,%rsi
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %r15d,%r15d
jmp    1258 <main+0x108>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15d
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    $0x1a,%r15d
je     11c0 <main+0x70>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%al
test   %al,%al
je     1240 <main+0xf0>
mov    %r13,%r12
jmp    129f <main+0x14f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
mov    %r15d,%esi
call   1030 <decrypt@plt>
mov    %eax,%edi
call   1040 <putchar@plt>
movzbl (%r12),%eax
add    $0x1,%r12
test   %al,%al
je     1240 <main+0xf0>
cmpl   $0x0,0xc(%rsp)
je     1280 <main+0x130>
movsbl %al,%edi
mov    %r15d,%esi
call   1060 <encrypt@plt>
jmp    128b <main+0x13b>

LLVM IR (-O0):
@.str = [36 x i8] c"> Decrypt(0), Encrypt(1), Exit(*): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"> %stext: \00"
@.str.3 = [6 x i8] c"Plain\00"
@.str.4 = [7 x i8] c"Cipher\00"
@.str.5 = [8 x i8] c" %[^\0A]s\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [7 x i8] c"%2d - \00"
@.str.8 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2048 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %0, %64
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = load i32, i32* %4
%13 = icmp slt i32 1, %12
br i1 %13, label %14, label %15
14: ; preds = %11, %6
br label %66
15: ; preds = %11
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %24
24: ; preds = %60, %15
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 26
br i1 %26, label %27, label %64
27: ; preds = %24
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %56, %27
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %59
36: ; preds = %30
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = load i32, i32* %2
%45 = call i32 @encrypt(i8 signext %43, i32 %44)
br label %53
46: ; preds = %36
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = load i32, i32* %2
%52 = call i32 @decrypt(i8 signext %50, i32 %51)
br label %53
53: ; preds = %46, %39
%54 = phi i32 [ %45, %39 ], [ %52, %46 ]
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %30
59: ; preds = %30
br label %60
60: ; preds = %59
%61 = load i32, i32* %2
%62 = add nsw i32 %61, 1
store i32 %62, i32* %2
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %24
64: ; preds = %24
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %6
66: ; preds = %14
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str = [36 x i8] c"> Decrypt(0), Encrypt(1), Exit(*): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"> %stext: \00"
@.str.3 = [6 x i8] c"Plain\00"
@.str.4 = [7 x i8] c"Cipher\00"
@.str.5 = [8 x i8] c" %[^\0A]s\00"
@.str.7 = [7 x i8] c"%2d - \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp ugt i32 %7, 1
br i1 %8, label %47, label %9
9: ; preds = %0, %41
%10 = phi i32 [ %45, %41 ], [ %7, %0 ]
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%15 = call i32 @putchar(i32 10)
br label %16
16: ; preds = %9, %37
%17 = phi i32 [ 0, %9 ], [ %38, %37 ]
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %17)
%19 = load i8, i8* %4
%20 = icmp eq i8 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %16, %30
%22 = phi i64 [ %33, %30 ], [ 0, %16 ]
%23 = phi i8 [ %35, %30 ], [ %19, %16 ]
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @encrypt(i8 signext %23, i32 %17)
br label %30
28: ; preds = %21
%29 = call i32 @decrypt(i8 signext %23, i32 %17)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
%32 = call i32 @putchar(i32 %31)
%33 = add nuw i64 %22, 1
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %21
37: ; preds = %30, %16
%38 = add nuw nsw i32 %17, 1
%39 = call i32 @putchar(i32 10)
%40 = icmp eq i32 %38, 26
br i1 %40, label %41, label %16
41: ; preds = %37
%42 = call i32 @putchar(i32 10)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%44 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%45 = load i32, i32* %1
%46 = icmp ugt i32 %45, 1
br i1 %46, label %47, label %9
47: ; preds = %41, %0
ret i32 0
}