#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*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  check_pharse(argc, argv);
  int count;
  char *key;
  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];
  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/example.c",
            36, 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   10a0 <check_pharse@plt>
mov    0x2df7(%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    1239 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1258 <main+0xa8>
lea    0xdc0(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1383 <main+0x1d3>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdae(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12c9 <main+0x119>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%r8
lea    0xd75(%rip),%rsi
lea    0xd7e(%rip),%rdx
mov    $0x24,%ecx
call   1080 <fprintf@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    12ce <main+0x11e>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    %eax,%edx
mov    0x2d09(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     136c <main+0x1bc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x70(%rbp)
sub    $0x64,%eax
je     133e <main+0x18e>
jmp    1314 <main+0x164>
mov    -0x70(%rbp),%eax
sub    $0x65,%eax
jne    1352 <main+0x1a2>
jmp    1325 <main+0x175>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1070 <encrypt@plt>
jmp    1352 <main+0x1a2>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <decrypt@plt>
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
jmp    12ce <main+0x11e>
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   10a0 <check_pharse@plt>
mov    0x2e00(%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    12bc <main+0x10c>
mov    0x18(%r15),%rdi
mov    0x28(%r15),%rax
mov    %rax,-0x30(%rbp)
lea    0xdef(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12e3 <main+0x133>
mov    %rax,%r13
mov    0x2dbf(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    -0x38(%rbp),%rdx
call   1050 <fread@plt>
test   %eax,%eax
je     12ca <main+0x11a>
mov    %eax,%r14d
jmp    1296 <main+0xe6>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    -0x30(%rbp),%rcx
call   1030 <decrypt@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r13,%rcx
call   10c0 <fwrite@plt>
mov    0x2d6c(%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     12ca <main+0x11a>
mov    0x8(%r15),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
je     1250 <main+0xa0>
cmp    $0x65,%eax
jne    1262 <main+0xb2>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    -0x30(%rbp),%rcx
call   1070 <encrypt@plt>
jmp    1262 <main+0xb2>
lea    0xdfb(%rip),%rdi
call   1040 <puts@plt>
jmp    12d2 <main+0x122>
mov    %r13,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cee(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd01(%rip),%rsi
lea    0xd0a(%rip),%rdx
mov    %ebx,%edi
mov    $0x24,%ecx
mov    %rax,%r8
call   1080 <fprintf@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
call   10b0 <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 = [172 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/example.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 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 %78
35: ; preds = %29
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 5
%38 = load i8*, i8** %37
store i8* %38, i8** %7
%39 = load i8*, i8** %8
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %12
%41 = load i32*, i32** %12
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.3, i64 0, i64 0), i32 36, i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %35
br label %51
51: ; preds = %71, %50
%52 = trunc i64 %18 to i32
%53 = load i32, i32* @stdin
%54 = call i32 @fread(i8* %20, i32 1, i32 %52, i32 %53)
store i32 %54, i32* %6
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %75
56: ; preds = %51
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
switch i32 %62, label %71 [
i32 101, label %63
i32 100, label %67
]
63: ; preds = %56
%64 = load i32, i32* %6
%65 = load i8*, i8** %7
%66 = call i32 @encrypt(i8* %21, i8* %20, i32 %64, i8* %65)
br label %71
67: ; preds = %56
%68 = load i32, i32* %6
%69 = load i8*, i8** %7
%70 = call i32 @decrypt(i8* %21, i8* %20, i32 %68, i8* %69)
br label %71
71: ; preds = %56, %67, %63
%72 = load i32, i32* %6
%73 = load i32*, i32** %12
%74 = call i32 @fwrite(i8* %21, i32 1, i32 %72, i32* %73)
br label %51
75: ; preds = %51
%76 = load i32*, i32** %12
%77 = call i32 @fclose(i32* %76)
store i32 0, i32* %3
store i32 1, i32* %13
br label %78
78: ; preds = %75, %33
%79 = load i8*, i8** %9
%80 = load i32, i32* %3
ret i32 %80
}

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 = [172 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/example.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 = tail call i32 @check_pharse(i32 %0, i8** %1)
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 111
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 5
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %28, label %20
20: ; preds = %13
%21 = load i32, i32* @stdin
%22 = call i32 @fread(i8* %6, i32 1, i32 %4, i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %50, label %24
24: ; preds = %20
%25 = getelementptr inbounds i8*, i8** %1, i64 1
br label %35
26: ; preds = %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %52
28: ; preds = %13
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.3, i64 0, i64 0), i32 36, i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %24, %45
%36 = phi i32 [ %22, %24 ], [ %48, %45 ]
%37 = load i8*, i8** %25
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
switch i32 %40, label %45 [
i32 101, label %41
i32 100, label %43
]
41: ; preds = %35
%42 = call i32 @encrypt(i8* %7, i8* %6, i32 %36, i8* %17)
br label %45
43: ; preds = %35
%44 = call i32 @decrypt(i8* %7, i8* %6, i32 %36, i8* %17)
br label %45
45: ; preds = %35, %43, %41
%46 = call i32 @fwrite(i8* %7, i32 1, i32 %36, i32* %18)
%47 = load i32, i32* @stdin
%48 = call i32 @fread(i8* %6, i32 1, i32 %4, i32 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %35
50: ; preds = %45, %20
%51 = call i32 @fclose(i32* %18)
br label %52
52: ; preds = %50, %26
ret i32 0
}