#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 ((c = fgetc(ip)) != EOF) {
    if (c <= 122 && c >= 97) {
      c -= 97;
      flag = 1;
    } else if (c <= 90 && c >= 65)
      c -= 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;
    }
    p = (c - d) % 26;
    fputc((char)(flag == 1 ? p + 97 : p + 65), op);
    flag = 0;
  }
  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    135c <main+0x20c>
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,-0x2a(%rbp)
movsbl %al,%eax
mov    0x2e0c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1355 <main+0x205>
movsbl -0x2a(%rbp),%eax
cmp    $0x7a,%eax
jg     1217 <main+0xc7>
movsbl -0x2a(%rbp),%eax
cmp    $0x61,%eax
jl     1217 <main+0xc7>
movsbl -0x2a(%rbp),%eax
sub    $0x61,%eax
mov    %al,-0x2a(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    125d <main+0x10d>
movsbl -0x2a(%rbp),%eax
cmp    $0x5a,%eax
jg     1240 <main+0xf0>
movsbl -0x2a(%rbp),%eax
cmp    $0x41,%eax
jl     1240 <main+0xf0>
movsbl -0x2a(%rbp),%eax
sub    $0x41,%eax
mov    %al,-0x2a(%rbp)
jmp    1258 <main+0x108>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    135c <main+0x20c>
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    135c <main+0x20c>
jmp    1300 <main+0x1b0>
movsbl -0x2a(%rbp),%eax
movsbl -0x2b(%rbp),%ecx
sub    %ecx,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x29(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1330 <main+0x1e0>
movsbl -0x29(%rbp),%eax
add    $0x61,%eax
mov    %eax,-0x40(%rbp)
jmp    133a <main+0x1ea>
movsbl -0x29(%rbp),%eax
add    $0x41,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
movl   $0x0,-0x14(%rbp)
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    124d <main+0xfd>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e4c(%rip),%r13
xor    %ecx,%ecx
cmp    0x0(%r13),%al
je     125e <main+0x10e>
mov    %r14,(%rsp)
jmp    11ff <main+0xaf>
xchg   %ax,%ax
cmp    $0x1a,%r15b
setb   %al
sub    %cl,%r12b
movsbl %r12b,%ecx
imul   $0x4f,%ecx,%edx
movzwl %dx,%esi
shr    $0xb,%edx
shr    $0xf,%esi
add    %dl,%sil
movzbl %sil,%edx
lea    (%rdx,%rdx,4),%esi
lea    (%rsi,%rsi,4),%esi
add    %edx,%esi
sub    %sil,%cl
shl    $0x5,%al
add    %cl,%al
add    $0x41,%al
movsbl %al,%edi
mov    %r14,%rbp
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%al
je     126f <main+0x11f>
lea    -0x61(%rax),%r15d
mov    %r15d,%r12d
cmp    $0x1a,%r15b
jb     1215 <main+0xc5>
add    $0xbf,%al
mov    %eax,%r12d
cmp    $0x19,%al
ja     1244 <main+0xf4>
mov    %rbp,%r14
mov    (%rsp),%rax
mov    0x18(%rax),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
movzbl 0x0(%rbp),%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    0xdb9(%rip),%rdi
jmp    1254 <main+0x104>
lea    0xdc5(%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    125e <main+0x10e>

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* %10
%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* %10
%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* %10
%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* %10
%43 = sext i8 %42 to i32
%44 = sub nsw i32 %43, 97
%45 = trunc i32 %44 to i8
store i8 %45, i8* %10
store i32 1, i32* %6
br label %62
46: ; preds = %37, %33
%47 = load i8, i8* %10
%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* %10
%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* %10
%56 = sext i8 %55 to i32
%57 = sub nsw i32 %56, 65
%58 = trunc i32 %57 to i8
store i8 %58, i8* %10
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* %10
%105 = sext i8 %104 to i32
%106 = load i8, i8* %11
%107 = sext i8 %106 to i32
%108 = sub nsw i32 %105, %107
%109 = srem i32 %108, 26
%110 = trunc i32 %109 to i8
store i8 %110, i8* %9
%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* %9
%115 = sext i8 %114 to i32
%116 = add nsw i32 %115, 97
br label %121
117: ; preds = %103
%118 = load i8, i8* %9
%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)
store i32 0, i32* %6
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 %43
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 %46, label %14
14: ; preds = %4
%15 = getelementptr inbounds i8*, i8** %1, i64 3
br label %16
16: ; preds = %14, %33
%17 = phi i8 [ %11, %14 ], [ %40, %33 ]
%18 = add i8 %17, -97
%19 = icmp ult i8 %18, 26
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = add i8 %17, -65
%22 = icmp ult i8 %21, 26
br i1 %22, label %23, label %43
23: ; preds = %20, %16
%24 = phi i8 [ %18, %16 ], [ %21, %20 ]
%25 = load i8*, i8** %15
%26 = tail call i32 @strlen(i8* %25)
%27 = load i8, i8* %25
%28 = add i8 %27, -97
%29 = icmp ult i8 %28, 26
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = add i8 %27, -65
%32 = icmp ult i8 %31, 26
br i1 %32, label %33, label %43
33: ; preds = %30, %23
%34 = phi i8 [ %28, %23 ], [ %31, %30 ]
%35 = sub nsw i8 %24, %34
%36 = srem i8 %35, 26
%37 = select i1 %19, i8 97, i8 65
%38 = add nsw i8 %36, %37
%39 = tail call i32 @fputc(i8 signext %38, i32* %10)
%40 = tail call signext i8 @fgetc(i32* %7)
%41 = load i8, i8* @EOF
%42 = icmp eq i8 %40, %41
br i1 %42, label %46, label %16
43: ; preds = %30, %20, %2
%44 = 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), %20 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), %30 ]
%45 = tail call i32 @puts(i8* dereferenceable(1) %44)
br label %46
46: ; preds = %33, %43, %4
%47 = phi i32 [ 0, %4 ], [ 1, %43 ], [ 0, %33 ]
ret i32 %47
}