#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 enum func { ____Placeholder_func } func;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ decode_file(char *, char *, int, int);
int /*<<< orphan*/ encode_file(char *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int nativeBlockNum = 4;
  int parityBlockNum = 2;
  char *inFile = NULL;
  char *confFile = NULL;
  char *outFile = NULL;
  enum func { encode, decode };
  enum func op;
  nativeBlockNum = atoi(argv[1]);
  parityBlockNum = atoi(argv[2]);
  if (strcmp(argv[3], "-e") == 0) {
    op = encode;
  } else if (strcmp(argv[3], "-d") == 0) {
    op = decode;
  } else {
    printf("Invalid option!\n");
    exit(-1);
  }
  switch (op) {
  case encode:
    inFile = argv[4];
    encode_file(inFile, nativeBlockNum, parityBlockNum);
    break;
  case decode:
    if (argc == 5) {
      confFile = argv[4];
    } else if (argc == 7 && strcmp(argv[5], "-o") == 0) {
      confFile = argv[4];
      outFile = argv[6];
    } else {
      printf("Invalid command!\n");
      exit(-1);
    }
    decode_file(confFile, outFile, nativeBlockNum, parityBlockNum);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e6 <main+0x86>
movl   $0x0,-0x34(%rbp)
jmp    122b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe0e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1210 <main+0xb0>
movl   $0x1,-0x34(%rbp)
jmp    1226 <main+0xc6>
lea    0xdef(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    122b <main+0xcb>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     124f <main+0xef>
jmp    123e <main+0xde>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     126f <main+0x10f>
jmp    12fd <main+0x19d>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <encode_file@plt>
jmp    12fd <main+0x19d>
cmpl   $0x5,-0x8(%rbp)
jne    128a <main+0x12a>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12ea <main+0x18a>
cmpl   $0x7,-0x8(%rbp)
jne    12cf <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xd74(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12cf <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    12e5 <main+0x185>
lea    0xd44(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    12ea <main+0x18a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <decode_file@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbx),%rdi
lea    0xe71(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d3 <main+0x73>
mov    0x18(%rbx),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1202 <main+0xa2>
cmp    $0x5,%ebp
je     11e4 <main+0x84>
cmp    $0x7,%ebp
jne    120b <main+0xab>
mov    0x28(%rbx),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    120b <main+0xab>
mov    0x30(%rbx),%rsi
jmp    11e6 <main+0x86>
mov    0x20(%rbx),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   1050 <encode_file@plt>
jmp    11f5 <main+0x95>
xor    %esi,%esi
mov    0x20(%rbx),%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1030 <decode_file@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe00(%rip),%rdi
jmp    1212 <main+0xb2>
lea    0xe07(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-e\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [17 x i8] c"Invalid option!\0A\00"
@.str.3 = [3 x i8] c"-o\00"
@.str.4 = [18 x i8] c"Invalid command!\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 i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %6
store i32 2, i32* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %2
store i32 0, i32* %11
br label %37
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %11
br label %36
33: ; preds = %26
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %32
br label %37
37: ; preds = %36, %25
%38 = load i32, i32* %11
switch i32 %38, label %80 [
i32 0, label %39
i32 1, label %47
]
39: ; preds = %37
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 4
%42 = load i8*, i8** %41
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = call i32 @encode_file(i8* %43, i32 %44, i32 %45)
br label %80
47: ; preds = %37
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 5
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 4
%53 = load i8*, i8** %52
store i8* %53, i8** %9
br label %74
54: ; preds = %47
%55 = load i32, i32* %4
%56 = icmp eq i32 %55, 7
br i1 %56, label %57, label %70
57: ; preds = %54
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 5
%60 = load i8*, i8** %59
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %57
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 4
%66 = load i8*, i8** %65
store i8* %66, i8** %9
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 6
%69 = load i8*, i8** %68
store i8* %69, i8** %10
br label %73
70: ; preds = %57, %54
%71 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 -1)
unreachable
73: ; preds = %63
br label %74
74: ; preds = %73, %50
%75 = load i8*, i8** %9
%76 = load i8*, i8** %10
%77 = load i32, i32* %6
%78 = load i32, i32* %7
%79 = call i32 @decode_file(i8* %75, i8* %76, i32 %77, i32 %78)
br label %80
80: ; preds = %37, %74, %39
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-e\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.3 = [3 x i8] c"-o\00"
@str = [16 x i8] c"Invalid option!\00"
@str.5 = [17 x i8] c"Invalid command!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %2
%14 = load i8*, i8** %9
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 4
%22 = load i8*, i8** %21
%23 = tail call i32 @encode_file(i8* %22, i32 %5, i32 %8)
br label %41
24: ; preds = %13
switch i32 %0, label %33 [
i32 5, label %36
i32 7, label %25
]
25: ; preds = %24
%26 = getelementptr inbounds i8*, i8** %1, i64 5
%27 = load i8*, i8** %26
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = getelementptr inbounds i8*, i8** %1, i64 6
%32 = load i8*, i8** %31
br label %36
33: ; preds = %24, %25
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%35 = tail call i32 @exit(i32 -1)
unreachable
36: ; preds = %24, %30
%37 = phi i8* [ %32, %30 ], [ null, %24 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 4
%39 = load i8*, i8** %38
%40 = tail call i32 @decode_file(i8* %39, i8* %37, i32 %5, i32 %8)
br label %41
41: ; preds = %36, %20
ret i32 0
}