#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 /*<<< orphan*/ decrypt(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ encrypt(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, unsigned int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
unsigned int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned int,
                          int /*<<< orphan*/ *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Expected prog_name option filename\n");
    return -1;
  }
  if (strcmp(argv[1], "encrypt") == 0) {
    if (argc != 4) {
      printf("Expected: prog_name encrypt input output\n");
      return -1;
    }
    FILE *filep;
    filep = fopen(argv[2], "rb");
    unsigned int file_length;
    unsigned char *buffer;
    unsigned char *buffer2;
    if (filep == NULL) {
      printf("Could not open input file %s, exiting now\n", argv[2]);
      return -1;
    }
    fseek(filep, 0, 2);
    file_length = ftell(filep);
    fseek(filep, 0, 0);
    buffer = malloc(file_length * sizeof(unsigned char));
    buffer2 = malloc(file_length * sizeof(unsigned char));
    fread(buffer, sizeof(unsigned char), file_length, filep);
    fclose(filep);
    int count;
    for (count = 0; count < file_length; count++) {
      buffer2[count] = buffer[count];
    }
    encrypt(buffer, buffer2, file_length);
    filep = fopen(argv[3], "wb");
    if (filep == NULL) {
      printf("Could not open output file %s, exiting now\n", argv[2]);
      return -1;
    }
    unsigned char buf2[] = {4, 3, 2, 1};
    fwrite(buf2, sizeof(unsigned char), 4, filep);
    fwrite(buffer2, sizeof(unsigned char), file_length, filep);
    fclose(filep);
  } else if (strcmp(argv[1], "decrypt") == 0) {
    if (argc != 4) {
      printf("Expected: prog_name decrypt input output\n");
      return -1;
    }
    FILE *filep;
    filep = fopen(argv[2], "rb");
    unsigned int file_length;
    unsigned char *buffer;
    unsigned char *buffer2;
    if (filep == NULL) {
      printf("Could not open input file %s, exiting now\n", argv[2]);
      return -1;
    }
    fseek(filep, 0, 2);
    file_length = ftell(filep);
    fseek(filep, 0, 0);
    if (file_length <= 4) {
      printf("File %s is too small\n", argv[2]);
      fclose(filep);
      return -1;
    }
    buffer = malloc(file_length * sizeof(unsigned char));
    buffer2 = malloc((file_length - 4) * sizeof(unsigned char));
    fread(buffer, sizeof(unsigned char), file_length, filep);
    fclose(filep);
    if ((buffer[0] != 1) && (buffer[0] != 2) && (buffer[0] != 3) &&
        (buffer[0] != 4)) {
      printf("File %s is not encrypted\n", argv[2]);
      return -1;
    }
    buffer = &buffer[4];
    file_length -= 4;
    int count;
    for (count = 0; count < file_length; count++) {
      buffer2[count] = buffer[count];
    }
    decrypt(buffer, buffer2, file_length);
    filep = fopen(argv[3], "wb");
    if (filep == NULL) {
      printf("Could not open output file %s, exiting now\n", argv[2]);
      return -1;
    }
    fwrite(buffer2, sizeof(unsigned char), file_length, filep);
    fclose(filep);
  } else if (strcmp(argv[1], "archive") == 0) {
  } else if (strcmp(argv[1], "unarchive") == 0) {
  } else {
    printf("Unrecognized option: %s, available options "
           "are:\n\tencrypt\n\tdecrypt\n\tarchive\n\tunarchive\n",
           argv[1]);
    return -1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ea <main+0x3a>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13ab <main+0x1fb>
cmpl   $0x4,-0x8(%rbp)
je     122c <main+0x7c>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1271 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <fseek@plt>
mov    -0x1c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1313 <main+0x163>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12e3 <main+0x133>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <encrypt@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd52(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1368 <main+0x1b8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    0xe08(%rip),%eax
mov    %eax,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   10d0 <fwrite@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1674 <main+0x4c4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcf9(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    15fd <main+0x44d>
cmpl   $0x4,-0x8(%rbp)
je     13ed <main+0x23d>
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc5a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1432 <main+0x282>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10b0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <fseek@plt>
cmpl   $0x4,-0x44(%rbp)
ja     1490 <main+0x2e0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x44(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%eax
sub    $0x4,%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x50(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
je     1539 <main+0x389>
mov    -0x50(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2,%eax
je     1539 <main+0x389>
mov    -0x50(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3,%eax
je     1539 <main+0x389>
mov    -0x50(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x4,%eax
je     1539 <main+0x389>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xbd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x50(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jae    1585 <main+0x3d5>
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1555 <main+0x3a5>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1030 <decrypt@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xae0(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    15da <main+0x42a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xac0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
mov    -0x58(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
jmp    166f <main+0x4bf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb0b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1620 <main+0x470>
jmp    166a <main+0x4ba>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xae6(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1643 <main+0x493>
jmp    1665 <main+0x4b5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xacd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1674 <main+0x4c4>
jmp    166a <main+0x4ba>
jmp    166f <main+0x4bf>
jmp    1674 <main+0x4c4>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11f1 <main+0x21>
lea    0xf69(%rip),%rdi
call   1040 <puts@plt>
jmp    14a5 <main+0x2d5>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xdff(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1268 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1362 <main+0x192>
mov    0x8(%rbx),%rdi
lea    0xe70(%rip),%rsi
call   1090 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     14aa <main+0x2da>
mov    0x8(%rbx),%rdi
lea    0xe53(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     14aa <main+0x2da>
mov    0x8(%rbx),%rsi
lea    0xe44(%rip),%rdi
jmp    149e <main+0x2ce>
cmp    $0x4,%ebp
jne    13ca <main+0x1fa>
mov    0x10(%rbx),%rdi
lea    0xd8c(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ec <main+0x21c>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10d0 <fseek@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <fseek@plt>
mov    %r15d,%edi
call   10c0 <malloc@plt>
mov    %rax,%r12
mov    %r15d,%edi
call   10c0 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
test   %r15d,%r15d
je     12f7 <main+0x127>
mov    %r15d,%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <memcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1080 <encrypt@plt>
mov    0x18(%rbx),%rdi
lea    0xd26(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1486 <main+0x2b6>
mov    %rax,%rbp
movl   $0x1020304,0x4(%rsp)
01
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbp,%rcx
call   10f0 <fwrite@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
xor    %ebp,%ebp
jmp    14aa <main+0x2da>
cmp    $0x4,%ebp
jne    13db <main+0x20b>
mov    0x10(%rbx),%rdi
lea    0xc96(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ec <main+0x21c>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10d0 <fseek@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <fseek@plt>
cmp    $0x4,%r14d
ja     13fc <main+0x22c>
mov    0x10(%rbx),%rsi
lea    0xcb7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    14a5 <main+0x2d5>
lea    0xd56(%rip),%rdi
call   1040 <puts@plt>
jmp    14a5 <main+0x2d5>
lea    0xd1c(%rip),%rdi
call   1040 <puts@plt>
jmp    14a5 <main+0x2d5>
mov    0x10(%rbx),%rsi
lea    0xc14(%rip),%rdi
jmp    149e <main+0x2ce>
mov    %r14d,%r13d
mov    %r14d,%edi
call   10c0 <malloc@plt>
mov    %rax,%r12
add    $0xfffffffc,%r14d
mov    %r14d,%edi
call   10c0 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    (%r12),%al
add    $0xff,%al
cmp    $0x4,%al
jae    1493 <main+0x2c3>
add    $0x4,%r12
mov    %r14d,%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   10b0 <memcpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <decrypt@plt>
mov    0x18(%rbx),%rdi
lea    0xbcd(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1486 <main+0x2b6>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
jmp    134b <main+0x17b>
mov    0x10(%rbx),%rsi
lea    0xba8(%rip),%rdi
jmp    149e <main+0x2ce>
mov    0x10(%rbx),%rsi
lea    0xbe5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Expected prog_name option filename\0A\00"
@.str.1 = [8 x i8] c"encrypt\00"
@.str.2 = [42 x i8] c"Expected: prog_name encrypt input output\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [43 x i8] c"Could not open input file %s, exiting now\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [44 x i8] c"Could not open output file %s, exiting now\0A\00"
@__const.main.buf2 = [4 x i8] c"\04\03\02\01"
@.str.7 = [8 x i8] c"decrypt\00"
@.str.8 = [42 x i8] c"Expected: prog_name decrypt input output\0A\00"
@.str.9 = [22 x i8] c"File %s is too small\0A\00"
@.str.10 = [26 x i8] c"File %s is not encrypted\0A\00"
@.str.11 = [8 x i8] c"archive\00"
@.str.12 = [10 x i8] c"unarchive\00"
@.str.13 = [87 x i8] c"Unrecognized option: %s, available options are:\0A\09encrypt\0A\09decrypt\0A\09archive\0A\09unarchive\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 i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [4 x i8]
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %263
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %111
27: ; preds = %21
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 4
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %263
32: ; preds = %27
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %6
%37 = load i32*, i32** %6
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %42)
store i32 -1, i32* %3
br label %263
44: ; preds = %32
%45 = load i32*, i32** %6
%46 = call i32 @fseek(i32* %45, i32 0, i32 2)
%47 = load i32*, i32** %6
%48 = call i32 @ftell(i32* %47)
store i32 %48, i32* %7
%49 = load i32*, i32** %6
%50 = call i32 @fseek(i32* %49, i32 0, i32 0)
%51 = load i32, i32* %7
%52 = zext i32 %51 to i64
%53 = mul i64 %52, 1
%54 = trunc i64 %53 to i32
%55 = call i8* @malloc(i32 %54)
store i8* %55, i8** %8
%56 = load i32, i32* %7
%57 = zext i32 %56 to i64
%58 = mul i64 %57, 1
%59 = trunc i64 %58 to i32
%60 = call i8* @malloc(i32 %59)
store i8* %60, i8** %9
%61 = load i8*, i8** %8
%62 = load i32, i32* %7
%63 = load i32*, i32** %6
%64 = call i32 @fread(i8* %61, i32 1, i32 %62, i32* %63)
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
store i32 0, i32* %10
br label %67
67: ; preds = %81, %44
%68 = load i32, i32* %10
%69 = load i32, i32* %7
%70 = icmp ult i32 %68, %69
br i1 %70, label %71, label %84
71: ; preds = %67
%72 = load i8*, i8** %8
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8, i8* %75
%77 = load i8*, i8** %9
%78 = load i32, i32* %10
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 %76, i8* %80
br label %81
81: ; preds = %71
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
br label %67
84: ; preds = %67
%85 = load i8*, i8** %8
%86 = load i8*, i8** %9
%87 = load i32, i32* %7
%88 = call i32 @encrypt(i8* %85, i8* %86, i32 %87)
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 3
%91 = load i8*, i8** %90
%92 = call i32* @fopen(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %92, i32** %6
%93 = load i32*, i32** %6
%94 = icmp eq i32* %93, null
br i1 %94, label %95, label %100
95: ; preds = %84
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 2
%98 = load i8*, i8** %97
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %98)
store i32 -1, i32* %3
br label %263
100: ; preds = %84
%101 = bitcast [4 x i8]* %11 to i8*
%102 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%103 = load i32*, i32** %6
%104 = call i32 @fwrite(i8* %102, i32 1, i32 4, i32* %103)
%105 = load i8*, i8** %9
%106 = load i32, i32* %7
%107 = load i32*, i32** %6
%108 = call i32 @fwrite(i8* %105, i32 1, i32 %106, i32* %107)
%109 = load i32*, i32** %6
%110 = call i32 @fclose(i32* %109)
br label %263
111: ; preds = %21
%112 = load i8**, i8*** %5
%113 = getelementptr inbounds i8*, i8** %112, i64 1
%114 = load i8*, i8** %113
%115 = call i64 @strcmp(i8* %114, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %241
117: ; preds = %111
%118 = load i32, i32* %4
%119 = icmp ne i32 %118, 4
br i1 %119, label %120, label %122
120: ; preds = %117
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %263
122: ; preds = %117
%123 = load i8**, i8*** %5
%124 = getelementptr inbounds i8*, i8** %123, i64 2
%125 = load i8*, i8** %124
%126 = call i32* @fopen(i8* %125, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %126, i32** %12
%127 = load i32*, i32** %12
%128 = icmp eq i32* %127, null
br i1 %128, label %129, label %134
129: ; preds = %122
%130 = load i8**, i8*** %5
%131 = getelementptr inbounds i8*, i8** %130, i64 2
%132 = load i8*, i8** %131
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %132)
store i32 -1, i32* %3
br label %263
134: ; preds = %122
%135 = load i32*, i32** %12
%136 = call i32 @fseek(i32* %135, i32 0, i32 2)
%137 = load i32*, i32** %12
%138 = call i32 @ftell(i32* %137)
store i32 %138, i32* %13
%139 = load i32*, i32** %12
%140 = call i32 @fseek(i32* %139, i32 0, i32 0)
%141 = load i32, i32* %13
%142 = icmp ule i32 %141, 4
br i1 %142, label %143, label %150
143: ; preds = %134
%144 = load i8**, i8*** %5
%145 = getelementptr inbounds i8*, i8** %144, i64 2
%146 = load i8*, i8** %145
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %146)
%148 = load i32*, i32** %12
%149 = call i32 @fclose(i32* %148)
store i32 -1, i32* %3
br label %263
150: ; preds = %134
%151 = load i32, i32* %13
%152 = zext i32 %151 to i64
%153 = mul i64 %152, 1
%154 = trunc i64 %153 to i32
%155 = call i8* @malloc(i32 %154)
store i8* %155, i8** %14
%156 = load i32, i32* %13
%157 = sub i32 %156, 4
%158 = zext i32 %157 to i64
%159 = mul i64 %158, 1
%160 = trunc i64 %159 to i32
%161 = call i8* @malloc(i32 %160)
store i8* %161, i8** %15
%162 = load i8*, i8** %14
%163 = load i32, i32* %13
%164 = load i32*, i32** %12
%165 = call i32 @fread(i8* %162, i32 1, i32 %163, i32* %164)
%166 = load i32*, i32** %12
%167 = call i32 @fclose(i32* %166)
%168 = load i8*, i8** %14
%169 = getelementptr inbounds i8, i8* %168, i64 0
%170 = load i8, i8* %169
%171 = zext i8 %170 to i32
%172 = icmp ne i32 %171, 1
br i1 %172, label %173, label %196
173: ; preds = %150
%174 = load i8*, i8** %14
%175 = getelementptr inbounds i8, i8* %174, i64 0
%176 = load i8, i8* %175
%177 = zext i8 %176 to i32
%178 = icmp ne i32 %177, 2
br i1 %178, label %179, label %196
179: ; preds = %173
%180 = load i8*, i8** %14
%181 = getelementptr inbounds i8, i8* %180, i64 0
%182 = load i8, i8* %181
%183 = zext i8 %182 to i32
%184 = icmp ne i32 %183, 3
br i1 %184, label %185, label %196
185: ; preds = %179
%186 = load i8*, i8** %14
%187 = getelementptr inbounds i8, i8* %186, i64 0
%188 = load i8, i8* %187
%189 = zext i8 %188 to i32
%190 = icmp ne i32 %189, 4
br i1 %190, label %191, label %196
191: ; preds = %185
%192 = load i8**, i8*** %5
%193 = getelementptr inbounds i8*, i8** %192, i64 2
%194 = load i8*, i8** %193
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %194)
store i32 -1, i32* %3
br label %263
196: ; preds = %185, %179, %173, %150
%197 = load i8*, i8** %14
%198 = getelementptr inbounds i8, i8* %197, i64 4
store i8* %198, i8** %14
%199 = load i32, i32* %13
%200 = sub i32 %199, 4
store i32 %200, i32* %13
store i32 0, i32* %16
br label %201
201: ; preds = %215, %196
%202 = load i32, i32* %16
%203 = load i32, i32* %13
%204 = icmp ult i32 %202, %203
br i1 %204, label %205, label %218
205: ; preds = %201
%206 = load i8*, i8** %14
%207 = load i32, i32* %16
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds i8, i8* %206, i64 %208
%210 = load i8, i8* %209
%211 = load i8*, i8** %15
%212 = load i32, i32* %16
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds i8, i8* %211, i64 %213
store i8 %210, i8* %214
br label %215
215: ; preds = %205
%216 = load i32, i32* %16
%217 = add nsw i32 %216, 1
store i32 %217, i32* %16
br label %201
218: ; preds = %201
%219 = load i8*, i8** %14
%220 = load i8*, i8** %15
%221 = load i32, i32* %13
%222 = call i32 @decrypt(i8* %219, i8* %220, i32 %221)
%223 = load i8**, i8*** %5
%224 = getelementptr inbounds i8*, i8** %223, i64 3
%225 = load i8*, i8** %224
%226 = call i32* @fopen(i8* %225, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %226, i32** %12
%227 = load i32*, i32** %12
%228 = icmp eq i32* %227, null
br i1 %228, label %229, label %234
229: ; preds = %218
%230 = load i8**, i8*** %5
%231 = getelementptr inbounds i8*, i8** %230, i64 2
%232 = load i8*, i8** %231
%233 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %232)
store i32 -1, i32* %3
br label %263
234: ; preds = %218
%235 = load i8*, i8** %15
%236 = load i32, i32* %13
%237 = load i32*, i32** %12
%238 = call i32 @fwrite(i8* %235, i32 1, i32 %236, i32* %237)
%239 = load i32*, i32** %12
%240 = call i32 @fclose(i32* %239)
br label %262
241: ; preds = %111
%242 = load i8**, i8*** %5
%243 = getelementptr inbounds i8*, i8** %242, i64 1
%244 = load i8*, i8** %243
%245 = call i64 @strcmp(i8* %244, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%246 = icmp eq i64 %245, 0
br i1 %246, label %247, label %248
247: ; preds = %241
br label %261
248: ; preds = %241
%249 = load i8**, i8*** %5
%250 = getelementptr inbounds i8*, i8** %249, i64 1
%251 = load i8*, i8** %250
%252 = call i64 @strcmp(i8* %251, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
%253 = icmp eq i64 %252, 0
br i1 %253, label %254, label %255
254: ; preds = %248
br label %260
255: ; preds = %248
%256 = load i8**, i8*** %5
%257 = getelementptr inbounds i8*, i8** %256, i64 1
%258 = load i8*, i8** %257
%259 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.13, i64 0, i64 0), i8* %258)
store i32 -1, i32* %3
br label %263
260: ; preds = %254
br label %261
261: ; preds = %260, %247
br label %262
262: ; preds = %261, %234
br label %263
263: ; preds = %19, %30, %39, %95, %120, %129, %143, %191, %229, %255, %262, %100
%264 = load i32, i32* %3
ret i32 %264
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"encrypt\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [43 x i8] c"Could not open input file %s, exiting now\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [44 x i8] c"Could not open output file %s, exiting now\0A\00"
@.str.7 = [8 x i8] c"decrypt\00"
@.str.9 = [22 x i8] c"File %s is too small\0A\00"
@.str.10 = [26 x i8] c"File %s is not encrypted\0A\00"
@.str.11 = [8 x i8] c"archive\00"
@.str.12 = [10 x i8] c"unarchive\00"
@.str.13 = [87 x i8] c"Unrecognized option: %s, available options are:\0A\09encrypt\0A\09decrypt\0A\09archive\0A\09unarchive\0A\00"
@str = [41 x i8] c"Expected: prog_name decrypt input output\00"
@str.14 = [41 x i8] c"Expected: prog_name encrypt input output\00"
@str.15 = [35 x i8] c"Expected prog_name option filename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.15, i64 0, i64 0))
br label %111
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %49
12: ; preds = %7
%13 = icmp eq i32 %0, 4
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.14, i64 0, i64 0))
br label %111
16: ; preds = %12
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %17
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %111
24: ; preds = %16
%25 = tail call i32 @fseek(i32* %19, i32 0, i32 2)
%26 = tail call i32 @ftell(i32* %19)
%27 = tail call i32 @fseek(i32* %19, i32 0, i32 0)
%28 = tail call i8* @malloc(i32 %26)
%29 = tail call i8* @malloc(i32 %26)
%30 = tail call i32 @fread(i8* %28, i32 1, i32 %26, i32* %19)
%31 = tail call i32 @fclose(i32* %19)
%32 = icmp eq i32 %26, 0
br i1 %32, label %35, label %33
33: ; preds = %24
%34 = zext i32 %26 to i64
br label %35
35: ; preds = %33, %24
%36 = tail call i32 @encrypt(i8* %28, i8* %29, i32 %26)
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = tail call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i8*, i8** %17
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %42)
br label %111
44: ; preds = %35
%45 = bitcast i32* %3 to i8*
store i32 16909060, i32* %3
%46 = call i32 @fwrite(i8* %45, i32 1, i32 4, i32* %39)
%47 = tail call i32 @fwrite(i8* %29, i32 1, i32 %26, i32* %39)
%48 = tail call i32 @fclose(i32* %39)
br label %111
49: ; preds = %7
%50 = load i8*, i8** %8
%51 = tail call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %100
53: ; preds = %49
%54 = icmp eq i32 %0, 4
br i1 %54, label %57, label %55
55: ; preds = %53
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %111
57: ; preds = %53
%58 = getelementptr inbounds i8*, i8** %1, i64 2
%59 = load i8*, i8** %58
%60 = tail call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i8*, i8** %58
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %111
65: ; preds = %57
%66 = tail call i32 @fseek(i32* %60, i32 0, i32 2)
%67 = tail call i32 @ftell(i32* %60)
%68 = tail call i32 @fseek(i32* %60, i32 0, i32 0)
%69 = icmp ult i32 %67, 5
br i1 %69, label %70, label %74
70: ; preds = %65
%71 = load i8*, i8** %58
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %71)
%73 = tail call i32 @fclose(i32* %60)
br label %111
74: ; preds = %65
%75 = tail call i8* @malloc(i32 %67)
%76 = add i32 %67, -4
%77 = tail call i8* @malloc(i32 %76)
%78 = tail call i32 @fread(i8* %75, i32 1, i32 %67, i32* %60)
%79 = tail call i32 @fclose(i32* %60)
%80 = load i8, i8* %75
%81 = add i8 %80, -1
%82 = icmp ult i8 %81, 4
br i1 %82, label %86, label %83
83: ; preds = %74
%84 = load i8*, i8** %58
%85 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %84)
br label %111
86: ; preds = %74
%87 = getelementptr i8, i8* %75, i64 4
%88 = zext i32 %76 to i64
%89 = tail call i32 @decrypt(i8* %87, i8* %77, i32 %76)
%90 = getelementptr inbounds i8*, i8** %1, i64 3
%91 = load i8*, i8** %90
%92 = tail call i32* @fopen(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%93 = icmp eq i32* %92, null
br i1 %93, label %94, label %97
94: ; preds = %86
%95 = load i8*, i8** %58
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %95)
br label %111
97: ; preds = %86
%98 = tail call i32 @fwrite(i8* %77, i32 1, i32 %76, i32* %92)
%99 = tail call i32 @fclose(i32* %92)
br label %111
100: ; preds = %49
%101 = load i8*, i8** %8
%102 = tail call i64 @strcmp(i8* %101, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%103 = icmp eq i64 %102, 0
br i1 %103, label %111, label %104
104: ; preds = %100
%105 = load i8*, i8** %8
%106 = tail call i64 @strcmp(i8* %105, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
%107 = icmp eq i64 %106, 0
br i1 %107, label %111, label %108
108: ; preds = %104
%109 = load i8*, i8** %8
%110 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @.str.13, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %62, %70, %83, %97, %94, %21, %44, %41, %104, %100, %5, %14, %55, %108
%112 = phi i32 [ -1, %5 ], [ -1, %14 ], [ -1, %55 ], [ 0, %100 ], [ 0, %104 ], [ -1, %108 ], [ -1, %21 ], [ -1, %41 ], [ 0, %44 ], [ -1, %62 ], [ -1, %70 ], [ -1, %83 ], [ -1, %94 ], [ 0, %97 ]
ret i32 %112
}