#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 */
char EOF;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int flag = 0;
  if (argc != 4) {
    printf("Usage: program input_file output_file key\n");
    return 1;
  }
  FILE *ip = fopen(argv[1], "r");
  FILE *op = fopen(argv[2], "w");
  char p, c, d;
  int i = 0;
  while ((p = fgetc(ip)) != EOF) {
    if (p <= 122 && p >= 97) {
      p -= 97;
      flag = 1;
    } else if (p <= 90 && p >= 65)
      p -= 65;
    else {
      printf("input only alphabets\n");
      return 1;
    }
    d = argv[3][i % strlen(argv[3])];
    if (d <= 122 && d >= 97) {
      d -= 97;
    } else if (d <= 90 && d >= 65)
      d -= 65;
    else {
      printf("input only alphabets\n");
      return 1;
    }
    c = (p + d) % 26;
    fputc((char)(flag == 1 ? c + 97 : c + 65), op);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     118f <main+0x3f>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1355 <main+0x205>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
mov    0x2e0c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     134e <main+0x1fe>
movsbl -0x29(%rbp),%eax
cmp    $0x7a,%eax
jg     1217 <main+0xc7>
movsbl -0x29(%rbp),%eax
cmp    $0x61,%eax
jl     1217 <main+0xc7>
movsbl -0x29(%rbp),%eax
sub    $0x61,%eax
mov    %al,-0x29(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    125d <main+0x10d>
movsbl -0x29(%rbp),%eax
cmp    $0x5a,%eax
jg     1240 <main+0xf0>
movsbl -0x29(%rbp),%eax
cmp    $0x41,%eax
jl     1240 <main+0xf0>
movsbl -0x29(%rbp),%eax
sub    $0x41,%eax
mov    %al,-0x29(%rbp)
jmp    1258 <main+0x108>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1355 <main+0x205>
jmp    125d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2b(%rbp)
movsbl -0x2b(%rbp),%eax
cmp    $0x7a,%eax
jg     12ba <main+0x16a>
movsbl -0x2b(%rbp),%eax
cmp    $0x61,%eax
jl     12ba <main+0x16a>
movsbl -0x2b(%rbp),%eax
sub    $0x61,%eax
mov    %al,-0x2b(%rbp)
jmp    1300 <main+0x1b0>
movsbl -0x2b(%rbp),%eax
cmp    $0x5a,%eax
jg     12e3 <main+0x193>
movsbl -0x2b(%rbp),%eax
cmp    $0x41,%eax
jl     12e3 <main+0x193>
movsbl -0x2b(%rbp),%eax
sub    $0x41,%eax
mov    %al,-0x2b(%rbp)
jmp    12fb <main+0x1ab>
lea    0xd45(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1355 <main+0x205>
jmp    1300 <main+0x1b0>
movsbl -0x29(%rbp),%eax
movsbl -0x2b(%rbp),%ecx
add    %ecx,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x2a(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1330 <main+0x1e0>
movsbl -0x2a(%rbp),%eax
add    $0x61,%eax
mov    %eax,-0x40(%rbp)
jmp    133a <main+0x1ea>
movsbl -0x2a(%rbp),%eax
add    $0x41,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    11c6 <main+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1240 <main+0xf0>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <fgetc@plt>
mov    0x2e4c(%rip),%r15
xor    %ecx,%ecx
cmp    (%r15),%al
je     1251 <main+0x101>
mov    %rbp,(%rsp)
xor    %ecx,%ecx
jmp    11f3 <main+0xa3>
nop
add    %bpl,%cl
movzbl %cl,%eax
imul   $0x4f,%eax,%ecx
shr    $0xb,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %dl,%al
cmp    $0x1,%r12d
sete   %cl
shl    $0x5,%cl
or     %al,%cl
add    $0x41,%cl
movsbl %cl,%edi
mov    %r14,%rbx
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %r13,%rdi
call   1050 <fgetc@plt>
mov    %r12d,%ecx
cmp    (%r15),%al
je     1262 <main+0x112>
lea    -0x61(%rax),%ebp
mov    $0x1,%r12d
cmp    $0x1a,%bpl
jb     120d <main+0xbd>
add    $0xbf,%al
mov    %eax,%ebp
mov    %ecx,%r12d
cmp    $0x19,%al
ja     1237 <main+0xe7>
mov    %rbx,%r14
mov    (%rsp),%rax
mov    0x18(%rax),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
movzbl (%rbx),%eax
lea    -0x61(%rax),%ecx
cmp    $0x1a,%cl
jb     11b0 <main+0x60>
add    $0xbf,%al
mov    %eax,%ecx
cmp    $0x19,%al
jbe    11b0 <main+0x60>
lea    0xdc6(%rip),%rdi
jmp    1247 <main+0xf7>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
jmp    1251 <main+0x101>

LLVM IR (-O0):
@.str = [43 x i8] c"Usage: program input_file output_file key\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.3 = [22 x i8] c"input only alphabets\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %127
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %8
store i32 0, i32* %12
br label %26
26: ; preds = %121, %17
%27 = load i32*, i32** %7
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %9
%29 = sext i8 %28 to i32
%30 = load i8, i8* @EOF
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %126
33: ; preds = %26
%34 = load i8, i8* %9
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 122
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load i8, i8* %9
%39 = sext i8 %38 to i32
%40 = icmp sge i32 %39, 97
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i8, i8* %9
%43 = sext i8 %42 to i32
%44 = sub nsw i32 %43, 97
%45 = trunc i32 %44 to i8
store i8 %45, i8* %9
store i32 1, i32* %6
br label %62
46: ; preds = %37, %33
%47 = load i8, i8* %9
%48 = sext i8 %47 to i32
%49 = icmp sle i32 %48, 90
br i1 %49, label %50, label %59
50: ; preds = %46
%51 = load i8, i8* %9
%52 = sext i8 %51 to i32
%53 = icmp sge i32 %52, 65
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i8, i8* %9
%56 = sext i8 %55 to i32
%57 = sub nsw i32 %56, 65
%58 = trunc i32 %57 to i8
store i8 %58, i8* %9
br label %61
59: ; preds = %50, %46
%60 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %127
61: ; preds = %54
br label %62
62: ; preds = %61, %41
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 3
%65 = load i8*, i8** %64
%66 = load i32, i32* %12
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 3
%69 = load i8*, i8** %68
%70 = call i32 @strlen(i8* %69)
%71 = srem i32 %66, %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %65, i64 %72
%74 = load i8, i8* %73
store i8 %74, i8* %11
%75 = load i8, i8* %11
%76 = sext i8 %75 to i32
%77 = icmp sle i32 %76, 122
br i1 %77, label %78, label %87
78: ; preds = %62
%79 = load i8, i8* %11
%80 = sext i8 %79 to i32
%81 = icmp sge i32 %80, 97
br i1 %81, label %82, label %87
82: ; preds = %78
%83 = load i8, i8* %11
%84 = sext i8 %83 to i32
%85 = sub nsw i32 %84, 97
%86 = trunc i32 %85 to i8
store i8 %86, i8* %11
br label %103
87: ; preds = %78, %62
%88 = load i8, i8* %11
%89 = sext i8 %88 to i32
%90 = icmp sle i32 %89, 90
br i1 %90, label %91, label %100
91: ; preds = %87
%92 = load i8, i8* %11
%93 = sext i8 %92 to i32
%94 = icmp sge i32 %93, 65
br i1 %94, label %95, label %100
95: ; preds = %91
%96 = load i8, i8* %11
%97 = sext i8 %96 to i32
%98 = sub nsw i32 %97, 65
%99 = trunc i32 %98 to i8
store i8 %99, i8* %11
br label %102
100: ; preds = %91, %87
%101 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %127
102: ; preds = %95
br label %103
103: ; preds = %102, %82
%104 = load i8, i8* %9
%105 = sext i8 %104 to i32
%106 = load i8, i8* %11
%107 = sext i8 %106 to i32
%108 = add nsw i32 %105, %107
%109 = srem i32 %108, 26
%110 = trunc i32 %109 to i8
store i8 %110, i8* %10
%111 = load i32, i32* %6
%112 = icmp eq i32 %111, 1
br i1 %112, label %113, label %117
113: ; preds = %103
%114 = load i8, i8* %10
%115 = sext i8 %114 to i32
%116 = add nsw i32 %115, 97
br label %121
117: ; preds = %103
%118 = load i8, i8* %10
%119 = sext i8 %118 to i32
%120 = add nsw i32 %119, 65
br label %121
121: ; preds = %117, %113
%122 = phi i32 [ %116, %113 ], [ %120, %117 ]
%123 = trunc i32 %122 to i8
%124 = load i32*, i32** %8
%125 = call i32 @fputc(i8 signext %123, i32* %124)
br label %26
126: ; preds = %26
store i32 0, i32* %3
br label %127
127: ; preds = %126, %100, %59, %15
%128 = load i32, i32* %3
ret i32 %128
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
@str.4 = [21 x i8] c"input only alphabets\00"
@str.5 = [42 x i8] c"Usage: program input_file output_file key\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %4, label %46
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call signext i8 @fgetc(i32* %7)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %49, label %14
14: ; preds = %4
%15 = getelementptr inbounds i8*, i8** %1, i64 3
br label %16
16: ; preds = %14, %35
%17 = phi i8 [ %11, %14 ], [ %43, %35 ]
%18 = phi i32 [ 0, %14 ], [ %26, %35 ]
%19 = add i8 %17, -97
%20 = icmp ult i8 %19, 26
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = add i8 %17, -65
%23 = icmp ult i8 %22, 26
br i1 %23, label %24, label %46
24: ; preds = %21, %16
%25 = phi i8 [ %19, %16 ], [ %22, %21 ]
%26 = phi i32 [ 1, %16 ], [ %18, %21 ]
%27 = load i8*, i8** %15
%28 = tail call i32 @strlen(i8* %27)
%29 = load i8, i8* %27
%30 = add i8 %29, -97
%31 = icmp ult i8 %30, 26
br i1 %31, label %35, label %32
32: ; preds = %24
%33 = add i8 %29, -65
%34 = icmp ult i8 %33, 26
br i1 %34, label %35, label %46
35: ; preds = %32, %24
%36 = phi i8 [ %30, %24 ], [ %33, %32 ]
%37 = add nuw nsw i8 %36, %25
%38 = urem i8 %37, 26
%39 = icmp eq i32 %26, 1
%40 = select i1 %39, i8 97, i8 65
%41 = add nuw nsw i8 %38, %40
%42 = tail call i32 @fputc(i8 signext %41, i32* %10)
%43 = tail call signext i8 @fgetc(i32* %7)
%44 = load i8, i8* @EOF
%45 = icmp eq i8 %43, %44
br i1 %45, label %49, label %16
46: ; preds = %32, %21, %2
%47 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), %21 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), %32 ]
%48 = tail call i32 @puts(i8* dereferenceable(1) %47)
br label %49
49: ; preds = %35, %46, %4
%50 = phi i32 [ 0, %4 ], [ 1, %46 ], [ 0, %35 ]
ret i32 %50
}