#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ encode(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
char optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int c;
  char *infile_path = NULL;
  char *outfile_path = NULL;
  char *keyboard_layout = NULL;
  outfile_path = "inject.bin";
  keyboard_layout = "languages/us.txt";
  while ((c = getopt(argc, argv, "l:o:i:")) != -1) {
    switch (c) {
    case 'l':
      keyboard_layout = optarg;
      break;
    case 'o':
      outfile_path = optarg;
      break;
    case 'i':
      infile_path = optarg;
      break;
    case '?':
      if (optopt == 'i' || optopt == 'o' || optopt == 'l') {
        fprintf(stderr, "Option -%c requires an argument\n", optopt);
        usage(argv[0]);
        exit(EXIT_FAILURE);
      }
    default:
      fprintf(stderr, "Unknown option encountered\n");
      usage(argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (infile_path == NULL) {
    fprintf(stderr, "input file not specified\n");
    usage(argv[0]);
    exit(EXIT_FAILURE);
  }
  printf("Phoenix_1's C ducky encoder\n\n");
  printf("Output will be stored at %s\n", outfile_path);
  printf("Using keyboard layout file %s\n", keyboard_layout);
  printf("Loading script file %s\n", infile_path);
  encode(infile_path, outfile_path, keyboard_layout);
  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)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe6b(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe6b(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6a(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12f2 <main+0x192>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     1243 <main+0xe3>
jmp    11d7 <main+0x77>
mov    -0x34(%rbp),%eax
sub    $0x69,%eax
je     1230 <main+0xd0>
jmp    11e8 <main+0x88>
mov    -0x34(%rbp),%eax
sub    $0x6c,%eax
je     120a <main+0xaa>
jmp    11f9 <main+0x99>
mov    -0x34(%rbp),%eax
sub    $0x6f,%eax
je     121d <main+0xbd>
jmp    12bc <main+0x15c>
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    12ed <main+0x18d>
mov    0x2dd4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12ed <main+0x18d>
mov    0x2dc1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12ed <main+0x18d>
mov    0x2d96(%rip),%rax
movsbl (%rax),%eax
cmp    $0x69,%eax
je     127c <main+0x11c>
mov    0x2d83(%rip),%rax
movsbl (%rax),%eax
cmp    $0x6f,%eax
je     127c <main+0x11c>
mov    0x2d70(%rip),%rax
movsbl (%rax),%eax
cmp    $0x6c,%eax
jne    12b7 <main+0x157>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
mov    0x2d54(%rip),%rax
movsbl (%rax),%edx
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12bc <main+0x15c>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11a4 <main+0x44>
cmpq   $0x0,-0x20(%rbp)
jne    132e <main+0x1ce>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <encode@plt>
xor    %eax,%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,%r14
mov    %edi,%ebp
lea    0xe84(%rip),%rbx
lea    0xe72(%rip),%rax
mov    %rax,(%rsp)
xor    %r15d,%r15d
lea    0xe80(%rip),%r13
mov    0x2e55(%rip),%r12
jmp    11b4 <main+0x44>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%rbx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1080 <getopt@plt>
cmp    $0x6c,%eax
je     11b0 <main+0x40>
cmp    $0x68,%eax
jle    11e9 <main+0x79>
cmp    $0x69,%eax
je     11e3 <main+0x73>
cmp    $0x6f,%eax
jne    1295 <main+0x125>
mov    (%r12),%rax
mov    %rax,(%rsp)
jmp    11b4 <main+0x44>
mov    (%r12),%r15
jmp    11b4 <main+0x44>
cmp    $0xffffffff,%eax
jne    1259 <main+0xe9>
test   %r15,%r15
je     12c2 <main+0x152>
lea    0xed0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe70(%rip),%rdi
mov    (%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <encode@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x3f,%eax
jne    1295 <main+0x125>
mov    0x2d7b(%rip),%rax
movzbl (%rax),%edx
lea    -0x69(%rdx),%eax
cmp    $0x6,%al
ja     1295 <main+0x125>
movzbl %al,%eax
mov    $0x49,%ecx
bt     %eax,%ecx
jae    1295 <main+0x125>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12ac <main+0x13c>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%rdi
call   1070 <usage@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
jmp    12a5 <main+0x135>

LLVM IR (-O0):
@.str = [11 x i8] c"inject.bin\00"
@.str.1 = [17 x i8] c"languages/us.txt\00"
@.str.2 = [7 x i8] c"l:o:i:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Option -%c requires an argument\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [28 x i8] c"Unknown option encountered\0A\00"
@.str.5 = [26 x i8] c"input file not specified\0A\00"
@.str.6 = [30 x i8] c"Phoenix_1's C ducky encoder\0A\0A\00"
@.str.7 = [29 x i8] c"Output will be stored at %s\0A\00"
@.str.8 = [31 x i8] c"Using keyboard layout file %s\0A\00"
@.str.9 = [24 x i8] c"Loading script file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %10
10: ; preds = %56, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %57
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %47 [
i32 108, label %17
i32 111, label %19
i32 105, label %21
i32 63, label %23
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %9
br label %56
19: ; preds = %15
%20 = load i8*, i8** @optarg
store i8* %20, i8** %8
br label %56
21: ; preds = %15
%22 = load i8*, i8** @optarg
store i8* %22, i8** %7
br label %56
23: ; preds = %15
%24 = load i8, i8* @optopt
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 105
br i1 %26, label %35, label %27
27: ; preds = %23
%28 = load i8, i8* @optopt
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 111
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8, i8* @optopt
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 108
br i1 %34, label %35, label %46
35: ; preds = %31, %27, %23
%36 = load i32, i32* @stderr
%37 = load i8, i8* @optopt
%38 = sext i8 %37 to i32
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @usage(i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %31
br label %47
47: ; preds = %15, %46
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @usage(i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %21, %19, %17
br label %10
57: ; preds = %10
%58 = load i8*, i8** %7
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %69
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i32 @usage(i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %57
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%71 = load i8*, i8** %8
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %71)
%73 = load i8*, i8** %9
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %73)
%75 = load i8*, i8** %7
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %75)
%77 = load i8*, i8** %7
%78 = load i8*, i8** %8
%79 = load i8*, i8** %9
%80 = call i32 @encode(i8* %77, i8* %78, i8* %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"inject.bin\00"
@.str.1 = [17 x i8] c"languages/us.txt\00"
@.str.2 = [7 x i8] c"l:o:i:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Option -%c requires an argument\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [28 x i8] c"Unknown option encountered\0A\00"
@.str.5 = [26 x i8] c"input file not specified\0A\00"
@.str.7 = [29 x i8] c"Output will be stored at %s\0A\00"
@.str.8 = [31 x i8] c"Using keyboard layout file %s\0A\00"
@.str.9 = [24 x i8] c"Loading script file %s\0A\00"
@str = [29 x i8] c"Phoenix_1's C ducky encoder\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i8* [ %18, %17 ], [ null, %2 ]
%5 = phi i8* [ %8, %17 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%6 = phi i8* [ %11, %17 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %2 ]
br label %7
7: ; preds = %3, %15
%8 = phi i8* [ %5, %3 ], [ %16, %15 ]
%9 = phi i8* [ %6, %3 ], [ %11, %15 ]
br label %10
10: ; preds = %7, %13
%11 = phi i8* [ %14, %13 ], [ %9, %7 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
switch i32 %12, label %29 [
i32 -1, label %36
i32 108, label %13
i32 111, label %15
i32 105, label %17
i32 63, label %19
]
13: ; preds = %10
%14 = load i8*, i8** @optarg
br label %10
15: ; preds = %10
%16 = load i8*, i8** @optarg
br label %7
17: ; preds = %10
%18 = load i8*, i8** @optarg
br label %3
19: ; preds = %10
%20 = load i8, i8* @optopt
switch i8 %20, label %29 [
i8 111, label %21
i8 108, label %21
i8 105, label %21
]
21: ; preds = %19, %19, %19
%22 = zext i8 %20 to i32
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%25 = load i8*, i8** %1
%26 = tail call i32 @usage(i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %10, %19
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%32 = load i8*, i8** %1
%33 = tail call i32 @usage(i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %10
%37 = icmp eq i8* %4, null
br i1 %37, label %38, label %45
38: ; preds = %36
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%41 = load i8*, i8** %1
%42 = tail call i32 @usage(i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %11)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%50 = tail call i32 @encode(i8* %4, i8* %8, i8* %11)
ret i32 0
}