int main(int argc, char *argv[]) {
  int mode = 0;
  if (argc != 3) {
    printUsage(argv[0]);
    return -1;
  }
  if (strcmp(argv[1], "-l") == 0) {
    mode = 0;
  } else if (strcmp(argv[1], "-s") == 0) {
    mode = 1;
  } else {
    printUsage(argv[0]);
    return -1;
  }
  char filename[] = "key.bin";
  IRpowerOn(1);
  if (IRserialOpen() < 0) {
    printf("%s E: Error getting serial device\n", __func__);
  }
  IRkickStart();
  sleep(1);
  if (mode == 0)
    IRlearnKeyToFile(argv[2]);
  else
    IRsendKeyFromFile(argv[2]);
  sleep(2);
  printf("\n");
  IRserialClose();
  IRpowerOn(0);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1080 <printUsage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ff <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe10(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    120a <main+0x6a>
movl   $0x0,-0x14(%rbp)
jmp    1252 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdea(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1233 <main+0x93>
movl   $0x1,-0x14(%rbp)
jmp    124d <main+0xad>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1080 <printUsage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ff <main+0x15f>
jmp    1252 <main+0xb2>
mov    0xdad(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    $0x1,%edi
mov    $0x0,%al
call   10a0 <IRpowerOn@plt>
mov    $0x0,%al
call   1090 <IRserialOpen@plt>
cmp    $0x0,%eax
jge    128e <main+0xee>
lea    0xd8e(%rip),%rdi
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <IRkickStart@plt>
mov    $0x1,%edi
mov    $0x0,%al
call   10c0 <sleep@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12bf <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x0,%al
call   10b0 <IRlearnKeyToFile@plt>
jmp    12ce <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x0,%al
call   1070 <IRsendKeyFromFile@plt>
mov    $0x2,%edi
mov    $0x0,%al
call   10c0 <sleep@plt>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <IRserialClose@plt>
xor    %edi,%edi
mov    $0x0,%al
call   10a0 <IRpowerOn@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11e9 <main+0x39>
mov    0x8(%rbx),%rbp
lea    0xe39(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
mov    %eax,%r14d
test   %eax,%eax
je     11fd <main+0x4d>
lea    0xe26(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11fd <main+0x4d>
mov    (%rbx),%rdi
xor    %eax,%eax
call   1090 <printUsage@plt>
mov    $0xffffffff,%eax
jmp    127e <main+0xce>
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <IRpowerOn@plt>
xor    %eax,%eax
call   10a0 <IRserialOpen@plt>
test   %eax,%eax
jns    1229 <main+0x79>
lea    0xdeb(%rip),%rdi
lea    0xe07(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <IRkickStart@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   10d0 <sleep@plt>
mov    0x10(%rbx),%rdi
xor    %eax,%eax
test   %r14d,%r14d
je     124e <main+0x9e>
call   1080 <IRsendKeyFromFile@plt>
jmp    1253 <main+0xa3>
call   10c0 <IRlearnKeyToFile@plt>
mov    $0x2,%edi
xor    %eax,%eax
call   10d0 <sleep@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <IRserialClose@plt>
xor    %edi,%edi
xor    %eax,%eax
call   10b0 <IRpowerOn@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-l\00"
@.str.1 = [3 x i8] c"-s\00"
@__const.main.filename = [8 x i8] c"key.bin\00"
@.str.2 = [35 x i8] c"%s E: Error getting serial device\0A\00"
@__func__.main = [5 x i8] c"main\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [8 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) bitcast (i32 (...)* @printUsage to i32 (i8*, ...)*)(i8* %13)
store i32 -1, i32* %3
br label %62
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %6
br label %35
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 1, i32* %6
br label %34
29: ; preds = %22
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) bitcast (i32 (...)* @printUsage to i32 (i8*, ...)*)(i8* %32)
store i32 -1, i32* %3
br label %62
34: ; preds = %28
br label %35
35: ; preds = %34, %21
%36 = bitcast [8 x i8]* %7 to i8*
%37 = call i32 (i32, ...) bitcast (i32 (...)* @IRpowerOn to i32 (i32, ...)*)(i32 1)
%38 = call i32 (...) @IRserialOpen()
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
%43 = call i32 (...) @IRkickStart()
%44 = call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) bitcast (i32 (...)* @IRlearnKeyToFile to i32 (i8*, ...)*)(i8* %50)
br label %57
52: ; preds = %42
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) bitcast (i32 (...)* @IRsendKeyFromFile to i32 (i8*, ...)*)(i8* %55)
br label %57
57: ; preds = %52, %47
%58 = call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 2)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%60 = call i32 (...) @IRserialClose()
%61 = call i32 (i32, ...) bitcast (i32 (...)* @IRpowerOn to i32 (i32, ...)*)(i32 0)
store i32 1, i32* %3
br label %62
62: ; preds = %57, %29, %10
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"-l\00"
@.str.1 = [3 x i8] c"-s\00"
@.str.2 = [35 x i8] c"%s E: Error getting serial device\0A\00"
@__func__.main = [5 x i8] c"main\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @printUsage to i32 (i8*, ...)*)(i8* %5)
br label %38
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %7
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i8*, i8** %1
%17 = tail call i32 (i8*, ...) bitcast (i32 (...)* @printUsage to i32 (i8*, ...)*)(i8* %16)
br label %38
18: ; preds = %12, %7
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @IRpowerOn to i32 (i32, ...)*)(i32 1)
%20 = tail call i32 (...) @IRserialOpen()
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.main, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = tail call i32 (...) @IRkickStart()
%26 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
br i1 %11, label %29, label %31
29: ; preds = %24
%30 = tail call i32 (i8*, ...) bitcast (i32 (...)* @IRlearnKeyToFile to i32 (i8*, ...)*)(i8* %28)
br label %33
31: ; preds = %24
%32 = tail call i32 (i8*, ...) bitcast (i32 (...)* @IRsendKeyFromFile to i32 (i8*, ...)*)(i8* %28)
br label %33
33: ; preds = %31, %29
%34 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 2)
%35 = tail call i32 @putchar(i32 10)
%36 = tail call i32 (...) @IRserialClose()
%37 = tail call i32 (i32, ...) bitcast (i32 (...)* @IRpowerOn to i32 (i32, ...)*)(i32 0)
br label %38
38: ; preds = %33, %15, %4
%39 = phi i32 [ -1, %4 ], [ 1, %33 ], [ -1, %15 ]
ret i32 %39
}