#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 /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int gcd(int, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int flag = 0, a, b, c, p;
  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");
  if (ip && gcd(a, b) == 1) {
    while ((p = fgetc(ip)) != EOF && (p != '\n')) {
      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;
      }
      c = ((a * p) + b) % 26;
      fputc((char)(flag == 1 ? c + 97 : c + 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     11af <main+0x3f>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <main+0x1d2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1326 <main+0x1b6>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1080 <gcd@plt>
cmp    $0x1,%eax
jne    1326 <main+0x1b6>
jmp    1223 <main+0xb3>
mov    -0x30(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
mov    0x2dae(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x39(%rbp)
je     124f <main+0xdf>
cmpl   $0xa,-0x24(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    125f <main+0xef>
jmp    1318 <main+0x1a8>
cmpl   $0x7a,-0x24(%rbp)
jg     1288 <main+0x118>
cmpl   $0x61,-0x24(%rbp)
jl     1288 <main+0x118>
mov    -0x24(%rbp),%eax
sub    $0x61,%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    12c7 <main+0x157>
cmpl   $0x5a,-0x24(%rbp)
jg     12aa <main+0x13a>
cmpl   $0x41,-0x24(%rbp)
jl     12aa <main+0x13a>
mov    -0x24(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x24(%rbp)
jmp    12c2 <main+0x152>
lea    0xd86(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <main+0x1d2>
jmp    12c7 <main+0x157>
mov    -0x18(%rbp),%eax
imul   -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    12f4 <main+0x184>
mov    -0x20(%rbp),%eax
add    $0x61,%eax
mov    %eax,-0x40(%rbp)
jmp    12fd <main+0x18d>
mov    -0x20(%rbp),%eax
add    $0x41,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x38(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
movl   $0x0,-0x14(%rbp)
jmp    1223 <main+0xb3>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1332 <main+0x1c2>
lea    0xd20(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <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   %r12
push   %rbx
cmp    $0x5,%edi
jne    126d <main+0xfd>
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x20(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
mov    0x8(%rbx),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    0x10(%rbx),%rdi
lea    0xe48(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rbp,%rbp
je     1280 <main+0x110>
mov    %r14d,%edi
mov    %r15d,%esi
call   1080 <gcd@plt>
cmp    $0x1,%eax
jne    1280 <main+0x110>
mov    %rbp,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%eax
je     128e <main+0x11e>
mov    0x2df1(%rip),%r12
jmp    1242 <main+0xd2>
nopl   0x0(%rax)
imul   %r14d,%edx
add    %r15d,%edx
movslq %edx,%rax
imul   $0x4ec4ec4f,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x23,%rdx
add    %esi,%edx
lea    (%rdx,%rdx,4),%esi
lea    (%rsi,%rsi,4),%esi
add    %edx,%esi
sub    %esi,%eax
add    %ecx,%eax
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %rbp,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%eax
je     128e <main+0x11e>
cmp    (%r12),%eax
je     128e <main+0x11e>
lea    -0x61(%rax),%edx
mov    $0x61,%ecx
cmp    $0x1a,%edx
jb     1200 <main+0x90>
add    $0xffffffbf,%eax
mov    $0x41,%ecx
mov    %eax,%edx
cmp    $0x1a,%eax
jb     1200 <main+0x90>
lea    0xdde(%rip),%rdi
jmp    1274 <main+0x104>
lea    0xdea(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    12a0 <main+0x130>
lea    0xd7d(%rip),%rdi
call   1030 <puts@plt>
jmp    1296 <main+0x126>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
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*
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, 5
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %101
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 3
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 4
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %11
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %12
%34 = load i32*, i32** %11
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %96
36: ; preds = %17
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32 @gcd(i32 %37, i32 %38)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %96
41: ; preds = %36
br label %42
42: ; preds = %88, %41
%43 = load i32*, i32** %11
%44 = call i32 @fgetc(i32* %43)
store i32 %44, i32* %10
%45 = load i32, i32* @EOF
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i32, i32* %10
%49 = icmp ne i32 %48, 10
br label %50
50: ; preds = %47, %42
%51 = phi i1 [ false, %42 ], [ %49, %47 ]
br i1 %51, label %52, label %93
52: ; preds = %50
%53 = load i32, i32* %10
%54 = icmp sle i32 %53, 122
br i1 %54, label %55, label %61
55: ; preds = %52
%56 = load i32, i32* %10
%57 = icmp sge i32 %56, 97
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %10
%60 = sub nsw i32 %59, 97
store i32 %60, i32* %10
store i32 1, i32* %6
br label %73
61: ; preds = %55, %52
%62 = load i32, i32* %10
%63 = icmp sle i32 %62, 90
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i32, i32* %10
%66 = icmp sge i32 %65, 65
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32, i32* %10
%69 = sub nsw i32 %68, 65
store i32 %69, i32* %10
br label %72
70: ; preds = %64, %61
%71 = 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 %101
72: ; preds = %67
br label %73
73: ; preds = %72, %58
%74 = load i32, i32* %7
%75 = load i32, i32* %10
%76 = mul nsw i32 %74, %75
%77 = load i32, i32* %8
%78 = add nsw i32 %76, %77
%79 = srem i32 %78, 26
store i32 %79, i32* %9
%80 = load i32, i32* %6
%81 = icmp eq i32 %80, 1
br i1 %81, label %82, label %85
82: ; preds = %73
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 97
br label %88
85: ; preds = %73
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 65
br label %88
88: ; preds = %85, %82
%89 = phi i32 [ %84, %82 ], [ %87, %85 ]
%90 = trunc i32 %89 to i8
%91 = load i32*, i32** %12
%92 = call i32 @fputc(i8 signext %90, i32* %91)
store i32 0, i32* %6
br label %42
93: ; preds = %50
%94 = load i32*, i32** %11
%95 = call i32 @fclose(i32* %94)
br label %98
96: ; preds = %36, %17
%97 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.4, i64 0, i64 0))
br label %98
98: ; preds = %96, %93
%99 = load i32*, i32** %12
%100 = call i32 @fclose(i32* %99)
store i32 0, i32* %3
br label %101
101: ; preds = %98, %70, %15
%102 = load i32, i32* %3
ret i32 %102
}

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 %58
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 = icmp eq i32* %15, null
br i1 %19, label %54, label %20
20: ; preds = %6
%21 = tail call i32 @gcd(i32 %9, i32 %12)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %54
23: ; preds = %20
%24 = tail call i32 @fgetc(i32* %15)
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
%27 = icmp ne i32 %24, 10
%28 = and i1 %27, %26
br i1 %28, label %29, label %52
29: ; preds = %23, %38
%30 = phi i32 [ %47, %38 ], [ %24, %23 ]
%31 = add i32 %30, -97
%32 = icmp ult i32 %31, 26
br i1 %32, label %38, label %33
33: ; preds = %29
%34 = add i32 %30, -65
%35 = icmp ult i32 %34, 26
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
br label %58
38: ; preds = %33, %29
%39 = phi i32 [ 97, %29 ], [ 65, %33 ]
%40 = phi i32 [ %31, %29 ], [ %34, %33 ]
%41 = mul nsw i32 %40, %9
%42 = add nsw i32 %41, %12
%43 = srem i32 %42, 26
%44 = add nsw i32 %43, %39
%45 = trunc i32 %44 to i8
%46 = tail call i32 @fputc(i8 signext %45, i32* %18)
%47 = tail call i32 @fgetc(i32* %15)
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
%50 = icmp ne i32 %47, 10
%51 = and i1 %50, %49
br i1 %51, label %29, label %52
52: ; preds = %38, %23
%53 = tail call i32 @fclose(i32* %15)
br label %56
54: ; preds = %20, %6
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
%57 = tail call i32 @fclose(i32* %18)
br label %58
58: ; preds = %36, %56, %4
%59 = phi i32 [ 1, %4 ], [ 1, %36 ], [ 0, %56 ]
ret i32 %59
}