#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 */
int EOF;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int fix(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int gcd(int, int);
int modInverse(int, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int flag = 0, a, b, c, p, x;
  if (argc != 5) {
    printf("Usage: program input_filename output_filename a b\n");
    return 1;
  }
  a = atoi(argv[3]);
  b = atoi(argv[4]);
  FILE *ip = fopen(argv[1], "r");
  FILE *op = fopen(argv[2], "w");
  a = modInverse(a, 26);
  if (ip && gcd(a, b) == 1) {
    while ((c = fgetc(ip)) != EOF && (c != '\n')) {
      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;
      }
      x = fix(c - b);
      p = (a * x);
      p = p % 26;
      if (p < 0)
        p += 26;
      fputc((char)(flag == 1 ? p + 97 : p + 65), op);
      flag = 0;
    }
    fclose(ip);
  } else {
    printf("Please check if the input file is available and a and b are "
           "co-prime\n");
  }
  fclose(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   $0x5,-0x8(%rbp)
je     11cf <main+0x3f>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1396 <main+0x206>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x1a,%esi
call   1030 <modInverse@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     137a <main+0x1ea>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1090 <gcd@plt>
cmp    $0x1,%eax
jne    137a <main+0x1ea>
jmp    1253 <main+0xc3>
mov    -0x30(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
mov    0x2d7e(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x39(%rbp)
je     127f <main+0xef>
cmpl   $0xa,-0x20(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    128f <main+0xff>
jmp    136c <main+0x1dc>
cmpl   $0x7a,-0x20(%rbp)
jg     12b8 <main+0x128>
cmpl   $0x61,-0x20(%rbp)
jl     12b8 <main+0x128>
mov    -0x20(%rbp),%eax
sub    $0x61,%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    12f7 <main+0x167>
cmpl   $0x5a,-0x20(%rbp)
jg     12da <main+0x14a>
cmpl   $0x41,-0x20(%rbp)
jl     12da <main+0x14a>
mov    -0x20(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x20(%rbp)
jmp    12f2 <main+0x162>
lea    0xd56(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1396 <main+0x206>
jmp    12f7 <main+0x167>
mov    -0x20(%rbp),%edi
sub    -0x1c(%rbp),%edi
call   10b0 <fix@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1330 <main+0x1a0>
mov    -0x24(%rbp),%eax
add    $0x1a,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1348 <main+0x1b8>
mov    -0x24(%rbp),%eax
add    $0x61,%eax
mov    %eax,-0x40(%rbp)
jmp    1351 <main+0x1c1>
mov    -0x24(%rbp),%eax
add    $0x41,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x38(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
movl   $0x0,-0x14(%rbp)
jmp    1253 <main+0xc3>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1386 <main+0x1f6>
lea    0xccc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
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    $0x5,%edi
jne    12ad <main+0x11d>
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x20(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
lea    0xe26(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    $0x1a,%esi
call   1030 <modInverse@plt>
test   %r12,%r12
je     12c0 <main+0x130>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14d,%esi
call   1090 <gcd@plt>
cmp    $0x1,%eax
jne    12c0 <main+0x130>
mov    %r12,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%eax
je     12ce <main+0x13e>
mov    0x2dc2(%rip),%r13
jmp    1282 <main+0xf2>
nopl   0x0(%rax,%rax,1)
sub    %r14d,%edi
call   10b0 <fix@plt>
imul   %ebx,%eax
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
mov    %eax,%ecx
sub    %edx,%ecx
neg    %edx
test   %ecx,%ecx
lea    0x1a(%rax,%rdx,1),%eax
cmovns %ecx,%eax
add    %ebp,%eax
movsbl %al,%edi
mov    %r15,%rsi
call   1070 <fputc@plt>
mov    %r12,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%eax
je     12ce <main+0x13e>
cmp    0x0(%r13),%eax
je     12ce <main+0x13e>
lea    -0x61(%rax),%edi
mov    $0x61,%ebp
cmp    $0x1a,%edi
jb     1230 <main+0xa0>
add    $0xffffffbf,%eax
mov    $0x41,%ebp
mov    %eax,%edi
cmp    $0x1a,%eax
jb     1230 <main+0xa0>
lea    0xd9e(%rip),%rdi
jmp    12b4 <main+0x124>
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    12e0 <main+0x150>
lea    0xd3d(%rip),%rdi
call   1040 <puts@plt>
jmp    12d6 <main+0x146>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Usage: program input_filename output_filename a b\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.3 = [22 x i8] c"input only alphabets\0A\00"
@.str.4 = [70 x i8] c"Please check if the input file is available and a and b are co-prime\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 5
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %113
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 4
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %8
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %12
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %13
%35 = load i32, i32* %7
%36 = call i32 @modInverse(i32 %35, i32 26)
store i32 %36, i32* %7
%37 = load i32*, i32** %12
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %108
39: ; preds = %18
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 @gcd(i32 %40, i32 %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %108
44: ; preds = %39
br label %45
45: ; preds = %100, %44
%46 = load i32*, i32** %12
%47 = call i32 @fgetc(i32* %46)
store i32 %47, i32* %9
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i32, i32* %9
%52 = icmp ne i32 %51, 10
br label %53
53: ; preds = %50, %45
%54 = phi i1 [ false, %45 ], [ %52, %50 ]
br i1 %54, label %55, label %105
55: ; preds = %53
%56 = load i32, i32* %9
%57 = icmp sle i32 %56, 122
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load i32, i32* %9
%60 = icmp sge i32 %59, 97
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %9
%63 = sub nsw i32 %62, 97
store i32 %63, i32* %9
store i32 1, i32* %6
br label %76
64: ; preds = %58, %55
%65 = load i32, i32* %9
%66 = icmp sle i32 %65, 90
br i1 %66, label %67, label %73
67: ; preds = %64
%68 = load i32, i32* %9
%69 = icmp sge i32 %68, 65
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i32, i32* %9
%72 = sub nsw i32 %71, 65
store i32 %72, i32* %9
br label %75
73: ; preds = %67, %64
%74 = 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 %113
75: ; preds = %70
br label %76
76: ; preds = %75, %61
%77 = load i32, i32* %9
%78 = load i32, i32* %8
%79 = sub nsw i32 %77, %78
%80 = call i32 @fix(i32 %79)
store i32 %80, i32* %11
%81 = load i32, i32* %7
%82 = load i32, i32* %11
%83 = mul nsw i32 %81, %82
store i32 %83, i32* %10
%84 = load i32, i32* %10
%85 = srem i32 %84, 26
store i32 %85, i32* %10
%86 = load i32, i32* %10
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %76
%89 = load i32, i32* %10
%90 = add nsw i32 %89, 26
store i32 %90, i32* %10
br label %91
91: ; preds = %88, %76
%92 = load i32, i32* %6
%93 = icmp eq i32 %92, 1
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = load i32, i32* %10
%96 = add nsw i32 %95, 97
br label %100
97: ; preds = %91
%98 = load i32, i32* %10
%99 = add nsw i32 %98, 65
br label %100
100: ; preds = %97, %94
%101 = phi i32 [ %96, %94 ], [ %99, %97 ]
%102 = trunc i32 %101 to i8
%103 = load i32*, i32** %13
%104 = call i32 @fputc(i8 signext %102, i32* %103)
store i32 0, i32* %6
br label %45
105: ; preds = %53
%106 = load i32*, i32** %12
%107 = call i32 @fclose(i32* %106)
br label %110
108: ; preds = %39, %18
%109 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.4, i64 0, i64 0))
br label %110
110: ; preds = %108, %105
%111 = load i32*, i32** %13
%112 = call i32 @fclose(i32* %111)
store i32 0, i32* %3
br label %113
113: ; preds = %110, %73, %16
%114 = load i32, i32* %3
ret i32 %114
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [69 x i8] c"Please check if the input file is available and a and b are co-prime\00"
@str.5 = [21 x i8] c"input only alphabets\00"
@str.6 = [50 x i8] c"Usage: program input_filename output_filename a b\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.6, i64 0, i64 0))
br label %63
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 3
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 4
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @modInverse(i32 %9, i32 26)
%20 = icmp eq i32* %15, null
br i1 %20, label %59, label %21
21: ; preds = %6
%22 = tail call i32 @gcd(i32 %19, i32 %12)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %59
24: ; preds = %21
%25 = tail call i32 @fgetc(i32* %15)
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %25, %26
%28 = icmp ne i32 %25, 10
%29 = and i1 %28, %27
br i1 %29, label %30, label %57
30: ; preds = %24, %39
%31 = phi i32 [ %52, %39 ], [ %25, %24 ]
%32 = add i32 %31, -97
%33 = icmp ult i32 %32, 26
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = add i32 %31, -65
%36 = icmp ult i32 %35, 26
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
br label %63
39: ; preds = %34, %30
%40 = phi i32 [ 65, %34 ], [ 97, %30 ]
%41 = phi i32 [ %35, %34 ], [ %32, %30 ]
%42 = sub nsw i32 %41, %12
%43 = tail call i32 @fix(i32 %42)
%44 = mul nsw i32 %43, %19
%45 = srem i32 %44, 26
%46 = icmp slt i32 %45, 0
%47 = add nsw i32 %45, 26
%48 = select i1 %46, i32 %47, i32 %45
%49 = add nuw nsw i32 %48, %40
%50 = trunc i32 %49 to i8
%51 = tail call i32 @fputc(i8 signext %50, i32* %18)
%52 = tail call i32 @fgetc(i32* %15)
%53 = load i32, i32* @EOF
%54 = icmp ne i32 %52, %53
%55 = icmp ne i32 %52, 10
%56 = and i1 %55, %54
br i1 %56, label %30, label %57
57: ; preds = %39, %24
%58 = tail call i32 @fclose(i32* %15)
br label %61
59: ; preds = %21, %6
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
%62 = tail call i32 @fclose(i32* %18)
br label %63
63: ; preds = %37, %61, %4
%64 = phi i32 [ 1, %4 ], [ 1, %37 ], [ 0, %61 ]
ret i32 %64
}