#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 /*<<< orphan*/ check_pharse(int, char **);
int /*<<< orphan*/ decrypt(char *, char *, int, char *);
int /*<<< orphan*/ encrypt(char *, char *, int, char *);
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*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ update_table(char *, char *);
int main(int argc, char *argv[]) {
  check_pharse(argc, argv);
  int count;
  char *key, table[26 * 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 = argv[5];
  update_table(key, table);
  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/single-table.c",
            41, strerror(errno));
    exit(EXIT_FAILURE);
  }
  while ((count = fread(raw, sizeof(char), sizeof(raw), stdin)) != 0) {
    putchar(argv[1][1]);
    switch (argv[1][1]) {
    case 'e':
      encrypt(result, raw, count, table);
      break;
    case 'd':
      decrypt(result, raw, count, table);
      break;
    }
    fwrite(result, sizeof(char), count, file);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%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    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xa8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6f,%eax
jne    1265 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x68(%rbp)
jmp    1287 <main+0xb7>
lea    0xd94(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1400 <main+0x230>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   10c0 <update_table@plt>
mov    -0x68(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    1311 <main+0x141>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    %rax,%r8
lea    0xd2d(%rip),%rsi
lea    0xd36(%rip),%rdx
mov    $0x29,%ecx
call   1090 <fprintf@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1316 <main+0x146>
mov    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rax
mov    %eax,%edx
mov    0x2cbb(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     13e3 <main+0x213>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%edi
call   1040 <putchar@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0xb0(%rbp)
sub    $0x64,%eax
je     13a9 <main+0x1d9>
jmp    1376 <main+0x1a6>
mov    -0xb0(%rbp),%eax
sub    $0x65,%eax
jne    13c3 <main+0x1f3>
jmp    138a <main+0x1ba>
mov    -0xa0(%rbp),%rsi
mov    -0x98(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x60(%rbp),%rcx
call   1080 <encrypt@plt>
jmp    13c3 <main+0x1f3>
mov    -0xa0(%rbp),%rsi
mov    -0x98(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x60(%rbp),%rcx
call   1030 <decrypt@plt>
mov    -0x98(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
jmp    1316 <main+0x146>
mov    -0x88(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
mov    -0x70(%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    $0x48,%rsp
mov    %rsi,%r12
call   10b0 <check_pharse@plt>
mov    %rsp,%r14
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x10(%r12),%rax
cmpb   $0x6f,0x1(%rax)
jne    12fb <main+0x12b>
mov    %r14,-0x38(%rbp)
mov    0x18(%r12),%r14
mov    0x28(%r12),%rdi
lea    -0x70(%rbp),%rsi
call   10c0 <update_table@plt>
lea    0xdc0(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1329 <main+0x159>
mov    %rax,%r13
mov    0x2d8d(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    -0x30(%rbp),%rdx
call   1060 <fread@plt>
test   %eax,%eax
je     1309 <main+0x139>
mov    %eax,%r14d
jmp    12c6 <main+0xf6>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
lea    -0x70(%rbp),%rcx
call   1030 <decrypt@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r13,%rcx
call   10e0 <fwrite@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    -0x30(%rbp),%rdx
call   1060 <fread@plt>
mov    %eax,%r14d
test   %eax,%eax
je     1309 <main+0x139>
mov    0x8(%r12),%rax
movsbl 0x1(%rax),%edi
call   1040 <putchar@plt>
mov    0x8(%r12),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
je     1280 <main+0xb0>
cmp    $0x65,%eax
jne    1292 <main+0xc2>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
lea    -0x70(%rbp),%rcx
call   1080 <encrypt@plt>
jmp    1292 <main+0xc2>
lea    0xdc1(%rip),%rdi
call   1050 <puts@plt>
jmp    1315 <main+0x145>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    -0x38(%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    0x2ca8(%rip),%rax
mov    (%rax),%ebx
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcbb(%rip),%rsi
lea    0xcc4(%rip),%rdx
mov    %ebx,%edi
mov    $0x29,%ecx
mov    %rax,%r8
call   1090 <fprintf@plt>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
call   10d0 <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 = [177 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/single-table.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 i8*
%8 = alloca [52 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @check_pharse(i32 %15, i8** %16)
%18 = load i32, i32* @BUFSIZ
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %10
%21 = alloca i8, i64 %19
store i64 %19, i64* %11
%22 = alloca i8, i64 %19
store i64 %19, i64* %12
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 111
br i1 %29, label %30, label %34
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
store i8* %33, i8** %9
br label %36
34: ; preds = %2
%35 = 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* %14
br label %88
36: ; preds = %30
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 5
%39 = load i8*, i8** %38
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = getelementptr inbounds [52 x i8], [52 x i8]* %8, i64 0, i64 0
%42 = call i32 @update_table(i8* %40, i8* %41)
%43 = load i8*, i8** %9
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %13
%45 = load i32*, i32** %13
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %54
47: ; preds = %36
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.3, i64 0, i64 0), i32 41, i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %36
br label %55
55: ; preds = %81, %54
%56 = trunc i64 %19 to i32
%57 = load i32, i32* @stdin
%58 = call i32 @fread(i8* %21, i32 1, i32 %56, i32 %57)
store i32 %58, i32* %6
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %85
60: ; preds = %55
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = load i8, i8* %64
%66 = call i32 @putchar(i8 signext %65)
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
switch i32 %72, label %81 [
i32 101, label %73
i32 100, label %77
]
73: ; preds = %60
%74 = load i32, i32* %6
%75 = getelementptr inbounds [52 x i8], [52 x i8]* %8, i64 0, i64 0
%76 = call i32 @encrypt(i8* %22, i8* %21, i32 %74, i8* %75)
br label %81
77: ; preds = %60
%78 = load i32, i32* %6
%79 = getelementptr inbounds [52 x i8], [52 x i8]* %8, i64 0, i64 0
%80 = call i32 @decrypt(i8* %22, i8* %21, i32 %78, i8* %79)
br label %81
81: ; preds = %60, %77, %73
%82 = load i32, i32* %6
%83 = load i32*, i32** %13
%84 = call i32 @fwrite(i8* %22, i32 1, i32 %82, i32* %83)
br label %55
85: ; preds = %55
%86 = load i32*, i32** %13
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
store i32 1, i32* %14
br label %88
88: ; preds = %85, %34
%89 = load i8*, i8** %10
%90 = load i32, i32* %3
ret i32 %90
}

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 = [177 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/single-table.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 [52 x i8]
%4 = tail call i32 @check_pharse(i32 %0, i8** %1)
%5 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%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 %30
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 = call i32 @update_table(i8* %20, i8* %5)
%22 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %32, label %24
24: ; preds = %16
%25 = load i32, i32* @stdin
%26 = call i32 @fread(i8* %9, i32 1, i32 %6, i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %58, label %28
28: ; preds = %24
%29 = getelementptr inbounds i8*, i8** %1, i64 1
br label %39
30: ; preds = %2
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %60
32: ; preds = %16
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.3, i64 0, i64 0), i32 41, i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %28, %53
%40 = phi i32 [ %26, %28 ], [ %56, %53 ]
%41 = load i8*, i8** %29
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8, i8* %42
%44 = call i32 @putchar(i8 signext %43)
%45 = load i8*, i8** %29
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
switch i32 %48, label %53 [
i32 101, label %49
i32 100, label %51
]
49: ; preds = %39
%50 = call i32 @encrypt(i8* %10, i8* %9, i32 %40, i8* %5)
br label %53
51: ; preds = %39
%52 = call i32 @decrypt(i8* %10, i8* %9, i32 %40, i8* %5)
br label %53
53: ; preds = %39, %51, %49
%54 = call i32 @fwrite(i8* %10, i32 1, i32 %40, i32* %22)
%55 = load i32, i32* @stdin
%56 = call i32 @fread(i8* %9, i32 1, i32 %6, i32 %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %39
58: ; preds = %53, %24
%59 = call i32 @fclose(i32* %22)
br label %60
60: ; preds = %58, %30
ret i32 0
}