#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ const member_1;
};

/* Variables and functions */
int /*<<< orphan*/ firmware_pack_encode(int, int, char const **, char *,
                                        char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt_long(int, char **, char *, struct option *, int *);
int make_version(int, int, int);
#define no_argument 129
char *optarg;
int optind;
#define required_argument 128
int sscanf(char *, char *, int *, int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int c;
  char *note = "";
  char *output = "output.bin";
  int fw_version = 0;
  while (1) {
    int maj = 0;
    int min = 0;
    int rev = 0;
    static struct option long_options[] = {
        {"help", no_argument, 0, 'h'},
        {"note", required_argument, 0, 'n'},
        {"output", required_argument, 0, 'o'},
        {"version", required_argument, 0, 'V'},
        {0, 0, 0, 0}};
    int option_index = 0;
    c = getopt_long(argc, argv, "hn:o:V:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 'h':
      usage();
      return -1;
    case 'n':
      note = optarg;
      break;
    case 'o':
      output = optarg;
      break;
    case 'V':
      if (sscanf(optarg, "%d.%d.%d", &maj, &min, &rev) != 3) {
        fprintf(stderr, "Invalid version format");
        usage();
        return -1;
      }
      fw_version = make_version(maj, min, rev);
      break;
    case '?':
      break;
    default:
      usage();
      return -1;
    }
  }
  if (optind >= argc) {
    fprintf(stderr, "file list must be specified\n");
    usage();
    return -1;
  }
  firmware_pack_encode(fw_version, (argc - optind) / 2,
                       (const char **)&argv[optind], note, output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xfaf(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xf3c(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf2b(%rip),%rdx
lea    0x2e9c(%rip),%rcx
lea    -0x3c(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11df <main+0x7f>
jmp    12c7 <main+0x167>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x30,%eax
ja     12af <main+0x14f>
mov    -0x48(%rbp),%rax
lea    0xe01(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1343 <main+0x1e3>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12c2 <main+0x162>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12c2 <main+0x162>
mov    0x2db0(%rip),%rax
mov    (%rax),%rdi
lea    0xe9e(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1060 <sscanf@plt>
cmp    $0x3,%eax
je     1294 <main+0x134>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1343 <main+0x1e3>
mov    -0x30(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1040 <make_version@plt>
mov    %eax,-0x2c(%rbp)
jmp    12c2 <main+0x162>
jmp    12c2 <main+0x162>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1343 <main+0x1e3>
jmp    1193 <main+0x33>
mov    0x2d12(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1301 <main+0x1a1>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1343 <main+0x1e3>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%eax
mov    0x2cd2(%rip),%rcx
sub    (%rcx),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    0x2cbb(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1070 <firmware_pack_encode@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
lea    0xe7e(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xeda(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe8a(%rip),%r13
lea    0x2ebf(%rip),%r14
lea    0x14(%rsp),%r15
mov    0x2e4b(%rip),%r12
jmp    11b9 <main+0x59>
nop
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x14(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1030 <getopt_long@plt>
cmp    $0x6d,%eax
jg     1240 <main+0xe0>
cmp    $0x3f,%eax
je     11b9 <main+0x59>
cmp    $0x56,%eax
jne    125c <main+0xfc>
mov    (%r12),%rdi
lea    0xe26(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1060 <sscanf@plt>
cmp    $0x3,%eax
jne    1295 <main+0x135>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
call   1040 <make_version@plt>
mov    %eax,0x4(%rsp)
jmp    11b9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x6f,%eax
je     11b0 <main+0x50>
cmp    $0x6e,%eax
jne    12bc <main+0x15c>
mov    (%r12),%rax
mov    %rax,0x18(%rsp)
jmp    11b9 <main+0x59>
cmp    $0xffffffff,%eax
jne    12bc <main+0x15c>
mov    0x2d78(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    12a7 <main+0x147>
sub    %eax,%ebp
mov    %ebp,%esi
shr    $0x1f,%esi
add    %ebp,%esi
sar    %esi
lea    (%rbx,%rax,8),%rdx
mov    0x4(%rsp),%edi
mov    0x18(%rsp),%rcx
mov    0x20(%rsp),%r8
call   1070 <firmware_pack_encode@plt>
xor    %eax,%eax
jmp    12c8 <main+0x168>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
jmp    12b7 <main+0x157>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [11 x i8] c"output.bin\00"
@main.long_options = internal global [5 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 -127, i32 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8 -128, i32 0, i32 110 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8 -128, i32 0, i32 111 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8 -128, i32 0, i32 86 }, %struct.option zeroinitializer]
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [5 x i8] c"note\00"
@.str.4 = [7 x i8] c"output\00"
@.str.5 = [8 x i8] c"version\00"
@.str.6 = [8 x i8] c"hn:o:V:\00"
@optarg = global i8* null
@.str.7 = [9 x i8] c"%d.%d.%d\00"
@stderr = global i32 0
@.str.8 = [23 x i8] c"Invalid version format\00"
@optind = global i32 0
@.str.9 = [29 x i8] c"file list must be specified\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i32 0, i32* %9
br label %14
14: ; preds = %2, %45
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt_long(i32 %15, i8** %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %struct.option* getelementptr inbounds ([5 x %struct.option], [5 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %13)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %14
br label %46
21: ; preds = %14
%22 = load i32, i32* %6
switch i32 %22, label %43 [
i32 104, label %23
i32 110, label %25
i32 111, label %27
i32 86, label %29
i32 63, label %42
]
23: ; preds = %21
%24 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %67
25: ; preds = %21
%26 = load i8*, i8** @optarg
store i8* %26, i8** %7
br label %45
27: ; preds = %21
%28 = load i8*, i8** @optarg
store i8* %28, i8** %8
br label %45
29: ; preds = %21
%30 = load i8*, i8** @optarg
%31 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32* %10, i32* %11, i32* %12)
%32 = icmp ne i32 %31, 3
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%36 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %67
37: ; preds = %29
%38 = load i32, i32* %10
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = call i32 @make_version(i32 %38, i32 %39, i32 %40)
store i32 %41, i32* %9
br label %45
42: ; preds = %21
br label %45
43: ; preds = %21
%44 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %67
45: ; preds = %42, %37, %27, %25
br label %14
46: ; preds = %20
%47 = load i32, i32* @optind
%48 = load i32, i32* %4
%49 = icmp sge i32 %47, %48
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%53 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %67
54: ; preds = %46
%55 = load i32, i32* %9
%56 = load i32, i32* %4
%57 = load i32, i32* @optind
%58 = sub nsw i32 %56, %57
%59 = sdiv i32 %58, 2
%60 = load i8**, i8*** %5
%61 = load i32, i32* @optind
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %7
%65 = load i8*, i8** %8
%66 = call i32 @firmware_pack_encode(i32 %55, i32 %59, i8** %63, i8* %64, i8* %65)
store i32 0, i32* %3
br label %67
67: ; preds = %54, %50, %43, %33, %23
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [11 x i8] c"output.bin\00"
@main.long_options = internal global [5 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 -127, i32 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8 -128, i32 0, i32 110 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8 -128, i32 0, i32 111 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8 -128, i32 0, i32 86 }, %struct.option zeroinitializer]
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [5 x i8] c"note\00"
@.str.4 = [7 x i8] c"output\00"
@.str.5 = [8 x i8] c"version\00"
@.str.6 = [8 x i8] c"hn:o:V:\00"
@optarg = global i8* null
@.str.7 = [9 x i8] c"%d.%d.%d\00"
@stderr = global i32 0
@.str.8 = [23 x i8] c"Invalid version format\00"
@optind = global i32 0
@.str.9 = [29 x i8] c"file list must be specified\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
br label %11
11: ; preds = %34, %2
%12 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ], [ %35, %34 ]
%13 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %36, %34 ]
%14 = phi i32 [ 0, %2 ], [ %37, %34 ]
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%15 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %struct.option* getelementptr inbounds ([5 x %struct.option], [5 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %6)
switch i32 %15, label %32 [
i32 -1, label %38
i32 63, label %34
i32 110, label %16
i32 111, label %18
i32 86, label %20
]
16: ; preds = %11
%17 = load i8*, i8** @optarg
br label %34
18: ; preds = %11
%19 = load i8*, i8** @optarg
br label %34
20: ; preds = %11
%21 = load i8*, i8** @optarg
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%23 = icmp eq i32 %22, 3
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %32
27: ; preds = %20
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 @make_version(i32 %28, i32 %29, i32 %30)
br label %34
32: ; preds = %11, %24
%33 = call i32 (...) @usage()
br label %51
34: ; preds = %11, %16, %18, %27
%35 = phi i8* [ %12, %27 ], [ %12, %18 ], [ %17, %16 ], [ %12, %11 ]
%36 = phi i8* [ %13, %27 ], [ %19, %18 ], [ %13, %16 ], [ %13, %11 ]
%37 = phi i32 [ %31, %27 ], [ %14, %18 ], [ %14, %16 ], [ %14, %11 ]
br label %11
38: ; preds = %11
%39 = load i32, i32* @optind
%40 = icmp slt i32 %39, %0
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%44 = call i32 (...) @usage()
br label %51
45: ; preds = %38
%46 = sub nsw i32 %0, %39
%47 = sdiv i32 %46, 2
%48 = sext i32 %39 to i64
%49 = getelementptr inbounds i8*, i8** %1, i64 %48
%50 = call i32 @firmware_pack_encode(i32 %14, i32 %47, i8** %49, i8* %12, i8* %13)
br label %51
51: ; preds = %32, %45, %41
%52 = phi i32 [ -1, %41 ], [ 0, %45 ], [ -1, %32 ]
ret i32 %52
}