#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*/ member_1;
};

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int getopt_long(int, char **, char *, struct option *, int *);
#define no_argument 129
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
#define required_argument 128
int /*<<< orphan*/ splitFile(char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int offset = 0;
  char *offset_arg = NULL;
  int usealt = 0;
  char *dtb = NULL;
  int c;
  static struct option long_options[] = {
      {"offset", required_argument, NULL, 'o'},
      {"usealt", no_argument, NULL, 'a'},
      {NULL, 0, NULL, 0}};
  int option_index = 0;
  while ((c = getopt_long(argc, argv, "-ao:", long_options, &option_index)) !=
         -1) {
    switch (c) {
    case 'o':
      offset_arg = optarg;
      break;
    case 'a':
      usealt = 1;
      break;
    case 1:
      if (dtb == NULL) {
        dtb = optarg;
      } else {
        usage(argv[0]);
        exit(1);
      }
      break;
    case '?':
    default:
      printf("usage\n");
      usage(argv[0]);
      exit(1);
      break;
    }
  }
  if (dtb == NULL || argc == 1) {
    usage(argv[0]);
    exit(1);
  }
  if (offset_arg) {
    printf("Trying offset of %s\n", offset_arg);
    sscanf(offset_arg, "%x", &offset);
  }
  splitFile(dtb, offset, usealt);
  return EXIT_SUCCESS;
}


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   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdx
lea    0x2eb0(%rip),%rcx
lea    -0x38(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1292 <main+0x132>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x1,%eax
je     122b <main+0xcb>
jmp    11d9 <main+0x79>
mov    -0x3c(%rbp),%eax
sub    $0x3f,%eax
je     1264 <main+0x104>
jmp    11ea <main+0x8a>
mov    -0x3c(%rbp),%eax
sub    $0x61,%eax
je     121f <main+0xbf>
jmp    11fb <main+0x9b>
mov    -0x3c(%rbp),%eax
sub    $0x6f,%eax
jne    1269 <main+0x109>
jmp    120c <main+0xac>
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    128d <main+0x12d>
movl   $0x1,-0x24(%rbp)
jmp    128d <main+0x12d>
cmpq   $0x0,-0x30(%rbp)
jne    1249 <main+0xe9>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    125f <main+0xff>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    128d <main+0x12d>
jmp    1269 <main+0x109>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    119b <main+0x3b>
cmpq   $0x0,-0x30(%rbp)
je     12a7 <main+0x147>
cmpl   $0x1,-0x8(%rbp)
jne    12bd <main+0x15d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
je     12ee <main+0x18e>
mov    -0x20(%rbp),%rsi
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xd4a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1080 <splitFile@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
add    $0x40,%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,%r12
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x1c(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
lea    0xe6d(%rip),%r13
lea    0x2eb8(%rip),%r14
lea    0x1c(%rsp),%r15
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
jmp    11ca <main+0x5a>
nopl   0x0(%rax,%rax,1)
mov    0x2e31(%rip),%rax
mov    (%rax),%rbx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1040 <getopt_long@plt>
cmp    $0x6f,%eax
je     11c0 <main+0x50>
cmp    $0xffffffff,%eax
je     121e <main+0xae>
cmp    $0x1,%eax
je     1201 <main+0x91>
cmp    $0x61,%eax
jne    1284 <main+0x114>
mov    $0x1,%eax
mov    %rax,0x20(%rsp)
jmp    11ca <main+0x5a>
cmpq   $0x0,0x10(%rsp)
jne    1290 <main+0x120>
mov    0x2de4(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    11ca <main+0x5a>
cmp    $0x1,%ebp
mov    0x10(%rsp),%rbp
je     1290 <main+0x120>
test   %rbp,%rbp
je     1290 <main+0x120>
test   %rbx,%rbx
je     125d <main+0xed>
lea    0xdda(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdde(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%esi
jmp    125f <main+0xef>
xor    %esi,%esi
mov    %rbp,%rdi
mov    0x20(%rsp),%rdx
call   1090 <splitFile@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda0(%rip),%rdi
call   1030 <puts@plt>
mov    (%r12),%rdi
call   1070 <usage@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 111 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8 -127, i32* null, i32 97 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"offset\00"
@.str.1 = [7 x i8] c"usealt\00"
@.str.2 = [5 x i8] c"-ao:\00"
@optarg = global i8* null
@.str.3 = [7 x i8] c"usage\0A\00"
@.str.4 = [21 x i8] c"Trying offset of %s\0A\00"
@.str.5 = [3 x i8] c"%x\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i32 0, i32* %8
store i8* null, i8** %9
store i32 0, i32* %11
br label %12
12: ; preds = %42, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt_long(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %11)
store i32 %15, i32* %10
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %43
17: ; preds = %12
%18 = load i32, i32* %10
switch i32 %18, label %35 [
i32 111, label %19
i32 97, label %21
i32 1, label %22
i32 63, label %34
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %7
br label %42
21: ; preds = %17
store i32 1, i32* %8
br label %42
22: ; preds = %17
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i8*, i8** @optarg
store i8* %26, i8** %9
br label %33
27: ; preds = %22
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
br label %42
34: ; preds = %17
br label %35
35: ; preds = %17, %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @usage(i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33, %21, %19
br label %12
43: ; preds = %12
%44 = load i8*, i8** %9
%45 = icmp eq i8* %44, null
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %55
49: ; preds = %46, %43
%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 = call i32 @exit(i32 1)
unreachable
55: ; preds = %46
%56 = load i8*, i8** %7
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i8*, i8** %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = load i8*, i8** %7
%62 = call i32 @sscanf(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
br label %63
63: ; preds = %58, %55
%64 = load i8*, i8** %9
%65 = load i32, i32* %6
%66 = load i32, i32* %8
%67 = call i32 @splitFile(i8* %64, i32 %65, i32 %66)
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 111 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8 -127, i32* null, i32 97 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"offset\00"
@.str.1 = [7 x i8] c"usealt\00"
@.str.2 = [5 x i8] c"-ao:\00"
@optarg = global i8* null
@.str.4 = [21 x i8] c"Trying offset of %s\0A\00"
@.str.5 = [3 x i8] c"%x\00"
@EXIT_SUCCESS = global i32 0
@str = [6 x i8] c"usage\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %14, %2
%8 = phi i32 [ 0, %2 ], [ 1, %14 ]
%9 = phi i8* [ null, %2 ], [ %12, %14 ]
%10 = phi i8* [ null, %2 ], [ %15, %14 ]
br label %11
11: ; preds = %7, %21
%12 = phi i8* [ %9, %7 ], [ %22, %21 ]
%13 = phi i8* [ %10, %7 ], [ %15, %21 ]
br label %14
14: ; preds = %11, %17
%15 = phi i8* [ %18, %17 ], [ %13, %11 ]
%16 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %4)
switch i32 %16, label %27 [
i32 -1, label %32
i32 111, label %17
i32 97, label %7
i32 1, label %19
]
17: ; preds = %14
%18 = load i8*, i8** @optarg
br label %14
19: ; preds = %14
%20 = icmp eq i8* %12, null
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = load i8*, i8** @optarg
br label %11
23: ; preds = %19
%24 = load i8*, i8** %1
%25 = call i32 @usage(i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %14
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%29 = load i8*, i8** %1
%30 = call i32 @usage(i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %14
%33 = icmp eq i8* %12, null
%34 = icmp eq i32 %0, 1
%35 = or i1 %34, %33
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i8*, i8** %1
%38 = call i32 @usage(i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %32
%41 = icmp eq i8* %15, null
br i1 %41, label %46, label %42
42: ; preds = %40
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%44 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%45 = load i32, i32* %3
br label %46
46: ; preds = %42, %40
%47 = phi i32 [ %45, %42 ], [ 0, %40 ]
%48 = call i32 @splitFile(i8* %12, i32 %47, i32 %8)
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}