#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 stat {
  unsigned int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fstat(int, struct stat *);
int getopt(int, char **, char *);
unsigned int lseek(int, unsigned int, int /*<<< orphan*/);
char *malloc(unsigned int);
int open(char *, int /*<<< orphan*/);
char *optarg;
int optind;
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ usage(int /*<<< orphan*/, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char *device, *file, *buf;
  unsigned int offset;
  struct stat st;
  int ifd, ofd, c;
  device = "/dev/spi";
  file = NULL;
  offset = 0;
  while ((c = getopt(argc, argv, "?ho:d:")) > 0) {
    switch (c) {
    case 'd':
      device = optarg;
      break;
    case 'o':
      offset = strtoul(optarg, NULL, 0);
      break;
    case 'h':
    case '?':
      usage(stdout, 0);
      break;
    default:
      fprintf(stderr, "ERROR: unkown option '%c'\n", c);
      usage(stderr, 1);
      break;
    }
  }
  if (optind != (argc - 1)) {
    fprintf(stderr, "ERROR: need file to load\n");
    usage(stderr, 1);
  }
  file = argv[optind];
  if ((ifd = open(file, O_RDONLY)) < 0) {
    fprintf(stderr, "ERROR: failed to open %s, %s\n", file, strerror(errno));
    exit(1);
  }
  fstat(ifd, &st);
  if ((ofd = open(device, O_WRONLY)) < 0) {
    fprintf(stderr, "ERROR: failed to open %s, %s\n", device, strerror(errno));
    exit(1);
  }
  if (offset) {
    if (lseek(ofd, offset, SEEK_SET) != offset) {
      fprintf(stderr,
              "ERROR: failed to seek to offset %d, "
              "%s\n",
              offset, strerror(errno));
      exit(1);
    }
  }
  if ((buf = malloc(st.st_size)) == NULL) {
    fprintf(stderr, "ERROR: failed to malloc(%d), %s\n", st.st_size,
            strerror(errno));
    exit(1);
  }
  if (read(ifd, buf, st.st_size) != st.st_size) {
    fprintf(stderr, "ERROR: failed to read(%d), %s\n", st.st_size,
            strerror(errno));
    exit(1);
  }
  if (write(ofd, buf, st.st_size) != st.st_size) {
    fprintf(stderr, "ERROR: failed to write(%d), %s\n", st.st_size,
            strerror(errno));
    exit(1);
  }
  close(ofd);
  close(ifd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdf8(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jle    12e0 <main+0x110>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x3f,%eax
je     1299 <main+0xc9>
jmp    1236 <main+0x66>
mov    -0x40(%rbp),%eax
sub    $0x64,%eax
je     1269 <main+0x99>
jmp    1247 <main+0x77>
mov    -0x40(%rbp),%eax
sub    $0x68,%eax
je     1299 <main+0xc9>
jmp    1258 <main+0x88>
mov    -0x40(%rbp),%eax
sub    $0x6f,%eax
je     127c <main+0xac>
jmp    12ae <main+0xde>
mov    0x2d88(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12db <main+0x10b>
mov    0x2d75(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
jmp    12db <main+0x10b>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1090 <usage@plt>
jmp    12db <main+0x10b>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1090 <usage@plt>
jmp    1203 <main+0x33>
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1321 <main+0x151>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2cac(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2c9e(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1399 <main+0x1c9>
mov    0x2c6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10f0 <fstat@plt>
mov    -0x18(%rbp),%rdi
mov    0x2bf0(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    1407 <main+0x237>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1474 <main+0x2a4>
mov    -0x38(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    0x2b9a(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    -0x2c(%rbp),%eax
je     146f <main+0x29f>
mov    0x2b93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%edx
mov    %rax,%rcx
lea    0xc05(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1474 <main+0x2a4>
mov    -0x30(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    14cb <main+0x2fb>
mov    0x2b37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2b1d(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%edx
mov    %rax,%rcx
lea    0xbd1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1060 <read@plt>
cmp    -0x30(%rbp),%eax
je     1524 <main+0x354>
mov    0x2ade(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2ac4(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%edx
mov    %rax,%rcx
lea    0xb99(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <write@plt>
cmp    -0x30(%rbp),%eax
je     157d <main+0x3ad>
mov    0x2a85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    0x2a6b(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%edx
mov    %rax,%rcx
lea    0xb5f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe1f(%rip),%rdx
call   10b0 <getopt@plt>
test   %eax,%eax
jle    12ad <main+0xdd>
lea    0xe02(%rip),%rcx
mov    %rcx,0x8(%rsp)
mov    0x2dee(%rip),%r13
mov    0x2d9f(%rip),%r14
lea    0xdf1(%rip),%r12
mov    0x2da9(%rip),%r15
movl   $0x0,0x4(%rsp)
jmp    124b <main+0x7b>
nopl   0x0(%rax)
mov    (%r14),%edi
xor    %esi,%esi
call   1090 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10b0 <getopt@plt>
test   %eax,%eax
jle    12c1 <main+0xf1>
cmp    $0x67,%eax
jg     1270 <main+0xa0>
cmp    $0x3f,%eax
je     1230 <main+0x60>
cmp    $0x64,%eax
jne    1290 <main+0xc0>
mov    0x0(%r13),%rax
mov    %rax,0x8(%rsp)
jmp    123a <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x68,%eax
je     1230 <main+0x60>
cmp    $0x6f,%eax
jne    1290 <main+0xc0>
mov    0x0(%r13),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %eax,0x4(%rsp)
jmp    123a <main+0x6a>
nopl   (%rax)
mov    (%r15),%edi
lea    0xd76(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
mov    $0x1,%esi
jmp    1235 <main+0x65>
lea    0xd4c(%rip),%rax
mov    %rax,0x8(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x2d10(%rip),%r14
mov    (%r14),%eax
add    $0xffffffff,%ebp
cmp    %ebp,%eax
je     12fa <main+0x12a>
mov    0x2cef(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd48(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    $0x1,%esi
call   1090 <usage@plt>
mov    (%r14),%eax
cltq
mov    (%rbx,%rax,8),%rbx
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     13ce <main+0x1fe>
mov    %eax,%r12d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   10f0 <fstat@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     13f3 <main+0x223>
mov    %eax,%r13d
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
je     136c <main+0x19c>
mov    0x2c60(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
cmp    %ebp,%eax
jne    14a0 <main+0x2d0>
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     142a <main+0x25a>
mov    %rax,%rbp
mov    %r12d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1060 <read@plt>
cmp    %ebx,%eax
jne    144a <main+0x27a>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
jne    146a <main+0x29a>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf3(%rip),%rax
mov    (%rax),%ebp
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc59(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
jmp    1416 <main+0x246>
mov    0x2bce(%rip),%rax
mov    (%rax),%ebx
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc34(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%ebp
mov    0x2b86(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc43(%rip),%rsi
jmp    1488 <main+0x2b8>
mov    0x2b77(%rip),%rax
mov    (%rax),%ebp
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc44(%rip),%rsi
jmp    1488 <main+0x2b8>
mov    0x2b57(%rip),%rax
mov    (%rax),%ebp
mov    0x2b46(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc43(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2b21(%rip),%rax
mov    (%rax),%ebx
mov    0x2b10(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xba5(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
jmp    148c <main+0x2bc>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/dev/spi\00"
@.str.1 = [7 x i8] c"?ho:d:\00"
@optarg = global i8* null
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [27 x i8] c"ERROR: unkown option '%c'\0A\00"
@optind = global i32 0
@.str.3 = [26 x i8] c"ERROR: need file to load\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [30 x i8] c"ERROR: failed to open %s, %s\0A\00"
@errno = global i32 0
@O_WRONLY = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [40 x i8] c"ERROR: failed to seek to offset %d, %s\0A\00"
@.str.6 = [33 x i8] c"ERROR: failed to malloc(%d), %s\0A\00"
@.str.7 = [31 x i8] c"ERROR: failed to read(%d), %s\0A\00"
@.str.8 = [32 x i8] c"ERROR: failed to write(%d), %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 i32
%10 = alloca %struct.stat
%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 ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* null, i8** %7
store i32 0, i32* %9
br label %14
14: ; preds = %35, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %17, i32* %13
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %14
%20 = load i32, i32* %13
switch i32 %20, label %29 [
i32 100, label %21
i32 111, label %23
i32 104, label %26
i32 63, label %26
]
21: ; preds = %19
%22 = load i8*, i8** @optarg
store i8* %22, i8** %6
br label %35
23: ; preds = %19
%24 = load i8*, i8** @optarg
%25 = call i32 @strtoul(i8* %24, i32* null, i32 0)
store i32 %25, i32* %9
br label %35
26: ; preds = %19, %19
%27 = load i32, i32* @stdout
%28 = call i32 @usage(i32 %27, i32 0)
br label %35
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = load i32, i32* %13
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @stderr
%34 = call i32 @usage(i32 %33, i32 1)
br label %35
35: ; preds = %29, %26, %23, %21
br label %14
36: ; preds = %14
%37 = load i32, i32* @optind
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 1
%40 = icmp ne i32 %37, %39
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* @stderr
%45 = call i32 @usage(i32 %44, i32 1)
br label %46
46: ; preds = %41, %36
%47 = load i8**, i8*** %5
%48 = load i32, i32* @optind
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = load i32, i32* @O_RDONLY
%54 = call i32 @open(i8* %52, i32 %53)
store i32 %54, i32* %11
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %46
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %7
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %58, i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %46
%64 = load i32, i32* %11
%65 = call i32 @fstat(i32 %64, %struct.stat* %10)
%66 = load i8*, i8** %6
%67 = load i32, i32* @O_WRONLY
%68 = call i32 @open(i8* %66, i32 %67)
store i32 %68, i32* %12
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %63
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %6
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %72, i8* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %63
%78 = load i32, i32* %9
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %95
80: ; preds = %77
%81 = load i32, i32* %12
%82 = load i32, i32* %9
%83 = load i32, i32* @SEEK_SET
%84 = call i32 @lseek(i32 %81, i32 %82, i32 %83)
%85 = load i32, i32* %9
%86 = icmp ne i32 %84, %85
br i1 %86, label %87, label %94
87: ; preds = %80
%88 = load i32, i32* @stderr
%89 = load i32, i32* %9
%90 = load i32, i32* @errno
%91 = call i8* @strerror(i32 %90)
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %89, i8* %91)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %80
br label %95
95: ; preds = %94, %77
%96 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%97 = load i32, i32* %96
%98 = call i8* @malloc(i32 %97)
store i8* %98, i8** %8
%99 = icmp eq i8* %98, null
br i1 %99, label %100, label %108
100: ; preds = %95
%101 = load i32, i32* @stderr
%102 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%103 = load i32, i32* %102
%104 = load i32, i32* @errno
%105 = call i8* @strerror(i32 %104)
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %103, i8* %105)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %95
%109 = load i32, i32* %11
%110 = load i8*, i8** %8
%111 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i32 @read(i32 %109, i8* %110, i32 %112)
%114 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%115 = load i32, i32* %114
%116 = icmp ne i32 %113, %115
br i1 %116, label %117, label %125
117: ; preds = %108
%118 = load i32, i32* @stderr
%119 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%120 = load i32, i32* %119
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %120, i8* %122)
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %108
%126 = load i32, i32* %12
%127 = load i8*, i8** %8
%128 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%129 = load i32, i32* %128
%130 = call i32 @write(i32 %126, i8* %127, i32 %129)
%131 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%132 = load i32, i32* %131
%133 = icmp ne i32 %130, %132
br i1 %133, label %134, label %142
134: ; preds = %125
%135 = load i32, i32* @stderr
%136 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%137 = load i32, i32* %136
%138 = load i32, i32* @errno
%139 = call i8* @strerror(i32 %138)
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %137, i8* %139)
%141 = call i32 @exit(i32 1)
unreachable
142: ; preds = %125
%143 = load i32, i32* %12
%144 = call i32 @close(i32 %143)
%145 = load i32, i32* %11
%146 = call i32 @close(i32 %145)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/dev/spi\00"
@.str.1 = [7 x i8] c"?ho:d:\00"
@optarg = global i8* null
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [27 x i8] c"ERROR: unkown option '%c'\0A\00"
@optind = global i32 0
@.str.3 = [26 x i8] c"ERROR: need file to load\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [30 x i8] c"ERROR: failed to open %s, %s\0A\00"
@errno = global i32 0
@O_WRONLY = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [40 x i8] c"ERROR: failed to seek to offset %d, %s\0A\00"
@.str.6 = [33 x i8] c"ERROR: failed to malloc(%d), %s\0A\00"
@.str.7 = [31 x i8] c"ERROR: failed to read(%d), %s\0A\00"
@.str.8 = [32 x i8] c"ERROR: failed to write(%d), %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %2, %24
%8 = phi i32 [ %27, %24 ], [ %5, %2 ]
%9 = phi i8* [ %26, %24 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = phi i32 [ %25, %24 ], [ 0, %2 ]
switch i32 %8, label %19 [
i32 100, label %11
i32 111, label %13
i32 104, label %16
i32 63, label %16
]
11: ; preds = %7
%12 = load i8*, i8** @optarg
br label %24
13: ; preds = %7
%14 = load i8*, i8** @optarg
%15 = tail call i32 @strtoul(i8* nocapture %14, i32* null, i32 0)
br label %24
16: ; preds = %7, %7
%17 = load i32, i32* @stdout
%18 = tail call i32 @usage(i32 %17, i32 0)
br label %24
19: ; preds = %7
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%22 = load i32, i32* @stderr
%23 = tail call i32 @usage(i32 %22, i32 1)
br label %24
24: ; preds = %19, %16, %13, %11
%25 = phi i32 [ %10, %19 ], [ %10, %16 ], [ %15, %13 ], [ %10, %11 ]
%26 = phi i8* [ %9, %19 ], [ %9, %16 ], [ %9, %13 ], [ %12, %11 ]
%27 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp sgt i32 %27, 0
br i1 %28, label %7, label %29
29: ; preds = %24, %2
%30 = phi i32 [ 0, %2 ], [ %25, %24 ]
%31 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %2 ], [ %26, %24 ]
%32 = load i32, i32* @optind
%33 = add nsw i32 %0, -1
%34 = icmp eq i32 %32, %33
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @stderr
%39 = tail call i32 @usage(i32 %38, i32 1)
%40 = load i32, i32* @optind
br label %41
41: ; preds = %35, %29
%42 = phi i32 [ %40, %35 ], [ %32, %29 ]
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* @O_RDONLY
%47 = tail call i32 @open(i8* %45, i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %41
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = tail call i8* @strerror(i32 %51)
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %45, i8* %52)
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %41
%56 = call i32 @fstat(i32 %47, %struct.stat* %3)
%57 = load i32, i32* @O_WRONLY
%58 = tail call i32 @open(i8* %31, i32 %57)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = load i32, i32* @errno
%63 = tail call i8* @strerror(i32 %62)
%64 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %31, i8* %63)
%65 = tail call i32 @exit(i32 1)
unreachable
66: ; preds = %55
%67 = icmp eq i32 %30, 0
br i1 %67, label %78, label %68
68: ; preds = %66
%69 = load i32, i32* @SEEK_SET
%70 = tail call i32 @lseek(i32 %58, i32 %30, i32 %69)
%71 = icmp eq i32 %70, %30
br i1 %71, label %78, label %72
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = tail call i8* @strerror(i32 %74)
%76 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %30, i8* %75)
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %68, %66
%79 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%80 = load i32, i32* %79
%81 = tail call i8* @malloc(i32 %80)
%82 = icmp eq i8* %81, null
br i1 %82, label %83, label %89
83: ; preds = %78
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = tail call i8* @strerror(i32 %85)
%87 = tail call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %80, i8* %86)
%88 = tail call i32 @exit(i32 1)
unreachable
89: ; preds = %78
%90 = tail call i32 @read(i32 %47, i8* %81, i32 %80)
%91 = icmp eq i32 %90, %80
br i1 %91, label %98, label %92
92: ; preds = %89
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = tail call i8* @strerror(i32 %94)
%96 = tail call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %80, i8* %95)
%97 = tail call i32 @exit(i32 1)
unreachable
98: ; preds = %89
%99 = tail call i32 @write(i32 %58, i8* %81, i32 %80)
%100 = icmp eq i32 %99, %80
br i1 %100, label %107, label %101
101: ; preds = %98
%102 = load i32, i32* @stderr
%103 = load i32, i32* @errno
%104 = tail call i8* @strerror(i32 %103)
%105 = tail call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %80, i8* %104)
%106 = tail call i32 @exit(i32 1)
unreachable
107: ; preds = %98
%108 = tail call i32 @close(i32 %58)
%109 = tail call i32 @close(i32 %47)
ret i32 0
}