#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);
      if (res == 0)
        break;
      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    1685 <hd_main+0x4e5>
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)
cmpl   $0x0,-0x1024(%rbp)
jne    1493 <hd_main+0x2f3>
jmp    1640 <hd_main+0x4a0>
movl   $0x0,-0x1030(%rbp)
mov    -0x1030(%rbp),%eax
cmp    -0x1024(%rbp),%eax
jge    158e <hd_main+0x3ee>
mov    -0x1030(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    14db <hd_main+0x33b>
mov    -0x1034(%rbp),%esi
add    -0x1030(%rbp),%esi
lea    0xb92(%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    0xb46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1030(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
je     1557 <hd_main+0x3b7>
mov    -0x1030(%rbp),%eax
mov    -0x1024(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1575 <hd_main+0x3d5>
mov    -0x103c(%rbp),%esi
lea    0xb0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x103c(%rbp)
jmp    157a <hd_main+0x3da>
mov    -0x1030(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1030(%rbp)
jmp    149d <hd_main+0x2fd>
cmpl   $0x0,-0x1024(%rbp)
jge    160a <hd_main+0x46a>
mov    -0x10(%rbp),%rax
mov    0x2a22(%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    0x29dd(%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    0xa82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1685 <hd_main+0x4e5>
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    163b <hd_main+0x49b>
jmp    1640 <hd_main+0x4a0>
jmp    1419 <hd_main+0x279>
mov    -0x1038(%rbp),%esi
lea    0xa54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1048(%rbp)
je     166c <hd_main+0x4cc>
mov    -0x1048(%rbp),%edi
call   10c0 <sleep@plt>
jmp    1671 <hd_main+0x4d1>
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    13dc <hd_main+0x23c>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    $0xffffffff,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
mov    0x2dd6(%rip),%rax
movslq (%rax),%rax
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
jne    14ff <hd_main+0x35f>
mov    (%rbx,%rax,8),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
mov    0x10(%rsp),%r15
js     14a7 <hd_main+0x307>
mov    0x18(%rsp),%rax
lea    (%rax,%r15,1),%r13d
xor    %ebp,%ebp
mov    %rbx,0x38(%rsp)
mov    %r13d,0x2c(%rsp)
test   %r15d,%r15d
js     1255 <hd_main+0xb5>
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
mov    0xc(%rsp),%edi
mov    %r15d,%esi
call   1040 <lseek@plt>
mov    %r15d,%ebp
xor    %ebx,%ebx
xor    %r14d,%r14d
mov    %ebp,%r15d
nopl   (%rax)
mov    %r13d,%ebp
sub    %r15d,%ebp
cmp    $0x1000,%ebp
mov    $0x1000,%eax
cmovge %eax,%ebp
cmpl   $0x0,0x18(%rsp)
cmovle %eax,%ebp
mov    0xc(%rsp),%edi
lea    0x50(%rsp),%rsi
mov    %ebp,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1360 <hd_main+0x1c0>
mov    %ebp,0x30(%rsp)
mov    %eax,%r12d
test   %r12d,%r12d
jle    139b <hd_main+0x1fb>
lea    -0x1(%r12),%eax
mov    %rax,0x48(%rsp)
mov    %r15d,0x34(%rsp)
mov    %r15d,%eax
mov    %rax,0x40(%rsp)
xor    %ebp,%ebp
jmp    12e0 <hd_main+0x140>
nop
lea    0xdac(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %r14d,%r14d
add    %r15d,%ebx
add    $0x1,%rbp
cmp    %rbp,%r12
je     1330 <hd_main+0x190>
mov    %ebp,%r13d
and    $0xf,%r13d
jne    12ff <hd_main+0x15f>
mov    0x40(%rsp),%rax
lea    (%rax,%rbp,1),%esi
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x50(%rsp,%rbp,1),%r15d
add    %r15d,%r14d
lea    0xd5e(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0xf,%r13d
je     12c0 <hd_main+0x120>
cmp    %rbp,0x48(%rsp)
jne    12d4 <hd_main+0x134>
jmp    12c0 <hd_main+0x120>
nopl   0x0(%rax,%rax,1)
test   %r12d,%r12d
mov    0x2c(%rsp),%r13d
mov    0x34(%rsp),%r15d
js     139b <hd_main+0x1fb>
add    %r15d,%r12d
mov    %r12d,%r15d
cmp    %r13d,%r12d
jne    1260 <hd_main+0xc0>
mov    %r13d,%ebp
jmp    1363 <hd_main+0x1c3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%ebp
xor    %r14d,%r14d
lea    0xd34(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%rdi
test   %edi,%edi
mov    0x10(%rsp),%r15
je     14ea <hd_main+0x34a>
call   10c0 <sleep@plt>
test   %r15d,%r15d
jns    123d <hd_main+0x9d>
jmp    1255 <hd_main+0xb5>
mov    0x2c26(%rip),%rax
movslq (%rax),%rax
mov    0x38(%rsp),%rcx
mov    (%rcx,%rax,8),%rbx
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcb6(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    0x30(%rsp),%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <printf@plt>
jmp    14e4 <hd_main+0x344>
mov    $0xffffffff,%ecx
mov    %rcx,0x10(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x20(%rsp)
mov    0x2c04(%rip),%r15
lea    0xc05(%rip),%r14
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
jmp    1438 <hd_main+0x298>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
cmp    (%r12),%eax
je     11eb <hd_main+0x4b>
cmp    $0x62,%eax
jle    1460 <hd_main+0x2c0>
cmp    $0x63,%eax
je     1410 <hd_main+0x270>
cmp    $0x72,%eax
jne    1421 <hd_main+0x281>
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,0x20(%rsp)
jmp    1421 <hd_main+0x281>
nopw   0x0(%rax,%rax,1)
jne    1475 <hd_main+0x2d5>
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,0x10(%rsp)
jmp    1421 <hd_main+0x281>
cmp    $0x3f,%eax
jne    1421 <hd_main+0x281>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x2b4b(%rip),%rax
mov    (%rax),%ecx
lea    0xb71(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2b0a(%rip),%rax
mov    (%rax),%r14d
mov    0x2b10(%rip),%rax
movslq (%rax),%rax
mov    (%rbx,%rax,8),%rbp
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xb7b(%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    0x2ab2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb0d(%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 %204
80: ; preds = %60
br label %81
81: ; preds = %200, %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, %190
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
%113 = load i32, i32* %9
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %116
115: ; preds = %108
br label %191
116: ; preds = %108
store i32 0, i32* %12
br label %117
117: ; preds = %163, %116
%118 = load i32, i32* %12
%119 = load i32, i32* %9
%120 = icmp slt i32 %118, %119
br i1 %120, label %121, label %166
121: ; preds = %117
%122 = load i32, i32* %12
%123 = and i32 %122, 15
%124 = icmp eq i32 %123, 0
br i1 %124, label %125, label %130
125: ; preds = %121
%126 = load i32, i32* %13
%127 = load i32, i32* %12
%128 = add nsw i32 %126, %127
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %128)
br label %130
130: ; preds = %125, %121
%131 = load i32, i32* %12
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %132
%134 = load i8, i8* %133
%135 = zext i8 %134 to i32
%136 = load i32, i32* %15
%137 = add nsw i32 %136, %135
store i32 %137, i32* %15
%138 = load i32, i32* %12
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %139
%141 = load i8, i8* %140
%142 = zext i8 %141 to i32
%143 = load i32, i32* %14
%144 = add nsw i32 %143, %142
store i32 %144, i32* %14
%145 = load i32, i32* %12
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %146
%148 = load i8, i8* %147
%149 = zext i8 %148 to i32
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %149)
%151 = load i32, i32* %12
%152 = and i32 %151, 15
%153 = icmp eq i32 %152, 15
br i1 %153, label %159, label %154
154: ; preds = %130
%155 = load i32, i32* %12
%156 = load i32, i32* %9
%157 = sub nsw i32 %156, 1
%158 = icmp eq i32 %155, %157
br i1 %158, label %159, label %162
159: ; preds = %154, %130
%160 = load i32, i32* %15
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %160)
store i32 0, i32* %15
br label %162
162: ; preds = %159, %154
br label %163
163: ; preds = %162
%164 = load i32, i32* %12
%165 = add nsw i32 %164, 1
store i32 %165, i32* %12
br label %117
166: ; preds = %117
%167 = load i32, i32* %9
%168 = icmp slt i32 %167, 0
br i1 %168, label %169, label %180
169: ; preds = %166
%170 = load i8**, i8*** %5
%171 = load i32, i32* @optind
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i8*, i8** %170, i64 %172
%174 = load i8*, i8** %173
%175 = load i32, i32* %13
%176 = load i32, i32* %10
%177 = load i32, i32* @errno
%178 = call i8* @strerror(i32 %177)
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %174, i32 %175, i32 %176, i8* %178)
store i32 1, i32* %3
br label %204
180: ; preds = %166
%181 = load i32, i32* %9
%182 = load i32, i32* %13
%183 = add nsw i32 %182, %181
store i32 %183, i32* %13
%184 = load i32, i32* %13
%185 = load i32, i32* %16
%186 = load i32, i32* %17
%187 = add nsw i32 %185, %186
%188 = icmp eq i32 %184, %187
br i1 %188, label %189, label %190
189: ; preds = %180
br label %191
190: ; preds = %180
br label %91
191: ; preds = %189, %115
%192 = load i32, i32* %14
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %192)
%194 = load i32, i32* %18
%195 = icmp ne i32 %194, 0
br i1 %195, label %196, label %199
196: ; preds = %191
%197 = load i32, i32* %18
%198 = call i32 @sleep(i32 %197)
br label %199
199: ; preds = %196, %191
br label %200
200: ; preds = %199
%201 = load i32, i32* %18
%202 = icmp ne i32 %201, 0
br i1 %202, label %81, label %203
203: ; preds = %200
store i32 0, i32* %3
br label %204
204: ; preds = %203, %169, %70
%205 = load i32, i32* %3
ret i32 %205
}

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 %137
69: ; preds = %54, %135
%70 = phi i32 [ %132, %135 ], [ 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, %128
%77 = phi i32 [ %129, %128 ], [ %75, %74 ]
%78 = phi i32 [ %107, %128 ], [ 0, %74 ]
%79 = phi i32 [ %115, %128 ], [ 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 eq i32 %84, 0
br i1 %85, label %131, label %86
86: ; preds = %76
%87 = icmp sgt i32 %84, 0
br i1 %87, label %88, label %120
88: ; preds = %86
%89 = add nsw i32 %84, -1
%90 = zext i32 %89 to i64
%91 = zext i32 %84 to i64
br label %92
92: ; preds = %88, %114
%93 = phi i64 [ 0, %88 ], [ %116, %114 ]
%94 = phi i32 [ %79, %88 ], [ %115, %114 ]
%95 = phi i32 [ %78, %88 ], [ %107, %114 ]
%96 = trunc i64 %93 to i32
%97 = and i32 %96, 15
%98 = icmp eq i32 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %92
%100 = add nsw i32 %77, %96
%101 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %100)
br label %102
102: ; preds = %99, %92
%103 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %93
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = add nsw i32 %94, %105
%107 = add nsw i32 %95, %105
%108 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %105)
%109 = icmp eq i32 %97, 15
%110 = icmp eq i64 %93, %90
%111 = select i1 %109, i1 true, i1 %110
br i1 %111, label %112, label %114
112: ; preds = %102
%113 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %106)
br label %114
114: ; preds = %102, %112
%115 = phi i32 [ 0, %112 ], [ %106, %102 ]
%116 = add nuw nsw i64 %93, 1
%117 = icmp eq i64 %116, %91
br i1 %117, label %118, label %92
118: ; preds = %114
%119 = icmp slt i32 %84, 0
br i1 %119, label %120, label %128
120: ; preds = %86, %118
%121 = load i32, i32* @optind
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8*, i8** %1, i64 %122
%124 = load i8*, i8** %123
%125 = load i32, i32* @errno
%126 = tail call i8* @strerror(i32 %125)
%127 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %124, i32 %77, i32 %83, i8* %126)
br label %137
128: ; preds = %118
%129 = add nsw i32 %84, %77
%130 = icmp eq i32 %129, %57
br i1 %130, label %131, label %76
131: ; preds = %128, %76
%132 = phi i32 [ %77, %76 ], [ %57, %128 ]
%133 = phi i32 [ %78, %76 ], [ %107, %128 ]
%134 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %133)
br i1 %59, label %137, label %135
135: ; preds = %131
%136 = tail call i32 @sleep(i32 %38)
br label %69
137: ; preds = %131, %120, %60
%138 = phi i32 [ 1, %60 ], [ 1, %120 ], [ 0, %131 ]
ret i32 %138
}