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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char **, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int hd_main(int argc, char *argv[]) {
  int c;
  int fd;
  unsigned char buf[4096];
  int res;
  int read_len;
  int rv = 0;
  int i;
  int filepos = 0;
  int sum;
  int lsum;
  int base = -1;
  int count = 0;
  int repeat = 0;
  do {
    c = getopt(argc, argv, "b:c:r:");
    if (c == EOF)
      break;
    switch (c) {
    case 'b':
      base = strtol(optarg, NULL, 0);
      break;
    case 'c':
      count = strtol(optarg, NULL, 0);
      break;
    case 'r':
      repeat = strtol(optarg, NULL, 0);
      break;
    case '?':
      fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt);
      exit(1);
    }
  } while (1);
  if (optind + 1 != argc) {
    fprintf(stderr, "Usage: %s [-b base] [-c count] [-r delay] file\n",
            argv[0]);
    exit(1);
  }
  fd = open(argv[optind], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
    return 1;
  }
  do {
    if (base >= 0) {
      lseek(fd, base, SEEK_SET);
      filepos = base;
    }
    sum = 0;
    lsum = 0;
    while (1) {
      read_len = sizeof(buf);
      if (count > 0 && base + count - filepos < read_len)
        read_len = base + count - filepos;
      res = read(fd, &buf, read_len);
      for (i = 0; i < res; i++) {
        if ((i & 15) == 0) {
          printf("%08x: ", filepos + i);
        }
        lsum += buf[i];
        sum += buf[i];
        printf("%02x ", buf[i]);
        if (((i & 15) == 15) || (i == res - 1)) {
          printf("s %x\n", lsum);
          lsum = 0;
        }
      }
      if (res <= 0) {
        printf("Read error on %s, offset %d len %d, %s\n", argv[optind],
               filepos, read_len, strerror(errno));
        return 1;
      }
      filepos += res;
      if (filepos == base + count)
        break;
    }
    printf("sum %x\n", sum);
    if (repeat)
      sleep(repeat);
  } while (repeat);
  return 0;
}


x86 assembly (clang, -O0):
<hd_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x102c(%rbp)
movl   $0x0,-0x1034(%rbp)
movl   $0xffffffff,-0x1040(%rbp)
ff ff ff
movl   $0x0,-0x1044(%rbp)
movl   $0x0,-0x1048(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0e(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%eax
jne    1211 <hd_main+0x71>
jmp    1306 <hd_main+0x166>
mov    -0x14(%rbp),%eax
mov    %eax,-0x104c(%rbp)
sub    $0x3f,%eax
je     12c1 <hd_main+0x121>
jmp    1228 <hd_main+0x88>
mov    -0x104c(%rbp),%eax
sub    $0x62,%eax
je     1264 <hd_main+0xc4>
jmp    123c <hd_main+0x9c>
mov    -0x104c(%rbp),%eax
sub    $0x63,%eax
je     1283 <hd_main+0xe3>
jmp    1250 <hd_main+0xb0>
mov    -0x104c(%rbp),%eax
sub    $0x72,%eax
je     12a2 <hd_main+0x102>
jmp    12f2 <hd_main+0x152>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x1040(%rbp)
jmp    12f2 <hd_main+0x152>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x1044(%rbp)
jmp    12f2 <hd_main+0x152>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x1048(%rbp)
jmp    12f2 <hd_main+0x152>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2d00(%rip),%rax
mov    (%rax),%ecx
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12f7 <hd_main+0x157>
mov    $0x1,%al
test   $0x1,%al
jne    11e4 <hd_main+0x44>
jmp    1306 <hd_main+0x166>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
je     1343 <hd_main+0x1a3>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2c7a(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2c84(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13d0 <hd_main+0x230>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x105c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c3e(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x1058(%rbp)
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x105c(%rbp),%edi
mov    -0x1058(%rbp),%rdx
mov    %rax,%rcx
lea    0xc92(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1673 <hd_main+0x4d3>
jmp    13d5 <hd_main+0x235>
cmpl   $0x0,-0x1040(%rbp)
jl     1405 <hd_main+0x265>
mov    -0x18(%rbp),%edi
mov    -0x1040(%rbp),%esi
mov    0x2bb6(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x1040(%rbp),%eax
mov    %eax,-0x1034(%rbp)
movl   $0x0,-0x1038(%rbp)
movl   $0x0,-0x103c(%rbp)
movl   $0x1000,-0x1028(%rbp)
cmpl   $0x0,-0x1044(%rbp)
jle    1466 <hd_main+0x2c6>
mov    -0x1040(%rbp),%eax
add    -0x1044(%rbp),%eax
sub    -0x1034(%rbp),%eax
cmp    -0x1028(%rbp),%eax
jge    1466 <hd_main+0x2c6>
mov    -0x1040(%rbp),%eax
add    -0x1044(%rbp),%eax
sub    -0x1034(%rbp),%eax
mov    %eax,-0x1028(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1024(%rbp)
movl   $0x0,-0x1030(%rbp)
mov    -0x1030(%rbp),%eax
cmp    -0x1024(%rbp),%eax
jge    157c <hd_main+0x3dc>
mov    -0x1030(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    14c9 <hd_main+0x329>
mov    -0x1034(%rbp),%esi
add    -0x1030(%rbp),%esi
lea    0xba4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1030(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%eax
ff
add    -0x103c(%rbp),%eax
mov    %eax,-0x103c(%rbp)
movslq -0x1030(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%eax
ff
add    -0x1038(%rbp),%eax
mov    %eax,-0x1038(%rbp)
movslq -0x1030(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%esi
ff
lea    0xb58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1030(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
je     1545 <hd_main+0x3a5>
mov    -0x1030(%rbp),%eax
mov    -0x1024(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1563 <hd_main+0x3c3>
mov    -0x103c(%rbp),%esi
lea    0xb21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x103c(%rbp)
jmp    1568 <hd_main+0x3c8>
mov    -0x1030(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1030(%rbp)
jmp    148b <hd_main+0x2eb>
cmpl   $0x0,-0x1024(%rbp)
jg     15f8 <hd_main+0x458>
mov    -0x10(%rbp),%rax
mov    0x2a34(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x1070(%rbp)
mov    -0x1034(%rbp),%eax
mov    %eax,-0x1064(%rbp)
mov    -0x1028(%rbp),%eax
mov    %eax,-0x1060(%rbp)
mov    0x29ef(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1070(%rbp),%rsi
mov    -0x1064(%rbp),%edx
mov    -0x1060(%rbp),%ecx
mov    %rax,%r8
lea    0xa94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1673 <hd_main+0x4d3>
mov    -0x1024(%rbp),%eax
add    -0x1034(%rbp),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x1034(%rbp),%eax
mov    -0x1040(%rbp),%ecx
add    -0x1044(%rbp),%ecx
cmp    %ecx,%eax
jne    1629 <hd_main+0x489>
jmp    162e <hd_main+0x48e>
jmp    1419 <hd_main+0x279>
mov    -0x1038(%rbp),%esi
lea    0xa66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1048(%rbp)
je     165a <hd_main+0x4ba>
mov    -0x1048(%rbp),%edi
call   10c0 <sleep@plt>
jmp    165f <hd_main+0x4bf>
cmpl   $0x0,-0x1048(%rbp)
jne    13d5 <hd_main+0x235>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hd_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1058,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe43(%rip),%rdx
call   1090 <getopt@plt>
mov    0x2e07(%rip),%r12
cmp    (%r12),%eax
jne    13b8 <hd_main+0x218>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    $0xffffffff,%r13d
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0x2dda(%rip),%r15
movslq (%r15),%rax
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
jne    14c6 <hd_main+0x326>
mov    (%rbx,%rax,8),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     1475 <hd_main+0x2d5>
mov    0x10(%rsp),%rax
lea    (%rax,%r13,1),%r12d
xor    %ebp,%ebp
mov    %rbx,0x38(%rsp)
mov    %r13,0x30(%rsp)
mov    %r12d,0x24(%rsp)
test   %r13d,%r13d
js     1251 <hd_main+0xb1>
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
mov    0xc(%rsp),%edi
mov    %r13d,%esi
call   1040 <lseek@plt>
mov    %r13d,%ebp
xor    %ebx,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edx
sub    %ebp,%edx
cmp    $0x1000,%edx
mov    $0x1000,%eax
cmovge %eax,%edx
cmpl   $0x0,0x10(%rsp)
cmovle %eax,%edx
mov    0xc(%rsp),%edi
lea    0x50(%rsp),%rsi
mov    %edx,0x28(%rsp)
call   1050 <read@plt>
test   %eax,%eax
jle    1378 <hd_main+0x1d8>
mov    %eax,%r13d
lea    -0x1(%r13),%eax
mov    %rax,0x48(%rsp)
mov    %ebp,0x2c(%rsp)
mov    %ebp,%eax
mov    %rax,0x40(%rsp)
xor    %ebp,%ebp
jmp    12d0 <hd_main+0x130>
lea    0xdbc(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %r15d,%r15d
add    %r12d,%ebx
add    $0x1,%rbp
cmp    %rbp,%r13
je     1320 <hd_main+0x180>
mov    %ebp,%r14d
and    $0xf,%r14d
jne    12ef <hd_main+0x14f>
mov    0x40(%rsp),%rax
lea    (%rax,%rbp,1),%esi
lea    0xd7e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x50(%rsp,%rbp,1),%r12d
add    %r12d,%r15d
lea    0xd6e(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0xf,%r14d
je     12b0 <hd_main+0x110>
cmp    %rbp,0x48(%rsp)
jne    12c4 <hd_main+0x124>
jmp    12b0 <hd_main+0x110>
nopl   0x0(%rax,%rax,1)
test   %r13d,%r13d
mov    0x24(%rsp),%r12d
mov    0x2c(%rsp),%ebp
jle    1378 <hd_main+0x1d8>
add    %ebp,%r13d
mov    %r13d,%ebp
cmp    %r12d,%r13d
jne    1260 <hd_main+0xc0>
xor    %r14d,%r14d
lea    0xd5a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%rdi
test   %edi,%edi
je     14b1 <hd_main+0x311>
call   10c0 <sleep@plt>
mov    %r12d,%ebp
mov    0x30(%rsp),%r13
test   %r13d,%r13d
jns    1239 <hd_main+0x99>
jmp    1251 <hd_main+0xb1>
mov    0x2c49(%rip),%rax
movslq (%rax),%rax
mov    0x38(%rsp),%rcx
mov    (%rcx,%rax,8),%rbx
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcd9(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    0x28(%rsp),%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <printf@plt>
jmp    14ab <hd_main+0x30b>
mov    $0xffffffff,%r13d
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
mov    0x2c2c(%rip),%r15
lea    0xc2d(%rip),%r14
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
jmp    1408 <hd_main+0x268>
nopl   0x0(%rax)
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
cmp    (%r12),%eax
je     11e7 <hd_main+0x47>
cmp    $0x62,%eax
jle    1430 <hd_main+0x290>
cmp    $0x63,%eax
je     13e0 <hd_main+0x240>
cmp    $0x72,%eax
jne    13f1 <hd_main+0x251>
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,0x18(%rsp)
jmp    13f1 <hd_main+0x251>
nopw   0x0(%rax,%rax,1)
jne    1443 <hd_main+0x2a3>
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,%r13d
jmp    13f1 <hd_main+0x251>
cmp    $0x3f,%eax
jne    13f1 <hd_main+0x251>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x2b7d(%rip),%rax
mov    (%rax),%ecx
lea    0xba3(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2b3c(%rip),%rax
mov    (%rax),%r14d
movslq (%r15),%rax
mov    (%rbx,%rax,8),%rbp
mov    0x2b23(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xbb4(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x1058,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb46(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"b:c:r:\00"
@EOF = global i32 0
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: invalid option -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.2 = [48 x i8] c"Usage: %s [-b base] [-c count] [-r delay] file\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [23 x i8] c"could not open %s, %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [7 x i8] c"%08x: \00"
@.str.5 = [6 x i8] c"%02x \00"
@.str.6 = [6 x i8] c"s %x\0A\00"
@.str.7 = [40 x i8] c"Read error on %s, offset %d len %d, %s\0A\00"
@.str.8 = [8 x i8] c"sum %x\0A\00"
define i32 @hd_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %13
store i32 -1, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
br label %19
19: ; preds = %47, %2
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %19
br label %48
27: ; preds = %19
%28 = load i32, i32* %6
switch i32 %28, label %46 [
i32 98, label %29
i32 99, label %32
i32 114, label %35
i32 63, label %38
]
29: ; preds = %27
%30 = load i32, i32* @optarg
%31 = call i32 @strtol(i32 %30, i32* null, i32 0)
store i32 %31, i32* %16
br label %46
32: ; preds = %27
%33 = load i32, i32* @optarg
%34 = call i32 @strtol(i32 %33, i32* null, i32 0)
store i32 %34, i32* %17
br label %46
35: ; preds = %27
%36 = load i32, i32* @optarg
%37 = call i32 @strtol(i32 %36, i32* null, i32 0)
store i32 %37, i32* %18
br label %46
38: ; preds = %27
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i32, i32* @optopt
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %42, i32 %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %27, %35, %32, %29
br label %47
47: ; preds = %46
br i1 true, label %19, label %48
48: ; preds = %47, %26
%49 = load i32, i32* @optind
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %4
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 0
%57 = load i8*, i8** %56
%58 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %48
%61 = load i8**, i8*** %5
%62 = load i32, i32* @optind
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = load i32, i32* @O_RDONLY
%67 = call i32 @open(i8* %65, i32 %66)
store i32 %67, i32* %7
%68 = load i32, i32* %7
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %80
70: ; preds = %60
%71 = load i32, i32* @stderr
%72 = load i8**, i8*** %5
%73 = load i32, i32* @optind
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %76, i8* %78)
store i32 1, i32* %3
br label %200
80: ; preds = %60
br label %81
81: ; preds = %196, %80
%82 = load i32, i32* %16
%83 = icmp sge i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %81
%85 = load i32, i32* %7
%86 = load i32, i32* %16
%87 = load i32, i32* @SEEK_SET
%88 = call i32 @lseek(i32 %85, i32 %86, i32 %87)
%89 = load i32, i32* %16
store i32 %89, i32* %13
br label %90
90: ; preds = %84, %81
store i32 0, i32* %14
store i32 0, i32* %15
br label %91
91: ; preds = %90, %186
store i32 4096, i32* %10
%92 = load i32, i32* %17
%93 = icmp sgt i32 %92, 0
br i1 %93, label %94, label %108
94: ; preds = %91
%95 = load i32, i32* %16
%96 = load i32, i32* %17
%97 = add nsw i32 %95, %96
%98 = load i32, i32* %13
%99 = sub nsw i32 %97, %98
%100 = load i32, i32* %10
%101 = icmp slt i32 %99, %100
br i1 %101, label %102, label %108
102: ; preds = %94
%103 = load i32, i32* %16
%104 = load i32, i32* %17
%105 = add nsw i32 %103, %104
%106 = load i32, i32* %13
%107 = sub nsw i32 %105, %106
store i32 %107, i32* %10
br label %108
108: ; preds = %102, %94, %91
%109 = load i32, i32* %7
%110 = bitcast [4096 x i8]* %8 to i8**
%111 = load i32, i32* %10
%112 = call i32 @read(i32 %109, i8** %110, i32 %111)
store i32 %112, i32* %9
store i32 0, i32* %12
br label %113
113: ; preds = %159, %108
%114 = load i32, i32* %12
%115 = load i32, i32* %9
%116 = icmp slt i32 %114, %115
br i1 %116, label %117, label %162
117: ; preds = %113
%118 = load i32, i32* %12
%119 = and i32 %118, 15
%120 = icmp eq i32 %119, 0
br i1 %120, label %121, label %126
121: ; preds = %117
%122 = load i32, i32* %13
%123 = load i32, i32* %12
%124 = add nsw i32 %122, %123
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %124)
br label %126
126: ; preds = %121, %117
%127 = load i32, i32* %12
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %128
%130 = load i8, i8* %129
%131 = zext i8 %130 to i32
%132 = load i32, i32* %15
%133 = add nsw i32 %132, %131
store i32 %133, i32* %15
%134 = load i32, i32* %12
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %135
%137 = load i8, i8* %136
%138 = zext i8 %137 to i32
%139 = load i32, i32* %14
%140 = add nsw i32 %139, %138
store i32 %140, i32* %14
%141 = load i32, i32* %12
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %142
%144 = load i8, i8* %143
%145 = zext i8 %144 to i32
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %145)
%147 = load i32, i32* %12
%148 = and i32 %147, 15
%149 = icmp eq i32 %148, 15
br i1 %149, label %155, label %150
150: ; preds = %126
%151 = load i32, i32* %12
%152 = load i32, i32* %9
%153 = sub nsw i32 %152, 1
%154 = icmp eq i32 %151, %153
br i1 %154, label %155, label %158
155: ; preds = %150, %126
%156 = load i32, i32* %15
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %156)
store i32 0, i32* %15
br label %158
158: ; preds = %155, %150
br label %159
159: ; preds = %158
%160 = load i32, i32* %12
%161 = add nsw i32 %160, 1
store i32 %161, i32* %12
br label %113
162: ; preds = %113
%163 = load i32, i32* %9
%164 = icmp sle i32 %163, 0
br i1 %164, label %165, label %176
165: ; preds = %162
%166 = load i8**, i8*** %5
%167 = load i32, i32* @optind
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i8*, i8** %166, i64 %168
%170 = load i8*, i8** %169
%171 = load i32, i32* %13
%172 = load i32, i32* %10
%173 = load i32, i32* @errno
%174 = call i8* @strerror(i32 %173)
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %170, i32 %171, i32 %172, i8* %174)
store i32 1, i32* %3
br label %200
176: ; preds = %162
%177 = load i32, i32* %9
%178 = load i32, i32* %13
%179 = add nsw i32 %178, %177
store i32 %179, i32* %13
%180 = load i32, i32* %13
%181 = load i32, i32* %16
%182 = load i32, i32* %17
%183 = add nsw i32 %181, %182
%184 = icmp eq i32 %180, %183
br i1 %184, label %185, label %186
185: ; preds = %176
br label %187
186: ; preds = %176
br label %91
187: ; preds = %185
%188 = load i32, i32* %14
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %188)
%190 = load i32, i32* %18
%191 = icmp ne i32 %190, 0
br i1 %191, label %192, label %195
192: ; preds = %187
%193 = load i32, i32* %18
%194 = call i32 @sleep(i32 %193)
br label %195
195: ; preds = %192, %187
br label %196
196: ; preds = %195
%197 = load i32, i32* %18
%198 = icmp ne i32 %197, 0
br i1 %198, label %81, label %199
199: ; preds = %196
store i32 0, i32* %3
br label %200
200: ; preds = %199, %165, %70
%201 = load i32, i32* %3
ret i32 %201
}

LLVM IR (-O2):
@.str = [7 x i8] c"b:c:r:\00"
@EOF = global i32 0
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: invalid option -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.2 = [48 x i8] c"Usage: %s [-b base] [-c count] [-r delay] file\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [23 x i8] c"could not open %s, %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [7 x i8] c"%08x: \00"
@.str.5 = [6 x i8] c"%02x \00"
@.str.6 = [6 x i8] c"s %x\0A\00"
@.str.7 = [40 x i8] c"Read error on %s, offset %d len %d, %s\0A\00"
@.str.8 = [8 x i8] c"sum %x\0A\00"
define i32 @hd_main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %35, label %8
8: ; preds = %2, %28
%9 = phi i32 [ %32, %28 ], [ %5, %2 ]
%10 = phi i32 [ %31, %28 ], [ 0, %2 ]
%11 = phi i32 [ %30, %28 ], [ 0, %2 ]
%12 = phi i32 [ %29, %28 ], [ -1, %2 ]
switch i32 %9, label %28 [
i32 98, label %13
i32 99, label %16
i32 114, label %19
i32 63, label %22
]
13: ; preds = %8
%14 = load i32, i32* @optarg
%15 = tail call i32 @strtol(i32 %14, i32* null, i32 0)
br label %28
16: ; preds = %8
%17 = load i32, i32* @optarg
%18 = tail call i32 @strtol(i32 %17, i32* null, i32 0)
br label %28
19: ; preds = %8
%20 = load i32, i32* @optarg
%21 = tail call i32 @strtol(i32 %20, i32* null, i32 0)
br label %28
22: ; preds = %8
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %1
%25 = load i32, i32* @optopt
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %13, %16, %19, %8
%29 = phi i32 [ %12, %8 ], [ %12, %19 ], [ %12, %16 ], [ %15, %13 ]
%30 = phi i32 [ %11, %8 ], [ %11, %19 ], [ %18, %16 ], [ %11, %13 ]
%31 = phi i32 [ %10, %8 ], [ %21, %19 ], [ %10, %16 ], [ %10, %13 ]
%32 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %8
35: ; preds = %28, %2
%36 = phi i32 [ -1, %2 ], [ %29, %28 ]
%37 = phi i32 [ 0, %2 ], [ %30, %28 ]
%38 = phi i32 [ 0, %2 ], [ %31, %28 ]
%39 = load i32, i32* @optind
%40 = add nsw i32 %39, 1
%41 = icmp eq i32 %40, %0
br i1 %41, label %47, label %42
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %1
%45 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %35
%48 = sext i32 %39 to i64
%49 = getelementptr inbounds i8*, i8** %1, i64 %48
%50 = load i8*, i8** %49
%51 = load i32, i32* @O_RDONLY
%52 = tail call i32 @open(i8* %50, i32 %51)
%53 = icmp slt i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %47
%55 = icmp sgt i32 %36, -1
%56 = icmp sgt i32 %37, 0
%57 = add nsw i32 %37, %36
%58 = bitcast [4096 x i8]* %3 to i8**
%59 = icmp eq i32 %38, 0
br label %69
60: ; preds = %47
%61 = load i32, i32* @stderr
%62 = load i32, i32* @optind
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %1, i64 %63
%65 = load i8*, i8** %64
%66 = load i32, i32* @errno
%67 = tail call i8* @strerror(i32 %66)
%68 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %65, i8* %67)
br label %133
69: ; preds = %54, %131
%70 = phi i32 [ %57, %131 ], [ 0, %54 ]
br i1 %55, label %71, label %74
71: ; preds = %69
%72 = load i32, i32* @SEEK_SET
%73 = tail call i32 @lseek(i32 %52, i32 %36, i32 %72)
br label %74
74: ; preds = %71, %69
%75 = phi i32 [ %70, %69 ], [ %36, %71 ]
br label %76
76: ; preds = %74, %126
%77 = phi i32 [ %127, %126 ], [ %75, %74 ]
%78 = phi i32 [ %105, %126 ], [ 0, %74 ]
%79 = phi i32 [ %113, %126 ], [ 0, %74 ]
%80 = sub nsw i32 %57, %77
%81 = icmp slt i32 %80, 4096
%82 = select i1 %56, i1 %81, i1 false
%83 = select i1 %82, i32 %80, i32 4096
%84 = call i32 @read(i32 %52, i8** %58, i32 %83)
%85 = icmp sgt i32 %84, 0
br i1 %85, label %86, label %118
86: ; preds = %76
%87 = add nsw i32 %84, -1
%88 = zext i32 %87 to i64
%89 = zext i32 %84 to i64
br label %90
90: ; preds = %86, %112
%91 = phi i64 [ 0, %86 ], [ %114, %112 ]
%92 = phi i32 [ %79, %86 ], [ %113, %112 ]
%93 = phi i32 [ %78, %86 ], [ %105, %112 ]
%94 = trunc i64 %91 to i32
%95 = and i32 %94, 15
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %90
%98 = add nsw i32 %77, %94
%99 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %98)
br label %100
100: ; preds = %97, %90
%101 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %91
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = add nsw i32 %92, %103
%105 = add nsw i32 %93, %103
%106 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %103)
%107 = icmp eq i32 %95, 15
%108 = icmp eq i64 %91, %88
%109 = select i1 %107, i1 true, i1 %108
br i1 %109, label %110, label %112
110: ; preds = %100
%111 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %104)
br label %112
112: ; preds = %100, %110
%113 = phi i32 [ 0, %110 ], [ %104, %100 ]
%114 = add nuw nsw i64 %91, 1
%115 = icmp eq i64 %114, %89
br i1 %115, label %116, label %90
116: ; preds = %112
%117 = icmp slt i32 %84, 1
br i1 %117, label %118, label %126
118: ; preds = %76, %116
%119 = load i32, i32* @optind
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8*, i8** %1, i64 %120
%122 = load i8*, i8** %121
%123 = load i32, i32* @errno
%124 = tail call i8* @strerror(i32 %123)
%125 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %122, i32 %77, i32 %83, i8* %124)
br label %133
126: ; preds = %116
%127 = add nsw i32 %84, %77
%128 = icmp eq i32 %127, %57
br i1 %128, label %129, label %76
129: ; preds = %126
%130 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %105)
br i1 %59, label %133, label %131
131: ; preds = %129
%132 = tail call i32 @sleep(i32 %38)
br label %69
133: ; preds = %129, %118, %60
%134 = phi i32 [ 1, %60 ], [ 1, %118 ], [ 0, %129 ]
ret i32 %134
}