#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 */
char getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void main() {
  char s[30], k[27], c[30];
  int i, index;
  printf("Enter plain text: ");
  gets(s);
  printf("\nEnter key with 26 character:");
  for (i = 0; i < 26; i++) {
    printf("\n%c", i + 97);
    k[i] = getchar();
    printf("%c", k[i]);
  }
  for (i = 0; i < strlen(s); i++) {
    index = s[i] - 97;
    c[i] = k[index];
  }
  printf("Your cipher text is:");
  for (i = 0; i < strlen(s); i++) {
    printf("%c", c[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1060 <gets@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x1a,-0x64(%rbp)
jge    11c8 <main+0x88>
mov    -0x64(%rbp),%esi
add    $0x61,%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,%cl
movslq -0x64(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
movslq -0x64(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1174 <main+0x34>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jge    1218 <main+0xd8>
movslq -0x64(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
sub    $0x61,%eax
mov    %eax,-0x68(%rbp)
movslq -0x68(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%cl
movslq -0x64(%rbp),%rax
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11cf <main+0x8f>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x70(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
jge    126e <main+0x12e>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    122d <main+0xed>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1070 <gets@plt>
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffffffffffe6,%rbx
lea    0xea6(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    0x7b(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,0x3a(%rsp,%rbx,1)
movsbl %al,%edi
call   1030 <putchar@plt>
inc    %rbx
jne    1190 <main+0x40>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11f2 <main+0xa2>
xor    %ebx,%ebx
lea    0x20(%rsp),%r15
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
movsbq (%rsp,%rbx,1),%rax
movzbl -0x61(%rax,%r15,1),%eax
mov    %al,0x40(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11d0 <main+0x80>
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    123d <main+0xed>
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0x40(%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1220 <main+0xd0>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter plain text: \00"
@.str.1 = [30 x i8] c"\0AEnter key with 26 character:\00"
@.str.2 = [4 x i8] c"\0A%c\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [21 x i8] c"Your cipher text is:\00"
define void @main() {
%1 = alloca [30 x i8]
%2 = alloca [27 x i8]
%3 = alloca [30 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %10
10: ; preds = %27, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 26
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 97
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call signext i8 (...) @getchar()
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 %19
store i8 %17, i8* %20
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %13
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %10
30: ; preds = %10
store i32 0, i32* %4
br label %31
31: ; preds = %50, %30
%32 = load i32, i32* %4
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %53
36: ; preds = %31
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = sub nsw i32 %41, 97
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %48
store i8 %46, i8* %49
br label %50
50: ; preds = %36
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %31
53: ; preds = %31
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %55
55: ; preds = %67, %53
%56 = load i32, i32* %4
%57 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = icmp slt i32 %56, %58
br i1 %59, label %60, label %70
60: ; preds = %55
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %60
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
store i32 %69, i32* %4
br label %55
70: ; preds = %55
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter plain text: \00"
@.str.1 = [30 x i8] c"\0AEnter key with 26 character:\00"
@.str.2 = [4 x i8] c"\0A%c\00"
@.str.4 = [21 x i8] c"Your cipher text is:\00"
define void @main() {
%1 = alloca [30 x i8]
%2 = alloca [27 x i8]
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %13
%11 = call i32 @strlen(i8* %4)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %24, label %37
13: ; preds = %0, %13
%14 = phi i64 [ 0, %0 ], [ %22, %13 ]
%15 = trunc i64 %14 to i32
%16 = add i32 %15, 97
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call signext i8 (...) @getchar()
%19 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 %14
store i8 %18, i8* %19
%20 = sext i8 %18 to i32
%21 = call i32 @putchar(i32 %20)
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, 26
br i1 %23, label %10, label %13
24: ; preds = %10, %24
%25 = phi i64 [ %33, %24 ], [ 0, %10 ]
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i64
%29 = add nsw i64 %28, -97
%30 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %25
store i8 %31, i8* %32
%33 = add nuw nsw i64 %25, 1
%34 = call i32 @strlen(i8* %4)
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %24, label %37
37: ; preds = %24, %10
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @strlen(i8* %4)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %37, %41
%42 = phi i64 [ %47, %41 ], [ 0, %37 ]
%43 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 @putchar(i32 %45)
%47 = add nuw nsw i64 %42, 1
%48 = call i32 @strlen(i8* %4)
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %47, %49
br i1 %50, label %41, label %51
51: ; preds = %41, %37
ret void
}