#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*/ raw;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ check_pharse(int, char **);
int /*<<< orphan*/ decrypt(char *, char *, int, int *);
int /*<<< orphan*/ encrypt(char *, char *, int, int *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  check_pharse(argc, argv);
  int count;
  int key[2];
  char *path;
  char raw[BUFSIZ];
  char result[sizeof(raw)];
  FILE *file;
  if (argv[2][1] == 'o')
    path = argv[3];
  else {
    printf("input the output file name.\n");
    return 0;
  }
  key[0] = atoi(argv[5]);
  key[1] = atoi(argv[6]);
  file = fopen(path, "w");
  if (file == NULL) {
    fprintf(stderr, "%s LINE %d: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/time-river/a-collection-of-junior/refs/"
            "heads/master/homework/cryptology/affine.c",
            39, strerror(errno));
    exit(EXIT_FAILURE);
  }
  while ((count = fread(raw, sizeof(char), sizeof(raw), stdin)) != 0) {
    switch (argv[1][1]) {
    case 'e':
      encrypt(result, raw, count, key);
      break;
    case 'd':
      decrypt(result, raw, count, key);
      break;
    }
    fwrite(result, sizeof(char), count, file);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10b0 <check_pharse@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x68(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6f,%eax
jne    1249 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1268 <main+0xa8>
lea    0xdb0(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    13a7 <main+0x1e7>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12ed <main+0x12d>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%r8
lea    0xd51(%rip),%rsi
lea    0xd5a(%rip),%rdx
mov    $0x27,%ecx
call   1080 <fprintf@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    12f2 <main+0x132>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    %eax,%edx
mov    0x2ce5(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1390 <main+0x1d0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x70(%rbp)
sub    $0x64,%eax
je     1362 <main+0x1a2>
jmp    1338 <main+0x178>
mov    -0x70(%rbp),%eax
sub    $0x65,%eax
jne    1376 <main+0x1b6>
jmp    1349 <main+0x189>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x1c(%rbp),%rcx
call   1070 <encrypt@plt>
jmp    1376 <main+0x1b6>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x1c(%rbp),%rcx
call   1030 <decrypt@plt>
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
jmp    12f2 <main+0x132>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
call   10b0 <check_pharse@plt>
mov    %rsp,%r14
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
mov    %rax,-0x38(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x10(%r15),%rax
cmpb   $0x6f,0x1(%rax)
jne    12ec <main+0x12c>
mov    %r14,-0x40(%rbp)
mov    0x18(%r15),%r14
mov    0x28(%r15),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    0x30(%r15),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
lea    0xdc8(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     131a <main+0x15a>
mov    %rax,%r13
mov    0x2d95(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    -0x38(%rbp),%rdx
call   1050 <fread@plt>
test   %eax,%eax
je     12fa <main+0x13a>
mov    %eax,%r14d
jmp    12c6 <main+0x106>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
lea    -0x30(%rbp),%rcx
call   1030 <decrypt@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r13,%rcx
call   10d0 <fwrite@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    -0x38(%rbp),%rdx
call   1050 <fread@plt>
mov    %eax,%r14d
test   %eax,%eax
je     12fa <main+0x13a>
mov    0x8(%r15),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
je     1280 <main+0xc0>
cmp    $0x65,%eax
jne    1292 <main+0xd2>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
lea    -0x30(%rbp),%rcx
call   1070 <encrypt@plt>
jmp    1292 <main+0xd2>
lea    0xdca(%rip),%rdi
call   1040 <puts@plt>
jmp    1306 <main+0x146>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%r14
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb7(%rip),%rax
mov    (%rax),%ebx
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xcca(%rip),%rsi
lea    0xcd3(%rip),%rdx
mov    %ebx,%edi
mov    $0x27,%ecx
mov    %rax,%r8
call   1080 <fprintf@plt>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [29 x i8] c"input the output file name.\0A\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"%s LINE %d: %s\0A\00"
@.str.3 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/time-river/a-collection-of-junior/refs/heads/master/homework/cryptology/affine.c\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @check_pharse(i32 %14, i8** %15)
%17 = load i32, i32* @BUFSIZ
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %9
%20 = alloca i8, i64 %18
store i64 %18, i64* %10
%21 = alloca i8, i64 %18
store i64 %18, i64* %11
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 111
br i1 %28, label %29, label %33
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
store i8* %32, i8** %8
br label %35
33: ; preds = %2
%34 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
store i32 1, i32* %13
br label %85
35: ; preds = %29
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 5
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %39, i32* %40
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 6
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %44, i32* %45
%46 = load i8*, i8** %8
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %47, i32** %12
%48 = load i32*, i32** %12
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %57
50: ; preds = %35
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.3, i64 0, i64 0), i32 39, i8* %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %35
br label %58
58: ; preds = %78, %57
%59 = trunc i64 %18 to i32
%60 = load i32, i32* @stdin
%61 = call i32 @fread(i8* %20, i32 1, i32 %59, i32 %60)
store i32 %61, i32* %6
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %82
63: ; preds = %58
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
switch i32 %69, label %78 [
i32 101, label %70
i32 100, label %74
]
70: ; preds = %63
%71 = load i32, i32* %6
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%73 = call i32 @encrypt(i8* %21, i8* %20, i32 %71, i32* %72)
br label %78
74: ; preds = %63
%75 = load i32, i32* %6
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%77 = call i32 @decrypt(i8* %21, i8* %20, i32 %75, i32* %76)
br label %78
78: ; preds = %63, %74, %70
%79 = load i32, i32* %6
%80 = load i32*, i32** %12
%81 = call i32 @fwrite(i8* %21, i32 1, i32 %79, i32* %80)
br label %58
82: ; preds = %58
%83 = load i32*, i32** %12
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %3
store i32 1, i32* %13
br label %85
85: ; preds = %82, %33
%86 = load i8*, i8** %9
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"%s LINE %d: %s\0A\00"
@.str.3 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/time-river/a-collection-of-junior/refs/heads/master/homework/cryptology/affine.c\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@str = [28 x i8] c"input the output file name.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = tail call i32 @check_pharse(i32 %0, i8** %1)
%5 = bitcast [2 x i32]* %3 to i8*
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = alloca i8, i64 %7
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 111
br i1 %15, label %16, label %35
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 5
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 6
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %25, i32* %26
%27 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %37, label %29
29: ; preds = %16
%30 = load i32, i32* @stdin
%31 = call i32 @fread(i8* %9, i32 1, i32 %6, i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %59, label %33
33: ; preds = %29
%34 = getelementptr inbounds i8*, i8** %1, i64 1
br label %44
35: ; preds = %2
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %61
37: ; preds = %16
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.3, i64 0, i64 0), i32 39, i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %33, %54
%45 = phi i32 [ %31, %33 ], [ %57, %54 ]
%46 = load i8*, i8** %34
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
switch i32 %49, label %54 [
i32 101, label %50
i32 100, label %52
]
50: ; preds = %44
%51 = call i32 @encrypt(i8* %10, i8* %9, i32 %45, i32* %22)
br label %54
52: ; preds = %44
%53 = call i32 @decrypt(i8* %10, i8* %9, i32 %45, i32* %22)
br label %54
54: ; preds = %44, %52, %50
%55 = call i32 @fwrite(i8* %10, i32 1, i32 %45, i32* %27)
%56 = load i32, i32* @stdin
%57 = call i32 @fread(i8* %9, i32 1, i32 %6, i32 %56)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %44
59: ; preds = %54, %29
%60 = call i32 @fclose(i32* %27)
br label %61
61: ; preds = %59, %35
ret i32 0
}