#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 scalar_t__ ssize_t;
typedef scalar_t__ off_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
scalar_t__ atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(scalar_t__);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ pread(int, char *, scalar_t__, scalar_t__);
int /*<<< orphan*/ printDump(scalar_t__, char *, scalar_t__, int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    puts("Usage: <file name> <[offset,]amount> [format: bodxa]");
    return EXIT_FAILURE;
  }
  off_t offset = 0;
  off_t amount;
  if (strchr(argv[2], ',') != NULL) {
    char *offsetToken = strtok(argv[2], ",");
    offset = atol(offsetToken);
    char *amountToken = strtok(NULL, ",");
    amount = (amountToken != NULL) ? atol(amountToken) : 0;
  } else {
    amount = atol(argv[2]);
  }
  if (amount < 0) {
    fputs("Cannot read a negative amount.\n", stderr);
    return EXIT_FAILURE;
  }
  char *data = malloc(amount);
  if (data == NULL) {
    perror("Memory allocation error");
    return EXIT_FAILURE;
  }
  int printFormats = 0;
  if (argc > 3) {
    int formatCount = strlen(argv[3]);
    while (--formatCount >= 0) {
      char format = argv[3][formatCount];
      switch (format) {
      case 'b':
      case 'B':
        printFormats |= (1 << 0);
        break;
      case 'o':
      case 'O':
        printFormats |= (1 << 1);
        break;
      case 'd':
      case 'D':
        printFormats |= (1 << 2);
        break;
      case 'x':
      case 'X':
        printFormats |= (1 << 3);
        break;
      case 'a':
      case 'A':
        printFormats |= (1 << 4);
        break;
      default:
        printf("Unrecognized print format: %c\n", format);
        break;
      }
    }
  } else {
    printFormats = (1 << 2);
  }
  char *fileName = argv[1];
  int file = open(fileName, O_RDONLY);
  if (file < 0) {
    perror("File open error");
    free(data);
    return EXIT_FAILURE;
  }
  if (offset < 0) {
    off_t size = lseek(file, 0, SEEK_END);
    if (-offset > size || size == 0) {
      offset = 0;
    } else if (size < 0) {
      perror("Seek error");
      close(file);
      free(data);
      return EXIT_FAILURE;
    } else if (size > 0) {
      offset += size;
    }
  }
  ssize_t bytesRead = pread(file, data, amount, offset);
  if (bytesRead < 0) {
    perror("Reading error");
    close(file);
    free(data);
    return EXIT_FAILURE;
  }
  close(file);
  printDump(offset, data, bytesRead, printFormats);
  free(data);
  return EXIT_SUCCESS;
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    1230 <main+0x40>
lea    0xec6(%rip),%rdi
call   1040 <puts@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    158b <main+0x39b>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x2c,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     12c2 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xeb2(%rip),%rsi
call   1100 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe91(%rip),%rsi
call   1100 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12aa <main+0xba>
mov    -0x30(%rbp),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x70(%rbp)
jmp    12b5 <main+0xc5>
xor    %eax,%eax
mov    %rax,-0x70(%rbp)
jmp    12b5 <main+0xc5>
mov    -0x70(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    12d3 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1304 <main+0x114>
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
lea    0xe29(%rip),%rdi
call   1090 <fputs@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    158b <main+0x39b>
mov    -0x20(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1339 <main+0x149>
lea    0xe14(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    158b <main+0x39b>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1408 <main+0x218>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jl     1403 <main+0x213>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x41(%rbp)
movsbl -0x41(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x78(%rbp)
sub    $0x37,%eax
ja     13ee <main+0x1fe>
mov    -0x78(%rbp),%rax
lea    0xc61(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x3c(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13fe <main+0x20e>
mov    -0x3c(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x3c(%rbp)
jmp    13fe <main+0x20e>
mov    -0x3c(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x3c(%rbp)
jmp    13fe <main+0x20e>
mov    -0x3c(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x3c(%rbp)
jmp    13fe <main+0x20e>
mov    -0x3c(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x3c(%rbp)
jmp    13fe <main+0x20e>
lea    0xd5a(%rip),%rdi
movsbl -0x41(%rbp),%esi
call   1070 <printf@plt>
jmp    135a <main+0x16a>
jmp    140f <main+0x21f>
movl   $0x4,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    0x2bba(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1460 <main+0x270>
lea    0xd2d(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    158b <main+0x39b>
cmpq   $0x0,-0x18(%rbp)
jge    1509 <main+0x319>
mov    -0x54(%rbp),%edi
mov    0x2b73(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %rax,-0x60(%rbp)
xor    %eax,%eax
sub    -0x18(%rbp),%rax
cmp    -0x60(%rbp),%rax
jg     149d <main+0x2ad>
cmpq   $0x0,-0x60(%rbp)
jne    14aa <main+0x2ba>
movq   $0x0,-0x18(%rbp)
jmp    1504 <main+0x314>
cmpq   $0x0,-0x60(%rbp)
jge    14e3 <main+0x2f3>
lea    0xcc2(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x54(%rbp),%edi
call   10a0 <close@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2aef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    158b <main+0x39b>
cmpq   $0x0,-0x60(%rbp)
jle    14fa <main+0x30a>
mov    -0x60(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    14ff <main+0x30f>
jmp    1504 <main+0x314>
jmp    1509 <main+0x319>
mov    -0x54(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1110 <pread@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jge    155a <main+0x36a>
lea    0xc56(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x54(%rbp),%edi
call   10a0 <close@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    158b <main+0x39b>
mov    -0x54(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
call   10b0 <printDump@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     1218 <main+0x28>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
mov    0x2db5(%rip),%rax
jmp    13ef <main+0x1ff>
mov    %rsi,%r15
mov    %edi,%r13d
mov    0x10(%rsi),%rdi
mov    $0x2c,%esi
call   1060 <strchr@plt>
mov    0x10(%r15),%rdi
test   %rax,%rax
je     131c <main+0x12c>
lea    0xed5(%rip),%rbp
mov    %rbp,%rsi
call   1100 <strtok@plt>
mov    %rax,%rdi
call   10d0 <atol@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
xor    %edi,%edi
mov    %rbp,%rsi
call   1100 <strtok@plt>
test   %rax,%rax
je     1279 <main+0x89>
mov    %rax,%rdi
call   10d0 <atol@plt>
mov    %rax,%r12
test   %r12,%r12
js     132f <main+0x13f>
mov    %r12,%rdi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1400 <main+0x210>
mov    %rax,%r14
mov    %rbx,(%rsp)
mov    $0x4,%ebp
cmp    $0x4,%r13d
jb     1352 <main+0x162>
mov    0x18(%r15),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1350 <main+0x160>
mov    %eax,%ebx
add    $0x1,%rbx
xor    %ebp,%ebp
lea    0xd40(%rip),%r13
jmp    12da <main+0xea>
or     $0x10,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    1352 <main+0x162>
lea    -0x2(%rbx),%eax
mov    0x18(%r15),%rcx
movsbl (%rcx,%rax,1),%eax
lea    -0x41(%rax),%ecx
cmp    $0x37,%ecx
ja     130b <main+0x11b>
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
or     $0x1,%ebp
jmp    12d0 <main+0xe0>
or     $0x4,%ebp
jmp    12d0 <main+0xe0>
or     $0x2,%ebp
jmp    12d0 <main+0xe0>
or     $0x8,%ebp
jmp    12d0 <main+0xe0>
movsbl %al,%esi
lea    0xe3a(%rip),%rdi
call   1070 <printf@plt>
jmp    12d0 <main+0xe0>
call   10d0 <atol@plt>
mov    %rax,%r12
xor    %ebx,%ebx
test   %r12,%r12
jns    1279 <main+0x89>
mov    0x2c9a(%rip),%rax
mov    (%rax),%esi
lea    0xdd8(%rip),%rdi
call   1090 <fputs@plt>
mov    0x2c7d(%rip),%rax
jmp    13ef <main+0x1ff>
xor    %ebp,%ebp
mov    0x8(%r15),%rdi
mov    0x2c83(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
test   %eax,%eax
js     1415 <main+0x225>
mov    %eax,%r15d
mov    (%rsp),%rbx
test   %rbx,%rbx
js     137d <main+0x18d>
mov    %rbx,%r13
jmp    13af <main+0x1bf>
mov    0x2c64(%rip),%rax
mov    (%rax),%edx
xor    %r13d,%r13d
mov    %r15d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %rbx,%rcx
neg    %rcx
cmp    %rcx,%rax
jl     13af <main+0x1bf>
test   %rax,%rax
je     13af <main+0x1bf>
js     1448 <main+0x258>
add    %rbx,%rax
mov    %rax,%r13
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1110 <pread@plt>
test   %rax,%rax
js     1423 <main+0x233>
mov    %rax,%rbx
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   10b0 <printDump@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2bd1(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd30(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2bb5(%rip),%rax
jmp    13ef <main+0x1ff>
lea    0xd52(%rip),%rdi
call   10f0 <perror@plt>
jmp    1437 <main+0x247>
lea    0xd5f(%rip),%rdi
call   10f0 <perror@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2b82(%rip),%rax
jmp    13ef <main+0x1ff>
lea    0xd2f(%rip),%rdi
jmp    142a <main+0x23a>

LLVM IR (-O0):
@.str = [53 x i8] c"Usage: <file name> <[offset,]amount> [format: bodxa]\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c",\00"
@.str.2 = [32 x i8] c"Cannot read a negative amount.\0A\00"
@stderr = global i32 0
@.str.3 = [24 x i8] c"Memory allocation error\00"
@.str.4 = [31 x i8] c"Unrecognized print format: %c\0A\00"
@O_RDONLY = global i32 0
@.str.5 = [16 x i8] c"File open error\00"
@SEEK_END = global i32 0
@.str.6 = [11 x i8] c"Seek error\00"
@.str.7 = [14 x i8] c"Reading error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @puts(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %183
23: ; preds = %2
store i64 0, i64* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32* @strchr(i8* %26, i8 signext 44)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %45
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = call i64 @atol(i8* %34)
store i64 %35, i64* %6
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %29
%40 = load i8*, i8** %9
%41 = call i64 @atol(i8* %40)
br label %43
42: ; preds = %29
br label %43
43: ; preds = %42, %39
%44 = phi i64 [ %41, %39 ], [ 0, %42 ]
store i64 %44, i64* %7
br label %50
45: ; preds = %23
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i64 @atol(i8* %48)
store i64 %49, i64* %7
br label %50
50: ; preds = %45, %43
%51 = load i64, i64* %7
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = load i32, i32* @EXIT_FAILURE
store i32 %56, i32* %3
br label %183
57: ; preds = %50
%58 = load i64, i64* %7
%59 = call i8* @malloc(i64 %58)
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
store i32 %64, i32* %3
br label %183
65: ; preds = %57
store i32 0, i32* %11
%66 = load i32, i32* %4
%67 = icmp sgt i32 %66, 3
br i1 %67, label %68, label %107
68: ; preds = %65
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 3
%71 = load i8*, i8** %70
%72 = call i32 @strlen(i8* %71)
store i32 %72, i32* %12
br label %73
73: ; preds = %105, %68
%74 = load i32, i32* %12
%75 = add nsw i32 %74, -1
store i32 %75, i32* %12
%76 = icmp sge i32 %75, 0
br i1 %76, label %77, label %106
77: ; preds = %73
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 3
%80 = load i8*, i8** %79
%81 = load i32, i32* %12
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8, i8* %83
store i8 %84, i8* %13
%85 = load i8, i8* %13
%86 = sext i8 %85 to i32
switch i32 %86, label %102 [
i32 98, label %87
i32 66, label %87
i32 111, label %90
i32 79, label %90
i32 100, label %93
i32 68, label %93
i32 120, label %96
i32 88, label %96
i32 97, label %99
i32 65, label %99
]
87: ; preds = %77, %77
%88 = load i32, i32* %11
%89 = or i32 %88, 1
store i32 %89, i32* %11
br label %105
90: ; preds = %77, %77
%91 = load i32, i32* %11
%92 = or i32 %91, 2
store i32 %92, i32* %11
br label %105
93: ; preds = %77, %77
%94 = load i32, i32* %11
%95 = or i32 %94, 4
store i32 %95, i32* %11
br label %105
96: ; preds = %77, %77
%97 = load i32, i32* %11
%98 = or i32 %97, 8
store i32 %98, i32* %11
br label %105
99: ; preds = %77, %77
%100 = load i32, i32* %11
%101 = or i32 %100, 16
store i32 %101, i32* %11
br label %105
102: ; preds = %77
%103 = load i8, i8* %13
%104 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8 signext %103)
br label %105
105: ; preds = %102, %99, %96, %93, %90, %87
br label %73
106: ; preds = %73
br label %108
107: ; preds = %65
store i32 4, i32* %11
br label %108
108: ; preds = %107, %106
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 1
%111 = load i8*, i8** %110
store i8* %111, i8** %14
%112 = load i8*, i8** %14
%113 = load i32, i32* @O_RDONLY
%114 = call i32 @open(i8* %112, i32 %113)
store i32 %114, i32* %15
%115 = load i32, i32* %15
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %122
117: ; preds = %108
%118 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%119 = load i8*, i8** %10
%120 = call i32 @free(i8* %119)
%121 = load i32, i32* @EXIT_FAILURE
store i32 %121, i32* %3
br label %183
122: ; preds = %108
%123 = load i64, i64* %6
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %157
125: ; preds = %122
%126 = load i32, i32* %15
%127 = load i32, i32* @SEEK_END
%128 = call i64 @lseek(i32 %126, i32 0, i32 %127)
store i64 %128, i64* %16
%129 = load i64, i64* %6
%130 = sub nsw i64 0, %129
%131 = load i64, i64* %16
%132 = icmp sgt i64 %130, %131
br i1 %132, label %136, label %133
133: ; preds = %125
%134 = load i64, i64* %16
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %137
136: ; preds = %133, %125
store i64 0, i64* %6
br label %156
137: ; preds = %133
%138 = load i64, i64* %16
%139 = icmp slt i64 %138, 0
br i1 %139, label %140, label %147
140: ; preds = %137
%141 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%142 = load i32, i32* %15
%143 = call i32 @close(i32 %142)
%144 = load i8*, i8** %10
%145 = call i32 @free(i8* %144)
%146 = load i32, i32* @EXIT_FAILURE
store i32 %146, i32* %3
br label %183
147: ; preds = %137
%148 = load i64, i64* %16
%149 = icmp sgt i64 %148, 0
br i1 %149, label %150, label %154
150: ; preds = %147
%151 = load i64, i64* %16
%152 = load i64, i64* %6
%153 = add nsw i64 %152, %151
store i64 %153, i64* %6
br label %154
154: ; preds = %150, %147
br label %155
155: ; preds = %154
br label %156
156: ; preds = %155, %136
br label %157
157: ; preds = %156, %122
%158 = load i32, i32* %15
%159 = load i8*, i8** %10
%160 = load i64, i64* %7
%161 = load i64, i64* %6
%162 = call i64 @pread(i32 %158, i8* %159, i64 %160, i64 %161)
store i64 %162, i64* %17
%163 = load i64, i64* %17
%164 = icmp slt i64 %163, 0
br i1 %164, label %165, label %172
165: ; preds = %157
%166 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%167 = load i32, i32* %15
%168 = call i32 @close(i32 %167)
%169 = load i8*, i8** %10
%170 = call i32 @free(i8* %169)
%171 = load i32, i32* @EXIT_FAILURE
store i32 %171, i32* %3
br label %183
172: ; preds = %157
%173 = load i32, i32* %15
%174 = call i32 @close(i32 %173)
%175 = load i64, i64* %6
%176 = load i8*, i8** %10
%177 = load i64, i64* %17
%178 = load i32, i32* %11
%179 = call i32 @printDump(i64 %175, i8* %176, i64 %177, i32 %178)
%180 = load i8*, i8** %10
%181 = call i32 @free(i8* %180)
%182 = load i32, i32* @EXIT_SUCCESS
store i32 %182, i32* %3
br label %183
183: ; preds = %172, %165, %140, %117, %62, %53, %20
%184 = load i32, i32* %3
ret i32 %184
}

LLVM IR (-O2):
@.str = [53 x i8] c"Usage: <file name> <[offset,]amount> [format: bodxa]\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c",\00"
@.str.2 = [32 x i8] c"Cannot read a negative amount.\0A\00"
@stderr = global i32 0
@.str.3 = [24 x i8] c"Memory allocation error\00"
@.str.4 = [31 x i8] c"Unrecognized print format: %c\0A\00"
@O_RDONLY = global i32 0
@.str.5 = [16 x i8] c"File open error\00"
@SEEK_END = global i32 0
@.str.6 = [11 x i8] c"Seek error\00"
@.str.7 = [14 x i8] c"Reading error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %107
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @strchr(i8* %8, i8 signext 44)
%10 = icmp eq i32* %9, null
%11 = load i8*, i8** %7
br i1 %10, label %19, label %12
12: ; preds = %6
%13 = tail call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i64 @atol(i8* %13)
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %28, label %17
17: ; preds = %12
%18 = tail call i64 @atol(i8* %15)
br label %21
19: ; preds = %6
%20 = tail call i64 @atol(i8* %11)
br label %21
21: ; preds = %17, %19
%22 = phi i64 [ %20, %19 ], [ %18, %17 ]
%23 = phi i64 [ 0, %19 ], [ %14, %17 ]
%24 = icmp slt i64 %22, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = tail call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %107
28: ; preds = %12, %21
%29 = phi i64 [ %23, %21 ], [ %14, %12 ]
%30 = phi i64 [ %22, %21 ], [ 0, %12 ]
%31 = tail call i8* @malloc(i64 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %107
35: ; preds = %28
%36 = icmp ugt i32 %0, 3
br i1 %36, label %37, label %68
37: ; preds = %35
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = tail call i32 @strlen(i8* %39)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %68
42: ; preds = %37
%43 = zext i32 %40 to i64
br label %44
44: ; preds = %42, %65
%45 = phi i64 [ %43, %42 ], [ %47, %65 ]
%46 = phi i32 [ 0, %42 ], [ %66, %65 ]
%47 = add nsw i64 %45, -1
%48 = load i8*, i8** %38
%49 = and i64 %47, 4294967295
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
switch i32 %52, label %63 [
i32 98, label %53
i32 66, label %53
i32 111, label %55
i32 79, label %55
i32 100, label %57
i32 68, label %57
i32 120, label %59
i32 88, label %59
i32 97, label %61
i32 65, label %61
]
53: ; preds = %44, %44
%54 = or i32 %46, 1
br label %65
55: ; preds = %44, %44
%56 = or i32 %46, 2
br label %65
57: ; preds = %44, %44
%58 = or i32 %46, 4
br label %65
59: ; preds = %44, %44
%60 = or i32 %46, 8
br label %65
61: ; preds = %44, %44
%62 = or i32 %46, 16
br label %65
63: ; preds = %44
%64 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8 signext %51)
br label %65
65: ; preds = %63, %61, %59, %57, %55, %53
%66 = phi i32 [ %46, %63 ], [ %62, %61 ], [ %60, %59 ], [ %58, %57 ], [ %56, %55 ], [ %54, %53 ]
%67 = icmp ugt i64 %45, 1
br i1 %67, label %44, label %68
68: ; preds = %65, %37, %35
%69 = phi i32 [ 4, %35 ], [ 0, %37 ], [ %66, %65 ]
%70 = getelementptr inbounds i8*, i8** %1, i64 1
%71 = load i8*, i8** %70
%72 = load i32, i32* @O_RDONLY
%73 = tail call i32 @open(i8* %71, i32 %72)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %68
%76 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%77 = tail call i32 @free(i8* %31)
br label %107
78: ; preds = %68
%79 = icmp slt i64 %29, 0
br i1 %79, label %80, label %95
80: ; preds = %78
%81 = load i32, i32* @SEEK_END
%82 = tail call i64 @lseek(i32 %73, i32 0, i32 %81)
%83 = sub nsw i64 0, %29
%84 = icmp slt i64 %82, %83
%85 = icmp eq i64 %82, 0
%86 = or i1 %84, %85
br i1 %86, label %95, label %87
87: ; preds = %80
%88 = icmp slt i64 %82, 0
br i1 %88, label %91, label %89
89: ; preds = %87
%90 = add nsw i64 %82, %29
br label %95
91: ; preds = %87
%92 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%93 = tail call i32 @close(i32 %73)
%94 = tail call i32 @free(i8* %31)
br label %107
95: ; preds = %89, %80, %78
%96 = phi i64 [ %29, %78 ], [ 0, %80 ], [ %90, %89 ]
%97 = tail call i64 @pread(i32 %73, i8* %31, i64 %30, i64 %96)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %95
%100 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%101 = tail call i32 @close(i32 %73)
%102 = tail call i32 @free(i8* %31)
br label %107
103: ; preds = %95
%104 = tail call i32 @close(i32 %73)
%105 = tail call i32 @printDump(i64 %96, i8* %31, i64 %97, i32 %69)
%106 = tail call i32 @free(i8* %31)
br label %107
107: ; preds = %99, %103, %91, %25, %75, %33, %4
%108 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %25 ], [ @EXIT_FAILURE, %33 ], [ @EXIT_FAILURE, %75 ], [ @EXIT_FAILURE, %91 ], [ @EXIT_FAILURE, %99 ], [ @EXIT_SUCCESS, %103 ]
%109 = load i32, i32* %108
ret i32 %109
}