#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int convert_to_obj(unsigned int, unsigned int, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ die(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ parse_segment_range(unsigned int *, unsigned int *, int,
                                       char **);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  unsigned int start, end;
  int res;
  FILE *in, *out;
  if (argc < ((1 + 1) + 1))
    die("Bad arguments: %s <in> <out> [<start>] [<end>]", argv[0]);
  parse_segment_range(&start, &end, argc, argv);
  in = fopen(argv[1], "rb");
  if (!in)
    die("Failed to open input file: %s", strerror(errno));
  out = fopen(argv[(1 + 1)], "w");
  if (!out) {
    fclose(in);
    die("Failed to open output file: %s", strerror(errno));
  }
  printf("Starting conversion of segments %u-%u to %s\n", start, end,
         argv[(1 + 1)]);
  res = convert_to_obj(start, end, in, out);
  fclose(in);
  fclose(out);
  if (!res)
    die("Conversion failed");
  puts("Conversion successful");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <parse_segment_range@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121a <main+0x8a>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe27(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1264 <main+0xd4>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xdf8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1070 <convert_to_obj@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    12be <main+0x12e>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
lea    0xdeb(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
cmp    $0x2,%edi
jg     11b2 <main+0x22>
mov    (%r15),%rsi
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1090 <die@plt>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
mov    %r15,%rcx
call   1030 <parse_segment_range@plt>
mov    0x8(%r15),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11fa <main+0x6a>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe41(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <die@plt>
mov    0x10(%r15),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1238 <main+0xa8>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe23(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <die@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    0x10(%r15),%rcx
lea    0xe27(%rip),%rdi
call   1060 <printf@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1070 <convert_to_obj@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %ebp,%ebp
jne    1285 <main+0xf5>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1090 <die@plt>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Bad arguments: %s <in> <out> [<start>] [<end>]\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [30 x i8] c"Failed to open input file: %s\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"Failed to open output file: %s\00"
@.str.5 = [45 x i8] c"Starting conversion of segments %u-%u to %s\0A\00"
@.str.6 = [18 x i8] c"Conversion failed\00"
@.str.7 = [22 x i8] c"Conversion successful\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 i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %13, %2
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @parse_segment_range(i32* %6, i32* %7, i32 %19, i8** %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %9
%26 = load i32*, i32** %9
%27 = icmp ne i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %18
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
%31 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %18
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %10
%37 = load i32*, i32** %10
%38 = icmp ne i32* %37, null
br i1 %38, label %45, label %39
39: ; preds = %32
%40 = load i32*, i32** %9
%41 = call i32 @fclose(i32* %40)
%42 = load i32, i32* @errno
%43 = call i32 @strerror(i32 %42)
%44 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %39, %32
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %47, i8* %50)
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = load i32*, i32** %9
%55 = load i32*, i32** %10
%56 = call i32 @convert_to_obj(i32 %52, i32 %53, i32* %54, i32* %55)
store i32 %56, i32* %8
%57 = load i32*, i32** %9
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %10
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %8
%62 = icmp ne i32 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %45
%64 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %65
65: ; preds = %63, %45
%66 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
}

LLVM IR (-O2):
@.str = [47 x i8] c"Bad arguments: %s <in> <out> [<start>] [<end>]\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [30 x i8] c"Failed to open input file: %s\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"Failed to open output file: %s\00"
@.str.5 = [45 x i8] c"Starting conversion of segments %u-%u to %s\0A\00"
@.str.6 = [18 x i8] c"Conversion failed\00"
@.str.7 = [22 x i8] c"Conversion successful\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %2
%12 = call i32 @parse_segment_range(i32* %3, i32* %4, i32 %0, i8** %1)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %11
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = call i32 @fclose(i32* %15)
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %26, %21
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = load i8*, i8** %22
%35 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %32, i32 %33, i8* %34)
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = call i32 @convert_to_obj(i32 %36, i32 %37, i32* %15, i32* %24)
%39 = call i32 @fclose(i32* %15)
%40 = call i32 @fclose(i32* %24)
%41 = icmp eq i32 %38, 0
br i1 %41, label %42, label %44
42: ; preds = %31
%43 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %31
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* @EXIT_SUCCESS
%47 = call i32 @exit(i32 %46)
unreachable
}