#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 *);
scalar_t__ isalpha(char);
scalar_t__ islower(char);
scalar_t__ isupper(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  if (argc == 2) {
    int r = atoi(argv[1]);
    printf("plaintext: ");
    char s[100];
    scanf("%s", s);
    printf("ciphertext: \n");
    for (int i = 0; i < strlen(s); i++) {
      if (isalpha(s[i])) {
        if (isupper(s[i])) {
          printf("%c", ((s[i] - 65 + r) % 26) + 65);
        }
        if (islower(s[i])) {
          printf("%c", ((s[i] - 97 + r) % 26) + 97);
        }
      } else
        printf("%c", s[i]);
    }
    printf("\n");
    return 0;
  } else {
    printf("Invalid key Entered.\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    12fb <main+0x18b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1080 <scanf@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
cmp    %ecx,%eax
jge    12e1 <main+0x171>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
je     12ae <main+0x13e>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1070 <isupper@plt>
cmp    $0x0,%rax
je     1261 <main+0xf1>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
sub    $0x41,%eax
add    -0x14(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x41,%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     12a9 <main+0x139>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
sub    $0x61,%eax
add    -0x14(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x61,%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c8 <main+0x158>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cd <main+0x15d>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11d9 <main+0x69>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1310 <main+0x1a0>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
cmp    $0x2,%edi
jne    12a6 <main+0x116>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r12d
lea    0xe48(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe43(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
call   10a0 <scanf@plt>
lea    0xe49(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    12ba <main+0x12a>
lea    -0x41(%r12),%r15d
add    $0xffffff9f,%r12d
xor    %ebx,%ebx
mov    %rsp,%rbp
jmp    121c <main+0x8c>
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    %rbp,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    12ba <main+0x12a>
movsbl (%rsp,%rbx,1),%edi
call   1080 <isalpha@plt>
movsbl (%rsp,%rbx,1),%edi
test   %rax,%rax
je     1200 <main+0x70>
call   1090 <isupper@plt>
test   %rax,%rax
je     1268 <main+0xd8>
movsbl (%rsp,%rbx,1),%eax
add    %r15d,%eax
movslq %eax,%rdi
imul   $0x4ec4ec4f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%edi
add    $0x41,%edi
call   1030 <putchar@plt>
movsbl (%rsp,%rbx,1),%edi
call   1040 <islower@plt>
test   %rax,%rax
je     1205 <main+0x75>
movsbl (%rsp,%rbx,1),%eax
add    %r12d,%eax
movslq %eax,%rdi
imul   $0x4ec4ec4f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%edi
add    $0x61,%edi
jmp    1200 <main+0x70>
lea    0xd62(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r14d
jmp    12c4 <main+0x134>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"plaintext: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"ciphertext: \0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [22 x i8] c"Invalid key Entered.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %84
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %20
20: ; preds = %79, %11
%21 = load i32, i32* %8
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %82
25: ; preds = %20
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isalpha(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %71
32: ; preds = %25
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i64 @isupper(i8 signext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %32
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 65
%46 = load i32, i32* %6
%47 = add nsw i32 %45, %46
%48 = srem i32 %47, 26
%49 = add nsw i32 %48, 65
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %39, %32
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = call i64 @islower(i8 signext %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %70
58: ; preds = %51
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = sub nsw i32 %63, 97
%65 = load i32, i32* %6
%66 = add nsw i32 %64, %65
%67 = srem i32 %66, 26
%68 = add nsw i32 %67, 97
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %58, %51
br label %78
71: ; preds = %25
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %71, %70
br label %79
79: ; preds = %78
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
store i32 %81, i32* %8
br label %20
82: ; preds = %20
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %86
84: ; preds = %2
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %86
86: ; preds = %84, %82
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [12 x i8] c"plaintext: \00"
@.str.1 = [3 x i8] c"%s\00"
@str = [21 x i8] c"Invalid key Entered.\00"
@str.6 = [13 x i8] c"ciphertext: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %57
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%13 = call i32 @strlen(i8* %10)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = add i32 %8, -65
%17 = add i32 %8, -97
br label %20
18: ; preds = %52, %5
%19 = call i32 @putchar(i32 10)
br label %59
20: ; preds = %15, %52
%21 = phi i64 [ 0, %15 ], [ %53, %52 ]
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call i64 @isalpha(i8 signext %23)
%25 = icmp eq i64 %24, 0
%26 = load i8, i8* %22
br i1 %25, label %47, label %27
27: ; preds = %20
%28 = call i64 @isupper(i8 signext %26)
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = load i8, i8* %22
%32 = sext i8 %31 to i32
%33 = add i32 %16, %32
%34 = srem i32 %33, 26
%35 = add nsw i32 %34, 65
%36 = call i32 @putchar(i32 %35)
br label %37
37: ; preds = %30, %27
%38 = load i8, i8* %22
%39 = call i64 @islower(i8 signext %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %52, label %41
41: ; preds = %37
%42 = load i8, i8* %22
%43 = sext i8 %42 to i32
%44 = add i32 %17, %43
%45 = srem i32 %44, 26
%46 = add nsw i32 %45, 97
br label %49
47: ; preds = %20
%48 = sext i8 %26 to i32
br label %49
49: ; preds = %41, %47
%50 = phi i32 [ %48, %47 ], [ %46, %41 ]
%51 = call i32 @putchar(i32 %50)
br label %52
52: ; preds = %49, %37
%53 = add nuw nsw i64 %21, 1
%54 = call i32 @strlen(i8* %10)
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %20, label %18
57: ; preds = %2
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %59
59: ; preds = %57, %18
%60 = phi i32 [ 0, %18 ], [ 1, %57 ]
ret i32 %60
}