#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 device_info {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ build_image(char const *, char const *, char const *,
                               unsigned int, int, int, struct device_info *);
int /*<<< orphan*/ convert_firmware(char const *, char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ extract_firmware(char const *, char const *);
struct device_info *find_board(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ set_source_date_epoch();
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  const char *board = NULL, *kernel_image = NULL, *rootfs_image = NULL,
             *output = NULL;
  const char *extract_image = NULL, *output_directory = NULL,
             *convert_image = NULL;
  bool add_jffs2_eof = false, sysupgrade = false;
  unsigned rev = 0;
  struct device_info *info;
  set_source_date_epoch();
  while (true) {
    int c;
    c = getopt(argc, argv, "B:k:r:o:V:jSh:x:d:z:");
    if (c == -1)
      break;
    switch (c) {
    case 'B':
      board = optarg;
      break;
    case 'k':
      kernel_image = optarg;
      break;
    case 'r':
      rootfs_image = optarg;
      break;
    case 'o':
      output = optarg;
      break;
    case 'V':
      sscanf(optarg, "r%u", &rev);
      break;
    case 'j':
      add_jffs2_eof = true;
      break;
    case 'S':
      sysupgrade = true;
      break;
    case 'h':
      usage(argv[0]);
      return 0;
    case 'd':
      output_directory = optarg;
      break;
    case 'x':
      extract_image = optarg;
      break;
    case 'z':
      convert_image = optarg;
      break;
    default:
      usage(argv[0]);
      return 1;
    }
  }
  if (extract_image || output_directory) {
    if (!extract_image)
      do {
        fprintf(stderr,
                "No factory/oem image given via -x <file>. Output directory is "
                "only valid with -x"
                ": %s\n",
                strerror(0));
        if (1)
          exit(1);
      } while (0);
    if (!output_directory)
      do {
        fprintf(
            stderr,
            "Can not extract an image without output directory. Use -d <dir>"
            ": %s\n",
            strerror(0));
        if (1)
          exit(1);
      } while (0);
    extract_firmware(extract_image, output_directory);
  } else if (convert_image) {
    if (!output)
      do {
        fprintf(stderr,
                "Can not convert a factory/oem image into sysupgrade image "
                "without output file. Use -o <file>"
                ": %s\n",
                strerror(0));
        if (1)
          exit(1);
      } while (0);
    convert_firmware(convert_image, output);
  } else {
    if (!board)
      do {
        fprintf(stderr,
                "no board has been specified"
                ": %s\n",
                strerror(0));
        if (1)
          exit(1);
      } while (0);
    if (!kernel_image)
      do {
        fprintf(stderr,
                "no kernel image has been specified"
                ": %s\n",
                strerror(0));
        if (1)
          exit(1);
      } while (0);
    if (!rootfs_image)
      do {
        fprintf(stderr,
                "no rootfs image has been specified"
                ": %s\n",
                strerror(0));
        if (1)
          exit(1);
      } while (0);
    if (!output)
      do {
        fprintf(stderr,
                "no output filename has been specified"
                ": %s\n",
                strerror(0));
        if (1)
          exit(1);
      } while (0);
    info = find_board(board);
    if (info == NULL)
      do {
        fprintf(stderr,
                "unsupported board %s"
                ": %s\n",
                board, strerror(0));
        if (1)
          exit(1);
      } while (0);
    build_image(output, kernel_image, rootfs_image, rev, add_jffs2_eof,
                sysupgrade, info);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    $0x0,%al
call   10d0 <set_source_date_epoch@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeb9(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1242 <main+0x92>
jmp    135c <main+0x1ac>
mov    -0x64(%rbp),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0x38,%eax
ja     133f <main+0x18f>
mov    -0x70(%rbp),%rax
lea    0xd9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d86(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1357 <main+0x1a7>
mov    0x2d73(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1357 <main+0x1a7>
mov    0x2d60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1357 <main+0x1a7>
mov    0x2d4d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1357 <main+0x1a7>
mov    0x2d3a(%rip),%rax
mov    (%rax),%rdi
lea    0xe31(%rip),%rsi
lea    -0x54(%rbp),%rdx
call   1070 <sscanf@plt>
jmp    1357 <main+0x1a7>
movl   $0x1,-0x4c(%rbp)
jmp    1357 <main+0x1a7>
movl   $0x1,-0x50(%rbp)
jmp    1357 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1610 <main+0x460>
mov    0x2ceb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1357 <main+0x1a7>
mov    0x2cd8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1357 <main+0x1a7>
mov    0x2cc5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1357 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1610 <main+0x460>
jmp    121d <main+0x6d>
cmpq   $0x0,-0x38(%rbp)
jne    1372 <main+0x1c2>
cmpq   $0x0,-0x40(%rbp)
je     1406 <main+0x256>
cmpq   $0x0,-0x38(%rbp)
jne    13b3 <main+0x203>
jmp    1382 <main+0x1d2>
mov    0x2c4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jne    13f4 <main+0x244>
jmp    13c3 <main+0x213>
mov    0x2c0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    %rax,%rdx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <extract_firmware@plt>
jmp    1609 <main+0x459>
cmpq   $0x0,-0x48(%rbp)
je     1464 <main+0x2b4>
cmpq   $0x0,-0x30(%rbp)
jne    1452 <main+0x2a2>
jmp    1421 <main+0x271>
mov    0x2bb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rdx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <convert_firmware@plt>
jmp    1604 <main+0x454>
cmpq   $0x0,-0x18(%rbp)
jne    14a5 <main+0x2f5>
jmp    1474 <main+0x2c4>
mov    0x2b5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rdx
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    14ec <main+0x33c>
jmp    14b5 <main+0x305>
mov    0x2b1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rdx
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1533 <main+0x383>
jmp    14fc <main+0x34c>
mov    0x2ad5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    157a <main+0x3ca>
jmp    1543 <main+0x393>
mov    0x2a8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xd02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1080 <find_board@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    15e0 <main+0x430>
jmp    1597 <main+0x3e7>
mov    0x2a3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x98(%rbp)
xor    %edi,%edi
call   10c0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    %rax,%rcx
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    -0x50(%rbp),%r9d
mov    -0x60(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <build_image@plt>
jmp    1609 <main+0x459>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%r12d
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
mov    %rax,0x28(%rsp)
xor    %eax,%eax
call   10d0 <set_source_date_epoch@plt>
lea    0xf03(%rip),%rbp
lea    0xe18(%rip),%r15
mov    0x2e09(%rip),%r14
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x40(%rsp)
xor    %eax,%eax
mov    %rax,0x38(%rsp)
xor    %eax,%eax
mov    %rax,0x30(%rsp)
xor    %eax,%eax
movl   $0x0,0x8(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
jmp    1230 <main+0x80>
mov    (%r14),%rax
mov    %rax,0x20(%rsp)
mov    %r13d,%eax
mov    %eax,%r13d
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   10a0 <getopt@plt>
lea    -0x42(%rax),%ecx
cmp    $0x38,%ecx
ja     12d8 <main+0x128>
mov    $0x1,%eax
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    (%r14),%rax
mov    %rax,0x18(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
movl   $0x1,0x8(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
mov    (%r14),%rdi
lea    0xe7a(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
mov    %r13d,%eax
jmp    1230 <main+0x80>
mov    (%r14),%rax
mov    %rax,0x38(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
mov    (%r14),%rax
mov    %rax,0x28(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
mov    (%r14),%rax
mov    %rax,0x10(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
mov    (%r14),%rax
mov    %rax,0x40(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
mov    (%r14),%rax
mov    %rax,0x30(%rsp)
mov    %r13d,%eax
jmp    1230 <main+0x80>
cmp    $0xffffffff,%eax
jne    1308 <main+0x158>
mov    0x40(%rsp),%rdi
mov    %rdi,%rax
mov    0x38(%rsp),%rsi
or     %rsi,%rax
je     1330 <main+0x180>
test   %rdi,%rdi
je     13bb <main+0x20b>
test   %rsi,%rsi
je     13d7 <main+0x227>
call   1030 <extract_firmware@plt>
jmp    131f <main+0x16f>
mov    (%rbx),%rdi
call   1090 <usage@plt>
mov    $0x1,%eax
jmp    1321 <main+0x171>
mov    (%rbx),%rdi
call   1090 <usage@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x30(%rsp),%rdi
test   %rdi,%rdi
je     134f <main+0x19f>
mov    0x10(%rsp),%rsi
test   %rsi,%rsi
je     13f0 <main+0x240>
call   1050 <convert_firmware@plt>
jmp    131f <main+0x16f>
mov    0x18(%rsp),%r15
test   %r15,%r15
mov    0x10(%rsp),%r14
je     1409 <main+0x259>
mov    0x28(%rsp),%rbx
test   %rbx,%rbx
mov    0x20(%rsp),%rbp
je     1422 <main+0x272>
test   %rbp,%rbp
je     143b <main+0x28b>
test   %r14,%r14
je     1454 <main+0x2a4>
mov    %r15,%rdi
call   1080 <find_board@plt>
test   %rax,%rax
je     1481 <main+0x2d1>
mov    0xc(%rsp),%ecx
mov    %rax,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r13d,%r8d
mov    0x8(%rsp),%r9d
call   1040 <build_image@plt>
jmp    131f <main+0x16f>
mov    0x2c16(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xd2b(%rip),%rsi
jmp    146b <main+0x2bb>
mov    0x2bfa(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xd65(%rip),%rsi
jmp    146b <main+0x2bb>
mov    0x2be1(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xd91(%rip),%rsi
jmp    146b <main+0x2bb>
mov    0x2bc8(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xdda(%rip),%rsi
jmp    146b <main+0x2bb>
mov    0x2baf(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xde2(%rip),%rsi
jmp    146b <main+0x2bb>
mov    0x2b96(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xdf1(%rip),%rsi
jmp    146b <main+0x2bb>
mov    0x2b7d(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xe00(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10c0 <strerror@plt>
lea    0xdfe(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.device_info = type { i32 }
@.str = [21 x i8] c"B:k:r:o:V:jSh:x:d:z:\00"
@optarg = global i8* null
@.str.1 = [4 x i8] c"r%u\00"
@stderr = global i32 0
@.str.2 = [86 x i8] c"No factory/oem image given via -x <file>. Output directory is only valid with -x: %s\0A\00"
@.str.3 = [69 x i8] c"Can not extract an image without output directory. Use -d <dir>: %s\0A\00"
@.str.4 = [98 x i8] c"Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>: %s\0A\00"
@.str.5 = [33 x i8] c"no board has been specified: %s\0A\00"
@.str.6 = [40 x i8] c"no kernel image has been specified: %s\0A\00"
@.str.7 = [40 x i8] c"no rootfs image has been specified: %s\0A\00"
@.str.8 = [43 x i8] c"no output filename has been specified: %s\0A\00"
@.str.9 = [26 x i8] c"unsupported board %s: %s\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 i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.device_info*
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i8* null, i8** %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%18 = call i32 (...) @set_source_date_epoch()
br label %19
19: ; preds = %2, %57
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %17
%23 = load i32, i32* %17
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %19
br label %58
26: ; preds = %19
%27 = load i32, i32* %17
switch i32 %27, label %52 [
i32 66, label %28
i32 107, label %30
i32 114, label %32
i32 111, label %34
i32 86, label %36
i32 106, label %39
i32 83, label %40
i32 104, label %41
i32 100, label %46
i32 120, label %48
i32 122, label %50
]
28: ; preds = %26
%29 = load i8*, i8** @optarg
store i8* %29, i8** %6
br label %57
30: ; preds = %26
%31 = load i8*, i8** @optarg
store i8* %31, i8** %7
br label %57
32: ; preds = %26
%33 = load i8*, i8** @optarg
store i8* %33, i8** %8
br label %57
34: ; preds = %26
%35 = load i8*, i8** @optarg
store i8* %35, i8** %9
br label %57
36: ; preds = %26
%37 = load i8*, i8** @optarg
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %15)
br label %57
39: ; preds = %26
store i32 1, i32* %13
br label %57
40: ; preds = %26
store i32 1, i32* %14
br label %57
41: ; preds = %26
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @usage(i8* %44)
store i32 0, i32* %3
br label %169
46: ; preds = %26
%47 = load i8*, i8** @optarg
store i8* %47, i8** %11
br label %57
48: ; preds = %26
%49 = load i8*, i8** @optarg
store i8* %49, i8** %10
br label %57
50: ; preds = %26
%51 = load i8*, i8** @optarg
store i8* %51, i8** %12
br label %57
52: ; preds = %26
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @usage(i8* %55)
store i32 1, i32* %3
br label %169
57: ; preds = %50, %48, %46, %40, %39, %36, %34, %32, %30, %28
br label %19
58: ; preds = %25
%59 = load i8*, i8** %10
%60 = icmp ne i8* %59, null
br i1 %60, label %64, label %61
61: ; preds = %58
%62 = load i8*, i8** %11
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %88
64: ; preds = %61, %58
%65 = load i8*, i8** %10
%66 = icmp ne i8* %65, null
br i1 %66, label %74, label %67
67: ; preds = %64
br label %68
68: ; preds = %67
%69 = load i32, i32* @stderr
%70 = call i8* @strerror(i32 0)
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), i8* %70)
%72 = call i32 @exit(i32 1)
unreachable
73: ; No predecessors!
br label %74
74: ; preds = %73, %64
%75 = load i8*, i8** %11
%76 = icmp ne i8* %75, null
br i1 %76, label %84, label %77
77: ; preds = %74
br label %78
78: ; preds = %77
%79 = load i32, i32* @stderr
%80 = call i8* @strerror(i32 0)
%81 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), i8* %80)
%82 = call i32 @exit(i32 1)
unreachable
83: ; No predecessors!
br label %84
84: ; preds = %83, %74
%85 = load i8*, i8** %10
%86 = load i8*, i8** %11
%87 = call i32 @extract_firmware(i8* %85, i8* %86)
br label %168
88: ; preds = %61
%89 = load i8*, i8** %12
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %105
91: ; preds = %88
%92 = load i8*, i8** %9
%93 = icmp ne i8* %92, null
br i1 %93, label %101, label %94
94: ; preds = %91
br label %95
95: ; preds = %94
%96 = load i32, i32* @stderr
%97 = call i8* @strerror(i32 0)
%98 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.4, i64 0, i64 0), i8* %97)
%99 = call i32 @exit(i32 1)
unreachable
100: ; No predecessors!
br label %101
101: ; preds = %100, %91
%102 = load i8*, i8** %12
%103 = load i8*, i8** %9
%104 = call i32 @convert_firmware(i8* %102, i8* %103)
br label %167
105: ; preds = %88
%106 = load i8*, i8** %6
%107 = icmp ne i8* %106, null
br i1 %107, label %115, label %108
108: ; preds = %105
br label %109
109: ; preds = %108
%110 = load i32, i32* @stderr
%111 = call i8* @strerror(i32 0)
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; No predecessors!
br label %115
115: ; preds = %114, %105
%116 = load i8*, i8** %7
%117 = icmp ne i8* %116, null
br i1 %117, label %125, label %118
118: ; preds = %115
br label %119
119: ; preds = %118
%120 = load i32, i32* @stderr
%121 = call i8* @strerror(i32 0)
%122 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %121)
%123 = call i32 @exit(i32 1)
unreachable
124: ; No predecessors!
br label %125
125: ; preds = %124, %115
%126 = load i8*, i8** %8
%127 = icmp ne i8* %126, null
br i1 %127, label %135, label %128
128: ; preds = %125
br label %129
129: ; preds = %128
%130 = load i32, i32* @stderr
%131 = call i8* @strerror(i32 0)
%132 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %131)
%133 = call i32 @exit(i32 1)
unreachable
134: ; No predecessors!
br label %135
135: ; preds = %134, %125
%136 = load i8*, i8** %9
%137 = icmp ne i8* %136, null
br i1 %137, label %145, label %138
138: ; preds = %135
br label %139
139: ; preds = %138
%140 = load i32, i32* @stderr
%141 = call i8* @strerror(i32 0)
%142 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %140, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* %141)
%143 = call i32 @exit(i32 1)
unreachable
144: ; No predecessors!
br label %145
145: ; preds = %144, %135
%146 = load i8*, i8** %6
%147 = call %struct.device_info* @find_board(i8* %146)
store %struct.device_info* %147, %struct.device_info** %16
%148 = load %struct.device_info*, %struct.device_info** %16
%149 = icmp eq %struct.device_info* %148, null
br i1 %149, label %150, label %158
150: ; preds = %145
br label %151
151: ; preds = %150
%152 = load i32, i32* @stderr
%153 = load i8*, i8** %6
%154 = call i8* @strerror(i32 0)
%155 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %153, i8* %154)
%156 = call i32 @exit(i32 1)
unreachable
157: ; No predecessors!
br label %158
158: ; preds = %157, %145
%159 = load i8*, i8** %9
%160 = load i8*, i8** %7
%161 = load i8*, i8** %8
%162 = load i32, i32* %15
%163 = load i32, i32* %13
%164 = load i32, i32* %14
%165 = load %struct.device_info*, %struct.device_info** %16
%166 = call i32 @build_image(i8* %159, i8* %160, i8* %161, i32 %162, i32 %163, i32 %164, %struct.device_info* %165)
br label %167
167: ; preds = %158, %101
br label %168
168: ; preds = %167, %84
store i32 0, i32* %3
br label %169
169: ; preds = %168, %52, %41
%170 = load i32, i32* %3
ret i32 %170
}

LLVM IR (-O2):
%struct.device_info = type { i32 }
@.str = [21 x i8] c"B:k:r:o:V:jSh:x:d:z:\00"
@optarg = global i8* null
@.str.1 = [4 x i8] c"r%u\00"
@stderr = global i32 0
@.str.2 = [86 x i8] c"No factory/oem image given via -x <file>. Output directory is only valid with -x: %s\0A\00"
@.str.3 = [69 x i8] c"Can not extract an image without output directory. Use -d <dir>: %s\0A\00"
@.str.4 = [98 x i8] c"Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>: %s\0A\00"
@.str.5 = [33 x i8] c"no board has been specified: %s\0A\00"
@.str.6 = [40 x i8] c"no kernel image has been specified: %s\0A\00"
@.str.7 = [40 x i8] c"no rootfs image has been specified: %s\0A\00"
@.str.8 = [43 x i8] c"no output filename has been specified: %s\0A\00"
@.str.9 = [26 x i8] c"unsupported board %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 (...) @set_source_date_epoch()
br label %6
6: ; preds = %19, %2
%7 = phi i8* [ null, %2 ], [ %20, %19 ]
%8 = phi i8* [ null, %2 ], [ %21, %19 ]
%9 = phi i8* [ null, %2 ], [ %22, %19 ]
%10 = phi i8* [ null, %2 ], [ %23, %19 ]
%11 = phi i8* [ null, %2 ], [ %24, %19 ]
%12 = phi i8* [ null, %2 ], [ %25, %19 ]
%13 = phi i32 [ 0, %2 ], [ %26, %19 ]
%14 = phi i32 [ 0, %2 ], [ %27, %19 ]
%15 = phi i8* [ null, %2 ], [ %28, %19 ]
%16 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
switch i32 %16, label %48 [
i32 -1, label %51
i32 66, label %17
i32 107, label %29
i32 114, label %31
i32 111, label %33
i32 86, label %35
i32 106, label %19
i32 83, label %38
i32 104, label %39
i32 100, label %42
i32 120, label %44
i32 122, label %46
]
17: ; preds = %6
%18 = load i8*, i8** @optarg
br label %19
19: ; preds = %17, %29, %31, %33, %35, %38, %42, %44, %46, %6
%20 = phi i8* [ %7, %46 ], [ %7, %44 ], [ %7, %42 ], [ %7, %38 ], [ %7, %35 ], [ %7, %33 ], [ %7, %31 ], [ %30, %29 ], [ %7, %17 ], [ %7, %6 ]
%21 = phi i8* [ %8, %46 ], [ %8, %44 ], [ %8, %42 ], [ %8, %38 ], [ %8, %35 ], [ %8, %33 ], [ %32, %31 ], [ %8, %29 ], [ %8, %17 ], [ %8, %6 ]
%22 = phi i8* [ %9, %46 ], [ %9, %44 ], [ %9, %42 ], [ %9, %38 ], [ %9, %35 ], [ %34, %33 ], [ %9, %31 ], [ %9, %29 ], [ %9, %17 ], [ %9, %6 ]
%23 = phi i8* [ %10, %46 ], [ %45, %44 ], [ %10, %42 ], [ %10, %38 ], [ %10, %35 ], [ %10, %33 ], [ %10, %31 ], [ %10, %29 ], [ %10, %17 ], [ %10, %6 ]
%24 = phi i8* [ %11, %46 ], [ %11, %44 ], [ %43, %42 ], [ %11, %38 ], [ %11, %35 ], [ %11, %33 ], [ %11, %31 ], [ %11, %29 ], [ %11, %17 ], [ %11, %6 ]
%25 = phi i8* [ %47, %46 ], [ %12, %44 ], [ %12, %42 ], [ %12, %38 ], [ %12, %35 ], [ %12, %33 ], [ %12, %31 ], [ %12, %29 ], [ %12, %17 ], [ %12, %6 ]
%26 = phi i32 [ %13, %46 ], [ %13, %44 ], [ %13, %42 ], [ %13, %38 ], [ %13, %35 ], [ %13, %33 ], [ %13, %31 ], [ %13, %29 ], [ %13, %17 ], [ 1, %6 ]
%27 = phi i32 [ %14, %46 ], [ %14, %44 ], [ %14, %42 ], [ 1, %38 ], [ %14, %35 ], [ %14, %33 ], [ %14, %31 ], [ %14, %29 ], [ %14, %17 ], [ %14, %6 ]
%28 = phi i8* [ %15, %46 ], [ %15, %44 ], [ %15, %42 ], [ %15, %38 ], [ %15, %35 ], [ %15, %33 ], [ %15, %31 ], [ %15, %29 ], [ %18, %17 ], [ %15, %6 ]
br label %6
29: ; preds = %6
%30 = load i8*, i8** @optarg
br label %19
31: ; preds = %6
%32 = load i8*, i8** @optarg
br label %19
33: ; preds = %6
%34 = load i8*, i8** @optarg
br label %19
35: ; preds = %6
%36 = load i8*, i8** @optarg
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %19
38: ; preds = %6
br label %19
39: ; preds = %6
%40 = load i8*, i8** %1
%41 = call i32 @usage(i8* %40)
br label %119
42: ; preds = %6
%43 = load i8*, i8** @optarg
br label %19
44: ; preds = %6
%45 = load i8*, i8** @optarg
br label %19
46: ; preds = %6
%47 = load i8*, i8** @optarg
br label %19
48: ; preds = %6
%49 = load i8*, i8** %1
%50 = call i32 @usage(i8* %49)
br label %119
51: ; preds = %6
%52 = icmp ne i8* %10, null
%53 = icmp ne i8* %11, null
%54 = select i1 %52, i1 true, i1 %53
br i1 %54, label %55, label %69
55: ; preds = %51
br i1 %52, label %61, label %56
56: ; preds = %55
%57 = load i32, i32* @stderr
%58 = call i8* @strerror(i32 0)
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %55
br i1 %53, label %67, label %62
62: ; preds = %61
%63 = load i32, i32* @stderr
%64 = call i8* @strerror(i32 0)
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %61
%68 = call i32 @extract_firmware(i8* %10, i8* %11)
br label %119
69: ; preds = %51
%70 = icmp eq i8* %12, null
br i1 %70, label %80, label %71
71: ; preds = %69
%72 = icmp eq i8* %9, null
br i1 %72, label %73, label %78
73: ; preds = %71
%74 = load i32, i32* @stderr
%75 = call i8* @strerror(i32 0)
%76 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.4, i64 0, i64 0), i8* %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %71
%79 = call i32 @convert_firmware(i8* %12, i8* %9)
br label %119
80: ; preds = %69
%81 = icmp eq i8* %15, null
br i1 %81, label %82, label %87
82: ; preds = %80
%83 = load i32, i32* @stderr
%84 = call i8* @strerror(i32 0)
%85 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %84)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %80
%88 = icmp eq i8* %7, null
br i1 %88, label %89, label %94
89: ; preds = %87
%90 = load i32, i32* @stderr
%91 = call i8* @strerror(i32 0)
%92 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %91)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %87
%95 = icmp eq i8* %8, null
br i1 %95, label %96, label %101
96: ; preds = %94
%97 = load i32, i32* @stderr
%98 = call i8* @strerror(i32 0)
%99 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %94
%102 = icmp eq i8* %9, null
br i1 %102, label %103, label %108
103: ; preds = %101
%104 = load i32, i32* @stderr
%105 = call i8* @strerror(i32 0)
%106 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* %105)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %101
%109 = call %struct.device_info* @find_board(i8* %15)
%110 = icmp eq %struct.device_info* %109, null
br i1 %110, label %111, label %116
111: ; preds = %108
%112 = load i32, i32* @stderr
%113 = call i8* @strerror(i32 0)
%114 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %15, i8* %113)
%115 = call i32 @exit(i32 1)
unreachable
116: ; preds = %108
%117 = load i32, i32* %3
%118 = call i32 @build_image(i8* %9, i8* %7, i8* %8, i32 %117, i32 %13, i32 %14, %struct.device_info* %109)
br label %119
119: ; preds = %39, %48, %67, %116, %78
%120 = phi i32 [ 0, %78 ], [ 0, %116 ], [ 0, %67 ], [ 0, %39 ], [ 1, %48 ]
ret i32 %120
}