#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 EXIT_FAILURE;
int /*<<< orphan*/ crypt(unsigned int, unsigned char *);
int /*<<< orphan*/ decrypt(unsigned int, unsigned char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
unsigned char *hex2data(unsigned char *, unsigned int);
int length(unsigned char *);
unsigned char *optarg;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ test();
int main(int argc, char **argv) {
  int opt;
  unsigned int size;
  unsigned int index;
  unsigned char *msg;
  unsigned char *data;
  enum { DECRYPT, CRYPT, TEST } mode = TEST;
  while ((opt = getopt(argc, argv, "d:c:")) != -1) {
    switch (opt) {
    case 'd':
      mode = DECRYPT;
      msg = optarg;
      size = length(msg);
      data = hex2data(msg, size);
      size = length(msg) / 2;
      break;
    case 'c':
      mode = CRYPT;
      msg = optarg;
      size = length(msg);
      data = hex2data(msg, size);
      size = length(msg) / 2;
      break;
    default:
      fprintf(stderr, "Usage: %s -[dc] [hexstring]\n", argv[0]);
      return EXIT_FAILURE;
    }
  }
  switch (mode) {
  case TEST:
    printf("Usage: %s -[dc] [hexstring]\n", argv[0]);
    test();
    break;
  case CRYPT:
    crypt(size, data);
    break;
  case DECRYPT:
    decrypt(size, data);
    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   $0x2,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12a7 <main+0x127>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x63,%eax
je     122b <main+0xab>
jmp    11d0 <main+0x50>
mov    -0x38(%rbp),%eax
sub    $0x64,%eax
jne    1275 <main+0xf5>
jmp    11e1 <main+0x61>
movl   $0x0,-0x34(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <hex2data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <length@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    12a2 <main+0x122>
movl   $0x1,-0x34(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <hex2data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <length@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    12a2 <main+0x122>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd79(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131f <main+0x19f>
jmp    119d <main+0x1d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     130c <main+0x18c>
jmp    12ba <main+0x13a>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     12fb <main+0x17b>
jmp    12cb <main+0x14b>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
jne    1318 <main+0x198>
jmp    12dc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd1b(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   10a0 <test@plt>
jmp    1318 <main+0x198>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <crypt@plt>
jmp    1318 <main+0x198>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1030 <decrypt@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x2,%r14d
jmp    11d9 <main+0x59>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r13d
mov    0x2e4b(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1040 <length@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <hex2data@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <length@plt>
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %r13d,%r14d
mov    %ebp,%edi
mov    %r15,%rsi
lea    0xe1b(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0x63,%eax
je     11a0 <main+0x20>
xor    %r13d,%r13d
cmp    $0x64,%eax
je     11a6 <main+0x26>
cmp    $0xffffffff,%eax
jne    1229 <main+0xa9>
xor    %ebp,%ebp
test   %r14d,%r14d
je     124c <main+0xcc>
cmp    $0x1,%r14d
je     1258 <main+0xd8>
cmp    $0x2,%r14d
jne    1262 <main+0xe2>
mov    (%r15),%rsi
lea    0xdec(%rip),%rdi
call   1060 <printf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <test@plt>
jmp    1262 <main+0xe2>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdc9(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%ebp
jmp    1262 <main+0xe2>
mov    %ebx,%edi
mov    %r12,%rsi
call   1030 <decrypt@plt>
jmp    1262 <main+0xe2>
mov    %ebx,%edi
mov    %r12,%rsi
call   1050 <crypt@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"d:c:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s -[dc] [hexstring]\0A\00"
@EXIT_FAILURE = global i32 0
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
%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 2, i32* %11
br label %12
12: ; preds = %46, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %47
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %39 [
i32 100, label %19
i32 99, label %29
]
19: ; preds = %17
store i32 0, i32* %11
%20 = load i8*, i8** @optarg
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i32 @length(i8* %21)
store i32 %22, i32* %7
%23 = load i8*, i8** %9
%24 = load i32, i32* %7
%25 = call i8* @hex2data(i8* %23, i32 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %9
%27 = call i32 @length(i8* %26)
%28 = sdiv i32 %27, 2
store i32 %28, i32* %7
br label %46
29: ; preds = %17
store i32 1, i32* %11
%30 = load i8*, i8** @optarg
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = call i32 @length(i8* %31)
store i32 %32, i32* %7
%33 = load i8*, i8** %9
%34 = load i32, i32* %7
%35 = call i8* @hex2data(i8* %33, i32 %34)
store i8* %35, i8** %10
%36 = load i8*, i8** %9
%37 = call i32 @length(i8* %36)
%38 = sdiv i32 %37, 2
store i32 %38, i32* %7
br label %46
39: ; preds = %17
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %3
br label %64
46: ; preds = %29, %19
br label %12
47: ; preds = %12
%48 = load i32, i32* %11
switch i32 %48, label %63 [
i32 2, label %49
i32 1, label %55
i32 0, label %59
]
49: ; preds = %47
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = call i32 (...) @test()
br label %63
55: ; preds = %47
%56 = load i32, i32* %7
%57 = load i8*, i8** %10
%58 = call i32 @crypt(i32 %56, i8* %57)
br label %63
59: ; preds = %47
%60 = load i32, i32* %7
%61 = load i8*, i8** %10
%62 = call i32 @decrypt(i32 %60, i8* %61)
br label %63
63: ; preds = %47, %59, %55, %49
store i32 0, i32* %3
br label %64
64: ; preds = %63, %39
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [5 x i8] c"d:c:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s -[dc] [hexstring]\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %14, %2
%4 = phi i32 [ undef, %2 ], [ %20, %14 ]
%5 = phi i8* [ undef, %2 ], [ %18, %14 ]
%6 = phi i32 [ 2, %2 ], [ %15, %14 ]
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %9 [
i32 -1, label %21
i32 100, label %14
i32 99, label %8
]
8: ; preds = %3
br label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
br label %30
14: ; preds = %3, %8
%15 = phi i32 [ 1, %8 ], [ 0, %3 ]
%16 = load i8*, i8** @optarg
%17 = tail call i32 @length(i8* %16)
%18 = tail call i8* @hex2data(i8* %16, i32 %17)
%19 = tail call i32 @length(i8* %16)
%20 = sdiv i32 %19, 2
br label %3
21: ; preds = %3
switch i32 %6, label %30 [
i32 2, label %22
i32 1, label %26
i32 0, label %28
]
22: ; preds = %21
%23 = load i8*, i8** %1
%24 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = tail call i32 (...) @test()
br label %30
26: ; preds = %21
%27 = tail call i32 @crypt(i32 %4, i8* %5)
br label %30
28: ; preds = %21
%29 = tail call i32 @decrypt(i32 %4, i8* %5)
br label %30
30: ; preds = %22, %26, %28, %21, %9
%31 = phi i32 [ %13, %9 ], [ 0, %21 ], [ 0, %28 ], [ 0, %26 ], [ 0, %22 ]
ret i32 %31
}