#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*/ key;
typedef int /*<<< orphan*/ iv;

/* Variables and functions */
int do_sendfile(char *, char *);
int do_sendfile_aes(char *, char *, char *, int, char *, int, int);
int /*<<< orphan*/ parse_hex(char *, int *, char *);
int print_help(int, char **);
int main(int argc, char **argv) {
  char *filename_in = argv[1];
  char *filename_out = argv[2];
  char key[128];
  int key_length = sizeof(key);
  char iv[128];
  int iv_length = sizeof(iv);
  int encrypt = 1;
  switch (argc) {
  case 3:
    return do_sendfile(filename_out, filename_in);
  case 6:
    encrypt = argv[5][0] == '1' ? 1 : 0;
  case 5:
    parse_hex(key, &key_length, argv[3]);
    parse_hex(iv, &iv_length, argv[4]);
    if (key_length == 0 || iv_length == 0)
      return -1;
    return do_sendfile_aes(filename_out, filename_in, key, key_length, iv,
                           iv_length, encrypt);
  default:
    return print_help(argc, argv);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x80,-0xa4(%rbp)
movl   $0x80,-0x134(%rbp)
movl   $0x1,-0x138(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x13c(%rbp)
sub    $0x3,%eax
je     11ce <main+0x8e>
jmp    11a6 <main+0x66>
mov    -0x13c(%rbp),%eax
sub    $0x5,%eax
je     1201 <main+0xc1>
jmp    11ba <main+0x7a>
mov    -0x13c(%rbp),%eax
sub    $0x6,%eax
je     11e3 <main+0xa3>
jmp    1296 <main+0x156>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <do_sendfile@plt>
mov    %eax,-0x4(%rbp)
jmp    12a5 <main+0x165>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
movsbl (%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x31,%edx
cmove  %ecx,%eax
mov    %eax,-0x138(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    -0xa4(%rbp),%rsi
call   1050 <parse_hex@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    -0x134(%rbp),%rsi
call   1050 <parse_hex@plt>
cmpl   $0x0,-0xa4(%rbp)
je     1251 <main+0x111>
cmpl   $0x0,-0x134(%rbp)
jne    125d <main+0x11d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a5 <main+0x165>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
mov    -0xa4(%rbp),%ecx
lea    -0x130(%rbp),%r8
mov    -0x134(%rbp),%r9d
mov    -0x138(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <do_sendfile_aes@plt>
mov    %eax,-0x4(%rbp)
jmp    12a5 <main+0x165>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <print_help@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%r15
movl   $0x80,0xc(%rsp)
movl   $0x80,0x8(%rsp)
cmp    $0x6,%edi
je     1193 <main+0x53>
cmp    $0x5,%edi
je     11a2 <main+0x62>
cmp    $0x3,%edi
jne    1210 <main+0xd0>
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <do_sendfile@plt>
mov    0x28(%rbx),%rax
xor    %ebp,%ebp
cmpb   $0x31,(%rax)
sete   %bpl
jmp    11a7 <main+0x67>
mov    $0x1,%ebp
mov    0x18(%rbx),%rdx
lea    0x90(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1050 <parse_hex@plt>
mov    0x20(%rbx),%rdx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <parse_hex@plt>
mov    0xc(%rsp),%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     1202 <main+0xc2>
mov    0x8(%rsp),%r9d
test   %r9d,%r9d
je     1202 <main+0xc2>
mov    %ebp,(%rsp)
lea    0x90(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <do_sendfile_aes@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rsi
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <print_help@plt>

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
store i8* %18, i8** %7
store i32 128, i32* %9
store i32 128, i32* %11
store i32 1, i32* %12
%19 = load i32, i32* %4
switch i32 %19, label %60 [
i32 3, label %20
i32 6, label %24
i32 5, label %34
]
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = load i8*, i8** %6
%23 = call i32 @do_sendfile(i8* %21, i8* %22)
store i32 %23, i32* %3
br label %64
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 5
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 49
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 1, i32 0
store i32 %33, i32* %12
br label %34
34: ; preds = %2, %24
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @parse_hex(i8* %35, i32* %9, i8* %38)
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 4
%43 = load i8*, i8** %42
%44 = call i32 @parse_hex(i8* %40, i32* %11, i8* %43)
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %34
%48 = load i32, i32* %11
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47, %34
store i32 -1, i32* %3
br label %64
51: ; preds = %47
%52 = load i8*, i8** %7
%53 = load i8*, i8** %6
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%55 = load i32, i32* %9
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%57 = load i32, i32* %11
%58 = load i32, i32* %12
%59 = call i32 @do_sendfile_aes(i8* %52, i8* %53, i8* %54, i32 %55, i8* %56, i32 %57, i32 %58)
store i32 %59, i32* %3
br label %64
60: ; preds = %2
%61 = load i32, i32* %4
%62 = load i8**, i8*** %5
%63 = call i32 @print_help(i32 %61, i8** %62)
store i32 %63, i32* %3
br label %64
64: ; preds = %60, %51, %50, %20
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca i32
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = bitcast i32* %4 to i8*
store i32 128, i32* %4
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%14 = bitcast i32* %6 to i8*
store i32 128, i32* %6
switch i32 %0, label %38 [
i32 3, label %15
i32 6, label %17
i32 5, label %23
]
15: ; preds = %2
%16 = tail call i32 @do_sendfile(i8* %10, i8* %8)
br label %40
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 5
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 49
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %2, %17
%24 = phi i32 [ 1, %2 ], [ %22, %17 ]
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = call i32 @parse_hex(i8* %11, i32* %4, i8* %26)
%28 = getelementptr inbounds i8*, i8** %1, i64 4
%29 = load i8*, i8** %28
%30 = call i32 @parse_hex(i8* %13, i32* %6, i8* %29)
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 0
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 0
%35 = select i1 %32, i1 true, i1 %34
br i1 %35, label %40, label %36
36: ; preds = %23
%37 = call i32 @do_sendfile_aes(i8* %10, i8* %8, i8* %11, i32 %31, i8* %13, i32 %33, i32 %24)
br label %40
38: ; preds = %2
%39 = tail call i32 @print_help(i32 %0, i8** %1)
br label %40
40: ; preds = %23, %38, %36, %15
%41 = phi i32 [ %39, %38 ], [ %37, %36 ], [ %16, %15 ], [ -1, %23 ]
ret i32 %41
}