#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ decrypt(char *, int);
int /*<<< orphan*/ encrypt(char *, int);
int /*<<< orphan*/ printf(char *);
int main(int c, char **argv) {
  if (c != 4) {
    printf("usage: ./sealer -e/-d inputfile key\n");
    return 1;
  }
  char *command = argv[1];
  char *inp = argv[2];
  int k = atoi(argv[3]);
  if (command[0] == '-' && command[1] == 'e')
    encrypt(inp, k);
  else if (command[0] == '-' && command[1] == 'd')
    decrypt(inp, k);
  return 0;
}


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   $0x4,-0x8(%rbp)
je     1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11d2 <main+0x92>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x65,%eax
jne    11d2 <main+0x92>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <encrypt@plt>
jmp    1204 <main+0xc4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11ff <main+0xbf>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    11ff <main+0xbf>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <decrypt@plt>
jmp    1204 <main+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x4,%edi
jne    117a <main+0x3a>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r14
mov    0x18(%rsi),%rdi
call   1060 <atoi@plt>
xor    %ebp,%ebp
cmpb   $0x2d,(%rbx)
jne    118b <main+0x4b>
mov    0x1(%rbx),%cl
cmp    $0x64,%cl
je     1192 <main+0x52>
cmp    $0x65,%cl
jne    118b <main+0x4b>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <encrypt@plt>
jmp    118b <main+0x4b>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <decrypt@plt>
jmp    118b <main+0x4b>

LLVM IR (-O0):
@.str = [37 x i8] c"usage: ./sealer -e/-d inputfile key\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%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, 4
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %57
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 45
br i1 %28, label %29, label %39
29: ; preds = %13
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 101
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i8*, i8** %7
%37 = load i32, i32* %8
%38 = call i32 @encrypt(i8* %36, i32 %37)
br label %56
39: ; preds = %29, %13
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 45
br i1 %44, label %45, label %55
45: ; preds = %39
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 100
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = load i8*, i8** %7
%53 = load i32, i32* %8
%54 = call i32 @decrypt(i8* %52, i32 %53)
br label %55
55: ; preds = %51, %45, %39
br label %56
56: ; preds = %55, %35
store i32 0, i32* %3
br label %57
57: ; preds = %56, %11
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@str = [36 x i8] c"usage: ./sealer -e/-d inputfile key\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %23
6: ; preds = %2
%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 i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = load i8, i8* %8
%15 = icmp eq i8 %14, 45
br i1 %15, label %16, label %23
16: ; preds = %6
%17 = getelementptr inbounds i8, i8* %8, i64 1
%18 = load i8, i8* %17
switch i8 %18, label %23 [
i8 101, label %19
i8 100, label %21
]
19: ; preds = %16
%20 = tail call i32 @encrypt(i8* %10, i32 %13)
br label %23
21: ; preds = %16
%22 = tail call i32 @decrypt(i8* %10, i32 %13)
br label %23
23: ; preds = %16, %6, %19, %21, %4
%24 = phi i32 [ 1, %4 ], [ 0, %21 ], [ 0, %19 ], [ 0, %6 ], [ 0, %16 ]
ret i32 %24
}