#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 */

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ slurp_path(char *, unsigned char **, size_t *, size_t *);
unsigned int strtoul(char *, char **, int);
int /*<<< orphan*/ write_blocks(unsigned char *, size_t, unsigned int);
int main(int argc, char *argv[]) {
  if (argc != 3)
    errx(1, "Usage: <file> <base>\n");
  char *tail;
  unsigned address = strtoul(argv[2], &tail, 16);
  if (*tail)
    errx(1, "Usage: <file> <base>\n");
  size_t offset = 0;
  size_t size = 0;
  unsigned char *data = NULL;
  slurp_path(argv[1], &data, &offset, &size);
  if (offset > 16) {
    write_blocks(data + 16, offset - 16, address + 16);
    write_blocks(data, 16, address);
  } else
    write_blocks(data, offset, address);
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     1171 <main+0x31>
mov    $0x1,%edi
lea    0xe94(%rip),%rsi
call   1030 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a8 <main+0x68>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1030 <errx@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <slurp_path@plt>
cmpq   $0x10,-0x28(%rbp)
jbe    1215 <main+0xd5>
mov    -0x38(%rbp),%rdi
add    $0x10,%rdi
mov    -0x28(%rbp),%rsi
sub    $0x10,%rsi
mov    -0x1c(%rbp),%edx
add    $0x10,%edx
call   1060 <write_blocks@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x10,%esi
call   1060 <write_blocks@plt>
jmp    1225 <main+0xe5>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <write_blocks@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     115f <main+0x1f>
lea    0xeab(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
mov    0x10(%rbx),%rdi
lea    0x20(%rsp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,%ebp
mov    0x20(%rsp),%rax
cmpb   $0x0,(%rax)
je     118f <main+0x4f>
lea    0xe7b(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1050 <slurp_path@plt>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
cmp    $0x11,%rsi
jb     11ee <main+0xae>
add    $0x10,%rdi
add    $0xfffffffffffffff0,%rsi
mov    %ebp,%edx
add    $0x10,%edx
call   1060 <write_blocks@plt>
mov    0x8(%rsp),%rdi
mov    $0x10,%esi
mov    %ebp,%edx
call   1060 <write_blocks@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: <file> <base>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @strtoul(i8* %18, i8** %6, i32 16)
store i32 %19, i32* %7
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %15
store i64 0, i64* %8
store i64 0, i64* %9
store i8* null, i8** %10
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @slurp_path(i8* %28, i8** %10, i64* %8, i64* %9)
%30 = load i64, i64* %8
%31 = icmp ugt i64 %30, 16
br i1 %31, label %32, label %43
32: ; preds = %25
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i64 16
%35 = load i64, i64* %8
%36 = sub i64 %35, 16
%37 = load i32, i32* %7
%38 = add i32 %37, 16
%39 = call i32 @write_blocks(i8* %34, i64 %36, i32 %38)
%40 = load i8*, i8** %10
%41 = load i32, i32* %7
%42 = call i32 @write_blocks(i8* %40, i64 16, i32 %41)
br label %48
43: ; preds = %25
%44 = load i8*, i8** %10
%45 = load i64, i64* %8
%46 = load i32, i32* %7
%47 = call i32 @write_blocks(i8* %44, i64 %45, i32 %46)
br label %48
48: ; preds = %43, %32
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage: <file> <base>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = bitcast i8** %3 to i8*
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @strtoul(i8* %13, i8** %3, i32 16)
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %10
%19 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %10
%21 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%22 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%23 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @slurp_path(i8* %25, i8** %6, i64* %4, i64* %5)
%27 = load i64, i64* %4
%28 = icmp ugt i64 %27, 16
%29 = load i8*, i8** %6
br i1 %28, label %30, label %37
30: ; preds = %20
%31 = getelementptr inbounds i8, i8* %29, i64 16
%32 = add i64 %27, -16
%33 = add i32 %14, 16
%34 = call i32 @write_blocks(i8* %31, i64 %32, i32 %33)
%35 = load i8*, i8** %6
%36 = call i32 @write_blocks(i8* %35, i64 16, i32 %14)
br label %39
37: ; preds = %20
%38 = call i32 @write_blocks(i8* %29, i64 %27, i32 %14)
br label %39
39: ; preds = %37, %30
ret i32 0
}