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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
void *getLong(char *, int, char *);
int /*<<< orphan*/ isprint(unsigned char);
int lseek(int, void *, int /*<<< orphan*/);
char *malloc(size_t);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, size_t);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  size_t len;
  off_t offset;
  int fd, ap, j;
  char *buf;
  ssize_t num_read, num_written;
  if (argc < 3 || strcmp(argv[1], "--help") == 0) {
    printf("%s file {r<length>|R<length>|w<string>|s<offset>}...\n", argv[0]);
    exit(1);
  }
  fd = open(argv[1], O_RDWR | O_CREAT,
            S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  if (fd == -1) {
    perror("open error");
    exit(1);
  }
  for (ap = 2; ap < argc; ap++) {
    switch (argv[ap][0]) {
    case 'r':
    case 'R':
      len = getLong(&argv[ap][1], 0100, argv[ap]);
      buf = malloc(len);
      if (buf == NULL) {
        perror("malloc");
        exit(1);
      }
      num_read = read(fd, buf, len);
      if (num_read == -1) {
        perror("read error");
        exit(1);
      }
      if (num_read == 0) {
        printf("%s: end-of-file\n", argv[ap]);
      } else {
        printf("%s: ", argv[ap]);
        for (j = 0; j < num_read; j++) {
          if (argv[ap][0] == 'r') {
            printf("%c", isprint((unsigned char)buf[j]) ? buf[j] : '?');
          } else {
            printf("%02x ", (unsigned int)buf[j]);
          }
        }
        printf("\n");
      }
      free(buf);
      break;
    case 'w':
      num_written = write(fd, &argv[ap][1], strlen(&argv[ap][1]));
      if (num_written == -1) {
        perror("write error");
        exit(1);
      }
      printf("%s wrote %ld bytes\n", argv[ap], (long)num_written);
      break;
    case 's':
      offset = getLong(&argv[ap][1], 0100, argv[ap]);
      if (lseek(fd, offset, SEEK_SET) == -1) {
        perror("lseek error");
        exit(1);
      }
      printf("%s: seek successed\n", argv[ap]);
      break;
    default:
      printf("Argument must start with [rRws]: %s\n", argv[ap]);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     120e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe99(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    122d <main+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
mov    0x2db3(%rip),%rax
or     (%rax),%esi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
mov    0x2d79(%rip),%rax
or     (%rax),%edx
mov    0x2d58(%rip),%rax
or     (%rax),%edx
mov    0x2d6f(%rip),%rax
or     (%rax),%edx
mov    0x2d3e(%rip),%rax
or     (%rax),%edx
mov    0x2d1d(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12a5 <main+0xd5>
lea    0xe3f(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    15ad <main+0x3dd>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
add    $0xffffffae,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x25,%eax
ja     1580 <main+0x3b0>
mov    -0x48(%rbp),%rax
lea    0xd1c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x40,%esi
call   10a0 <getLong@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1345 <main+0x175>
lea    0xdaa(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <read@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1378 <main+0x1a8>
lea    0xd7e(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    13a1 <main+0x1d1>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1472 <main+0x2a2>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1464 <main+0x294>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    1437 <main+0x267>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   10c0 <isprint@plt>
cmp    $0x0,%eax
je     1414 <main+0x244>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4c(%rbp)
jmp    1421 <main+0x251>
mov    $0x3f,%eax
mov    %eax,-0x4c(%rbp)
jmp    1421 <main+0x251>
mov    -0x4c(%rbp),%esi
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1451 <main+0x281>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1456 <main+0x286>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    13c2 <main+0x1f2>
lea    0xc68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    159a <main+0x3ca>
mov    -0x24(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
call   1050 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    14e0 <main+0x310>
lea    0xc40(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x40(%rbp),%rdx
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    159a <main+0x3ca>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x40,%esi
call   10a0 <getLong@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2a85(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1561 <main+0x391>
lea    0xbdf(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    159a <main+0x3ca>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xbbe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    159f <main+0x3cf>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12ac <main+0xdc>
xor    %eax,%eax
add    $0x60,%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
cmp    $0x3,%edi
jl     14ae <main+0x2ce>
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
lea    0xe91(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     14ae <main+0x2ce>
mov    0x2dc4(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d7a(%rip),%rax
mov    0x2d9b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d78(%rip),%rax
or     (%rax),%edx
mov    0x2d8f(%rip),%rax
or     (%rax),%edx
mov    0x2d5e(%rip),%rax
or     (%rax),%edx
mov    %rbx,(%rsp)
mov    0x8(%rbx),%rdi
mov    0x2d35(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     14c9 <main+0x2e9>
mov    %eax,%r14d
mov    %ebp,%r15d
mov    $0x2,%r13d
lea    0xd7a(%rip),%rbx
mov    %eax,0xc(%rsp)
mov    %r15,0x10(%rsp)
jmp    12be <main+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xea7(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r13
cmp    %r15,%r13
je     146c <main+0x28c>
mov    (%rsp),%rax
mov    (%rax,%r13,8),%rbp
movsbl 0x0(%rbp),%eax
add    $0xffffffae,%eax
cmp    $0x25,%eax
ja     12a0 <main+0xc0>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
lea    0x1(%rbp),%rdi
mov    $0x40,%esi
mov    %rbp,%rdx
call   10b0 <getLong@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10c0 <malloc@plt>
test   %rax,%rax
je     147d <main+0x29d>
mov    %rax,%r12
mov    %r14d,%edi
mov    %rax,%rsi
mov    %rbp,%rdx
call   1090 <read@plt>
test   %eax,%eax
mov    (%rsp),%rbx
je     1430 <main+0x250>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1486 <main+0x2a6>
mov    (%rbx,%r13,8),%rsi
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebp,%ebp
jle    1444 <main+0x264>
mov    %ebp,%r15d
xor    %r14d,%r14d
jmp    136d <main+0x18d>
nopw   0x0(%rax,%rax,1)
lea    0xdb1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r15
je     1444 <main+0x264>
mov    (%rbx,%r13,8),%rax
cmpb   $0x72,(%rax)
movsbl (%r12,%r14,1),%ebp
jne    1350 <main+0x170>
movzbl %bpl,%edi
call   10d0 <isprint@plt>
test   %eax,%eax
mov    $0x3f,%eax
cmove  %eax,%ebp
mov    %ebp,%edi
call   1040 <putchar@plt>
jmp    1360 <main+0x180>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbp),%rdi
mov    $0x40,%esi
mov    %rbp,%rdx
call   10b0 <getLong@plt>
mov    0x2c08(%rip),%rcx
mov    (%rcx),%edx
mov    %r14d,%edi
mov    %rax,%rsi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
je     148f <main+0x2af>
mov    (%rsp),%rax
mov    (%rax,%r13,8),%rsi
lea    0xd5d(%rip),%rdi
jmp    12aa <main+0xca>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
je     1498 <main+0x2b8>
mov    (%rsp),%rcx
mov    (%rcx,%r13,8),%rsi
movslq %eax,%rdx
lea    0xcf6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12b1 <main+0xd1>
mov    (%rbx,%r13,8),%rsi
lea    0xcb7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1458 <main+0x278>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%r14d
mov    0x10(%rsp),%r15
mov    %r12,%rdi
call   1030 <free@plt>
lea    0xb99(%rip),%rbx
jmp    12b1 <main+0xd1>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc5c(%rip),%rdi
jmp    149f <main+0x2bf>
lea    0xc5a(%rip),%rdi
jmp    149f <main+0x2bf>
lea    0xc98(%rip),%rdi
jmp    149f <main+0x2bf>
lea    0xc6f(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    (%rbx),%rsi
lea    0xbe7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc05(%rip),%rdi
jmp    149f <main+0x2bf>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [54 x i8] c"%s file {r<length>|R<length>|w<string>|s<offset>}...\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.2 = [11 x i8] c"open error\00"
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [11 x i8] c"read error\00"
@.str.5 = [17 x i8] c"%s: end-of-file\0A\00"
@.str.6 = [5 x i8] c"%s: \00"
@.str.7 = [3 x i8] c"%c\00"
@.str.8 = [6 x i8] c"%02x \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [12 x i8] c"write error\00"
@.str.11 = [20 x i8] c"%s wrote %ld bytes\0A\00"
@SEEK_SET = global i32 0
@.str.12 = [12 x i8] c"lseek error\00"
@.str.13 = [20 x i8] c"%s: seek successed\0A\00"
@.str.14 = [37 x i8] c"Argument must start with [rRws]: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_RDWR
%33 = load i32, i32* @O_CREAT
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IRGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IWGRP
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IROTH
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWOTH
%45 = or i32 %43, %44
%46 = call i32 @open(i8* %31, i32 %34, i32 %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %28
%50 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %28
store i32 2, i32* %9
br label %53
53: ; preds = %230, %52
%54 = load i32, i32* %9
%55 = load i32, i32* %4
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %233
57: ; preds = %53
%58 = load i8**, i8*** %5
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
switch i32 %65, label %222 [
i32 114, label %66
i32 82, label %66
i32 119, label %164
i32 115, label %194
]
66: ; preds = %57, %57
%67 = load i8**, i8*** %5
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = getelementptr inbounds i8, i8* %71, i64 1
%73 = load i8**, i8*** %5
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
%78 = call i8* @getLong(i8* %72, i32 64, i8* %77)
%79 = ptrtoint i8* %78 to i64
store i64 %79, i64* %6
%80 = load i64, i64* %6
%81 = call i8* @malloc(i64 %80)
store i8* %81, i8** %11
%82 = load i8*, i8** %11
%83 = icmp eq i8* %82, null
br i1 %83, label %84, label %87
84: ; preds = %66
%85 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %66
%88 = load i32, i32* %8
%89 = load i8*, i8** %11
%90 = load i64, i64* %6
%91 = call i32 @read(i32 %88, i8* %89, i64 %90)
store i32 %91, i32* %12
%92 = load i32, i32* %12
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %87
%95 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %87
%98 = load i32, i32* %12
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %107
100: ; preds = %97
%101 = load i8**, i8*** %5
%102 = load i32, i32* %9
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8*, i8** %101, i64 %103
%105 = load i8*, i8** %104
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %105)
br label %161
107: ; preds = %97
%108 = load i8**, i8*** %5
%109 = load i32, i32* %9
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %108, i64 %110
%112 = load i8*, i8** %111
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %112)
store i32 0, i32* %10
br label %114
114: ; preds = %156, %107
%115 = load i32, i32* %10
%116 = load i32, i32* %12
%117 = icmp slt i32 %115, %116
br i1 %117, label %118, label %159
118: ; preds = %114
%119 = load i8**, i8*** %5
%120 = load i32, i32* %9
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = getelementptr inbounds i8, i8* %123, i64 0
%125 = load i8, i8* %124
%126 = sext i8 %125 to i32
%127 = icmp eq i32 %126, 114
br i1 %127, label %128, label %147
128: ; preds = %118
%129 = load i8*, i8** %11
%130 = load i32, i32* %10
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %129, i64 %131
%133 = load i8, i8* %132
%134 = call i32 @isprint(i8 zeroext %133)
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %143
136: ; preds = %128
%137 = load i8*, i8** %11
%138 = load i32, i32* %10
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds i8, i8* %137, i64 %139
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
br label %144
143: ; preds = %128
br label %144
144: ; preds = %143, %136
%145 = phi i32 [ %142, %136 ], [ 63, %143 ]
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %145)
br label %155
147: ; preds = %118
%148 = load i8*, i8** %11
%149 = load i32, i32* %10
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8, i8* %148, i64 %150
%152 = load i8, i8* %151
%153 = sext i8 %152 to i32
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %153)
br label %155
155: ; preds = %147, %144
br label %156
156: ; preds = %155
%157 = load i32, i32* %10
%158 = add nsw i32 %157, 1
store i32 %158, i32* %10
br label %114
159: ; preds = %114
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %161
161: ; preds = %159, %100
%162 = load i8*, i8** %11
%163 = call i32 @free(i8* %162)
br label %229
164: ; preds = %57
%165 = load i32, i32* %8
%166 = load i8**, i8*** %5
%167 = load i32, i32* %9
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i8*, i8** %166, i64 %168
%170 = load i8*, i8** %169
%171 = getelementptr inbounds i8, i8* %170, i64 1
%172 = load i8**, i8*** %5
%173 = load i32, i32* %9
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds i8*, i8** %172, i64 %174
%176 = load i8*, i8** %175
%177 = getelementptr inbounds i8, i8* %176, i64 1
%178 = call i32 @strlen(i8* %177)
%179 = call i32 @write(i32 %165, i8* %171, i32 %178)
store i32 %179, i32* %13
%180 = load i32, i32* %13
%181 = icmp eq i32 %180, -1
br i1 %181, label %182, label %185
182: ; preds = %164
%183 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%184 = call i32 @exit(i32 1)
unreachable
185: ; preds = %164
%186 = load i8**, i8*** %5
%187 = load i32, i32* %9
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8*, i8** %186, i64 %188
%190 = load i8*, i8** %189
%191 = load i32, i32* %13
%192 = sext i32 %191 to i64
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i8* %190, i64 %192)
br label %229
194: ; preds = %57
%195 = load i8**, i8*** %5
%196 = load i32, i32* %9
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds i8*, i8** %195, i64 %197
%199 = load i8*, i8** %198
%200 = getelementptr inbounds i8, i8* %199, i64 1
%201 = load i8**, i8*** %5
%202 = load i32, i32* %9
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds i8*, i8** %201, i64 %203
%205 = load i8*, i8** %204
%206 = call i8* @getLong(i8* %200, i32 64, i8* %205)
store i8* %206, i8** %7
%207 = load i32, i32* %8
%208 = load i8*, i8** %7
%209 = load i32, i32* @SEEK_SET
%210 = call i32 @lseek(i32 %207, i8* %208, i32 %209)
%211 = icmp eq i32 %210, -1
br i1 %211, label %212, label %215
212: ; preds = %194
%213 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%214 = call i32 @exit(i32 1)
unreachable
215: ; preds = %194
%216 = load i8**, i8*** %5
%217 = load i32, i32* %9
%218 = sext i32 %217 to i64
%219 = getelementptr inbounds i8*, i8** %216, i64 %218
%220 = load i8*, i8** %219
%221 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i8* %220)
br label %229
222: ; preds = %57
%223 = load i8**, i8*** %5
%224 = load i32, i32* %9
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds i8*, i8** %223, i64 %225
%227 = load i8*, i8** %226
%228 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0), i8* %227)
br label %229
229: ; preds = %222, %215, %185, %161
br label %230
230: ; preds = %229
%231 = load i32, i32* %9
%232 = add nsw i32 %231, 1
store i32 %232, i32* %9
br label %53
233: ; preds = %53
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [54 x i8] c"%s file {r<length>|R<length>|w<string>|s<offset>}...\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.2 = [11 x i8] c"open error\00"
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [11 x i8] c"read error\00"
@.str.5 = [17 x i8] c"%s: end-of-file\0A\00"
@.str.6 = [5 x i8] c"%s: \00"
@.str.8 = [6 x i8] c"%02x \00"
@.str.10 = [12 x i8] c"write error\00"
@.str.11 = [20 x i8] c"%s wrote %ld bytes\0A\00"
@SEEK_SET = global i32 0
@.str.12 = [12 x i8] c"lseek error\00"
@.str.13 = [20 x i8] c"%s: seek successed\0A\00"
@.str.14 = [37 x i8] c"Argument must start with [rRws]: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4, %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %19, %18
%21 = load i32, i32* @S_IRGRP
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IWGRP
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IROTH
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IWOTH
%28 = or i32 %26, %27
%29 = tail call i32 @open(i8* %14, i32 %17, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %33, label %31
31: ; preds = %13
%32 = zext i32 %0 to i64
br label %36
33: ; preds = %13
%34 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %31, %114
%37 = phi i64 [ 2, %31 ], [ %115, %114 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
switch i32 %41, label %112 [
i32 114, label %42
i32 82, label %42
i32 119, label %88
i32 115, label %100
]
42: ; preds = %36, %36
%43 = getelementptr inbounds i8, i8* %39, i64 1
%44 = tail call i8* @getLong(i8* %43, i32 64, i8* %39)
%45 = ptrtoint i8* %44 to i64
%46 = tail call i8* @malloc(i64 %45)
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = tail call i32 @read(i32 %29, i8* %46, i64 %45)
switch i32 %52, label %59 [
i32 -1, label %53
i32 0, label %56
]
53: ; preds = %51
%54 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %51
%57 = load i8*, i8** %38
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %57)
br label %86
59: ; preds = %51
%60 = load i8*, i8** %38
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %60)
%62 = icmp sgt i32 %52, 0
br i1 %62, label %63, label %84
63: ; preds = %59
%64 = zext i32 %52 to i64
br label %65
65: ; preds = %63, %81
%66 = phi i64 [ 0, %63 ], [ %82, %81 ]
%67 = load i8*, i8** %38
%68 = load i8, i8* %67
%69 = icmp eq i8 %68, 114
%70 = getelementptr inbounds i8, i8* %46, i64 %66
%71 = load i8, i8* %70
br i1 %69, label %72, label %78
72: ; preds = %65
%73 = tail call i32 @isprint(i8 zeroext %71)
%74 = icmp eq i32 %73, 0
%75 = sext i8 %71 to i32
%76 = select i1 %74, i32 63, i32 %75
%77 = tail call i32 @putchar(i32 %76)
br label %81
78: ; preds = %65
%79 = sext i8 %71 to i32
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %72, %78
%82 = add nuw nsw i64 %66, 1
%83 = icmp eq i64 %82, %64
br i1 %83, label %84, label %65
84: ; preds = %81, %59
%85 = tail call i32 @putchar(i32 10)
br label %86
86: ; preds = %84, %56
%87 = tail call i32 @free(i8* %46)
br label %114
88: ; preds = %36
%89 = getelementptr inbounds i8, i8* %39, i64 1
%90 = tail call i32 @strlen(i8* %89)
%91 = tail call i32 @write(i32 %29, i8* %89, i32 %90)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %96
93: ; preds = %88
%94 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%95 = tail call i32 @exit(i32 1)
unreachable
96: ; preds = %88
%97 = load i8*, i8** %38
%98 = sext i32 %91 to i64
%99 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i8* %97, i64 %98)
br label %114
100: ; preds = %36
%101 = getelementptr inbounds i8, i8* %39, i64 1
%102 = tail call i8* @getLong(i8* %101, i32 64, i8* %39)
%103 = load i32, i32* @SEEK_SET
%104 = tail call i32 @lseek(i32 %29, i8* %102, i32 %103)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %109
106: ; preds = %100
%107 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%108 = tail call i32 @exit(i32 1)
unreachable
109: ; preds = %100
%110 = load i8*, i8** %38
%111 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i8* %110)
br label %114
112: ; preds = %36
%113 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0), i8* %39)
br label %114
114: ; preds = %86, %96, %109, %112
%115 = add nuw nsw i64 %37, 1
%116 = icmp eq i64 %115, %32
br i1 %116, label %117, label %36
117: ; preds = %114
ret i32 0
}