#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*/ F_OK;
int access(char const *, int /*<<< orphan*/);
int atoi(char const *);
int /*<<< orphan*/ compressT_LOLS(char const *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char const *argv[]) {
  FILE *fp;
  FILE *count;
  if (argc != 3) {
    printf("%s\n",
           "Error: Incorrect amount of arguments. Please use:\n\"./asst2 [text "
           "file to be compressed] [Number of parts]\"");
    return 1;
  }
  int numberOfParts = atoi(argv[2]);
  printf("%ld\n", numberOfParts);
  if (access(argv[1], F_OK) == -1) {
    printf("%s\n", "File does not exist");
    return 1;
  }
  fp = fopen(argv[1], "r");
  count = fopen(argv[1], "r");
  if (fp == NULL || count == NULL) {
    printf("%s\n", "File could not be opened.");
    return 1;
  }
  fclose(fp);
  fclose(count);
  compressT_LOLS(argv[1], numberOfParts);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a1 <main+0x41>
lea    0xe79(%rip),%rdi
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128b <main+0x12b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
jne    1202 <main+0xa2>
lea    0xe18(%rip),%rdi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128b <main+0x12b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1248 <main+0xe8>
cmpq   $0x0,-0x20(%rbp)
jne    1269 <main+0x109>
lea    0xdb1(%rip),%rdi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128b <main+0x12b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x24(%rbp),%esi
call   1050 <compressT_LOLS@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1205 <main+0x95>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
lea    0xed5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     120e <main+0x9e>
mov    0x8(%rbx),%rdi
lea    0xec3(%rip),%r15
mov    %r15,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    0x8(%rbx),%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
test   %rbp,%rbp
je     1217 <main+0xa7>
mov    %rax,%r15
test   %rax,%rax
je     1217 <main+0xa7>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x8(%rbx),%rdi
mov    %r14d,%esi
call   1060 <compressT_LOLS@plt>
xor    %eax,%eax
jmp    1228 <main+0xb8>
lea    0xdf4(%rip),%rdi
jmp    121e <main+0xae>
lea    0xe5b(%rip),%rdi
jmp    121e <main+0xae>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [107 x i8] c"Error: Incorrect amount of arguments. Please use:\0A\22./asst2 [text file to be compressed] [Number of parts]\22\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@F_OK = global i32 0
@.str.3 = [20 x i8] c"File does not exist\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [26 x i8] c"File could not be opened.\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %54
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @F_OK
%24 = call i32 @access(i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %54
28: ; preds = %13
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %6
%38 = icmp eq i32* %37, null
br i1 %38, label %42, label %39
39: ; preds = %28
%40 = load i32*, i32** %7
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %39, %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %54
44: ; preds = %39
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = load i32, i32* %8
%53 = call i32 @compressT_LOLS(i8* %51, i32 %52)
br label %54
54: ; preds = %44, %42, %26, %11
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str.1 = [107 x i8] c"Error: Incorrect amount of arguments. Please use:\0A\22./asst2 [text file to be compressed] [Number of parts]\22\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@F_OK = global i32 0
@.str.3 = [20 x i8] c"File does not exist\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [26 x i8] c"File could not be opened.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0))
br label %33
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @F_OK
%14 = tail call i32 @access(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %6
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %33
18: ; preds = %6
%19 = load i8*, i8** %11
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = load i8*, i8** %11
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32* %20, null
%24 = icmp eq i32* %22, null
%25 = or i1 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %33
28: ; preds = %18
%29 = tail call i32 @fclose(i32* %20)
%30 = tail call i32 @fclose(i32* %22)
%31 = load i8*, i8** %11
%32 = tail call i32 @compressT_LOLS(i8* %31, i32 %9)
br label %33
33: ; preds = %16, %26, %28, %4
%34 = phi i32 [ 1, %4 ], [ 1, %16 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %34
}