#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  int st_size;
};

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int S_IRWXG;
int S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ecc_block_fill(unsigned char *, int, unsigned char *, int,
                                  int, int);
int /*<<< orphan*/ err_msg(char *);
int fstat(int, struct stat *);
int la2pa(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int open(char *, int, ...);
int read(int, unsigned char *, int);
scalar_t__ strcmp(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ usage_exit(int, char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int ret;
  int ecc_fd;
  int part_fd;
  struct stat s;
  unsigned char *ecc_block;
  int ecc_block_len;
  unsigned char *tmp_block;
  int tmp_block_len;
  unsigned char *part;
  int part_len;
  int off_begin;
  int off_end;
  if (argc < 4) {
    usage_exit(1, argv[0]);
  }
  ret = 0;
  ecc_fd = 0;
  part_fd = 0;
  do {
    if (strcmp(argv[1], "create") == 0) {
      if (argc != 4) {
        ret = -1;
        break;
      }
      ecc_fd = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG);
      if (ecc_fd <= 0) {
        err_msg("failed open file");
        ret = -1;
        break;
      }
      tmp_block_len = strtol(argv[3], NULL, 16);
      if (tmp_block_len <= 0) {
        err_msg("incorrect length");
        ret = -1;
        break;
      }
      ecc_block_len = la2pa(tmp_block_len);
      tmp_block = malloc(tmp_block_len);
      ecc_block = malloc(ecc_block_len);
      memset(tmp_block, 0xff, tmp_block_len);
      memset(ecc_block, 0x00, ecc_block_len);
      ecc_block_fill(ecc_block, ecc_block_len, tmp_block, tmp_block_len, 0,
                     tmp_block_len - 1);
      write(ecc_fd, ecc_block, ecc_block_len);
    } else if (strcmp(argv[1], "fill") == 0) {
      ecc_fd = open(argv[2], O_RDWR);
      if (ecc_fd <= 0) {
        err_msg("failed open file");
        ret = -1;
        break;
      }
      part_fd = open(argv[3], O_RDONLY);
      if (part_fd <= 0) {
        err_msg("failed open file");
        ret = -1;
        break;
      }
      ret = fstat(ecc_fd, &s);
      if (ret != 0) {
        err_msg("fstat ecc fd failed");
        ret = -1;
        break;
      }
      ecc_block_len = s.st_size;
      ecc_block = malloc(ecc_block_len);
      ret = read(ecc_fd, ecc_block, ecc_block_len);
      if (ret != ecc_block_len) {
        err_msg("read ecc block failed");
        ret = -1;
        break;
      }
      ret = fstat(part_fd, &s);
      if (ret != 0) {
        err_msg("fstat part fd failed");
        ret = -1;
        break;
      }
      part_len = s.st_size;
      part = malloc(part_len);
      ret = read(part_fd, part, part_len);
      if (ret != part_len) {
        err_msg("read part failed");
        ret = -1;
        break;
      }
      off_begin = strtol(argv[4], NULL, 16);
      off_end = strtol(argv[5], NULL, 16);
      if ((off_begin < 0) || (off_end < 0)) {
        err_msg("incorrect offset");
        ret = -1;
        break;
      }
      ecc_block_fill(ecc_block, ecc_block_len, part, part_len, off_begin,
                     off_end);
      lseek(ecc_fd, 0, SEEK_SET);
      write(ecc_fd, ecc_block, ecc_block_len);
    } else {
      usage_exit(1, argv[0]);
    }
  } while (0);
  if (ecc_fd > 0) {
    close(ecc_fd);
  }
  if (part_fd > 0) {
    close(part_fd);
  }
  return ret;
  {
    unsigned char *tmp_block;
    int tmp_block_len = 24;
    unsigned char *ecc_block;
    int ecc_block_len = la2pa(tmp_block_len);
    unsigned char *part;
    int part_len = 8;
    int i;
    tmp_block = malloc(tmp_block_len);
    ecc_block = malloc(ecc_block_len);
    part = malloc(part_len);
    memset(tmp_block, 0xaa, tmp_block_len);
    memset(ecc_block, 0x00, ecc_block_len);
    memset(part, 0x1e, part_len);
    for (i = 0; i < part_len; i += 4) {
      part[i + 0] = 0x00;
      part[i + 1] = 0x60;
      part[i + 2] = 0x09;
      part[i + 3] = 0x40;
    }
    ecc_block_fill(ecc_block, ecc_block_len, tmp_block, tmp_block_len, 0,
                   tmp_block_len - 1);
    ecc_block_fill(ecc_block, ecc_block_len, part, part_len, 16, 23);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1214 <main+0x34>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
call   10d0 <usage_exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc8(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    136d <main+0x18d>
cmpl   $0x4,-0x8(%rbp)
je     125d <main+0x7d>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
mov    0x2d83(%rip),%rax
or     (%rax),%esi
mov    0x2d72(%rip),%rax
or     (%rax),%esi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    0x2d38(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     12be <main+0xde>
lea    0xd5a(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jg     12f9 <main+0x119>
lea    0xd30(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x3c(%rbp),%edi
call   1080 <la2pa@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x3c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    $0xff,%esi
call   1060 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x3c(%rbp),%r9d
sub    $0x1,%r9d
xor    %r8d,%r8d
call   1040 <ecc_block_fill@plt>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
jmp    15ad <main+0x3cd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcad(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1597 <main+0x3b7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2c36(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     13c8 <main+0x1e8>
lea    0xc50(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2be9(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1405 <main+0x225>
lea    0xc13(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1100 <fstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1436 <main+0x256>
lea    0xc09(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     147e <main+0x29e>
lea    0xbd5(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1100 <fstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     14af <main+0x2cf>
lea    0xbba(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4c(%rbp),%eax
je     14f7 <main+0x317>
lea    0xb87(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x50(%rbp)
jl     153d <main+0x35d>
cmpl   $0x0,-0x54(%rbp)
jge    1555 <main+0x375>
lea    0xb3a(%rip),%rdi
call   10f0 <err_msg@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    15b2 <main+0x3d2>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
mov    -0x50(%rbp),%r8d
mov    -0x54(%rbp),%r9d
call   1040 <ecc_block_fill@plt>
mov    -0x18(%rbp),%edi
mov    0x2a36(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
jmp    15a8 <main+0x3c8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
call   10d0 <usage_exit@plt>
jmp    15ad <main+0x3cd>
jmp    15b2 <main+0x3d2>
cmpl   $0x0,-0x18(%rbp)
jle    15c4 <main+0x3e4>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    15d6 <main+0x3f6>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x90,%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,%rbp
mov    %edi,%ebx
cmp    $0x3,%edi
jg     1206 <main+0x26>
mov    0x0(%rbp),%rsi
mov    $0x1,%edi
call   10d0 <usage_exit@plt>
mov    0x8(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     124a <main+0x6a>
mov    0x8(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1324 <main+0x144>
mov    0x0(%rbp),%rsi
mov    $0x1,%edi
call   10d0 <usage_exit@plt>
xor    %r13d,%r13d
jmp    141b <main+0x23b>
mov    $0xffffffff,%r13d
cmp    $0x4,%ebx
jne    141b <main+0x23b>
mov    0x10(%rbp),%rdi
mov    0x2d6c(%rip),%rax
mov    0x2d8d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d7a(%rip),%rax
or     (%rax),%esi
mov    0x2d59(%rip),%rax
mov    0x2d42(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
jle    138e <main+0x1ae>
mov    %eax,%r14d
mov    0x18(%rbp),%rdi
xor    %r13d,%r13d
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
test   %eax,%eax
jle    13a5 <main+0x1c5>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <la2pa@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   10c0 <malloc@plt>
mov    %rax,%r12
mov    %r15d,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0xff,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    %ebp,%r9d
add    $0xffffffff,%r9d
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
xor    %r8d,%r8d
call   1040 <ecc_block_fill@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
mov    %r14d,%edi
jmp    1416 <main+0x236>
mov    0x10(%rbp),%rdi
mov    0x2ca1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
jle    1377 <main+0x197>
mov    %eax,%r14d
mov    0x18(%rbp),%rdi
mov    0x2c76(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
jle    139c <main+0x1bc>
mov    %eax,%r15d
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
call   1100 <fstat@plt>
test   %eax,%eax
je     13bc <main+0x1dc>
lea    0xcbc(%rip),%rdi
jmp    1400 <main+0x220>
lea    0xc89(%rip),%rdi
call   10f0 <err_msg@plt>
mov    $0xffffffff,%r13d
jmp    141b <main+0x23b>
lea    0xc72(%rip),%rdi
call   10f0 <err_msg@plt>
jmp    141b <main+0x23b>
lea    0xc64(%rip),%rdi
jmp    13ac <main+0x1cc>
lea    0xc6c(%rip),%rdi
call   10f0 <err_msg@plt>
mov    $0xffffffff,%r13d
mov    %r14d,%edi
jmp    1416 <main+0x236>
mov    0x8(%rsp),%r12d
mov    %r12d,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
mov    %rax,%rsi
mov    %r12d,%edx
call   1090 <read@plt>
cmp    %r12d,%eax
jne    13f9 <main+0x219>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
call   1100 <fstat@plt>
test   %eax,%eax
je     142d <main+0x24d>
lea    0xc61(%rip),%rdi
jmp    1400 <main+0x220>
lea    0xc42(%rip),%rdi
call   10f0 <err_msg@plt>
mov    $0xffffffff,%r13d
mov    %r14d,%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%r13d
mov    %r13d,%edi
call   10c0 <malloc@plt>
mov    %r15d,%edi
mov    %rax,0x10(%rsp)
mov    %rax,%rsi
mov    %r13d,%edx
call   1090 <read@plt>
cmp    %r13d,%eax
jne    14c0 <main+0x2e0>
mov    0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
mov    %eax,0xc(%rsp)
mov    0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
mov    0xc(%rsp),%r8d
test   %r8d,%r8d
js     14cc <main+0x2ec>
test   %eax,%eax
js     14cc <main+0x2ec>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    0x10(%rsp),%rdx
mov    %r13d,%ecx
mov    %eax,%r9d
call   1040 <ecc_block_fill@plt>
mov    0x2b0f(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
jmp    140b <main+0x22b>
lea    0xba6(%rip),%rdi
jmp    1400 <main+0x220>
lea    0xbab(%rip),%rdi
jmp    1400 <main+0x220>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"create\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@.str.1 = [17 x i8] c"failed open file\00"
@.str.2 = [17 x i8] c"incorrect length\00"
@.str.3 = [5 x i8] c"fill\00"
@O_RDONLY = global i32 0
@.str.4 = [20 x i8] c"fstat ecc fd failed\00"
@.str.5 = [22 x i8] c"read ecc block failed\00"
@.str.6 = [21 x i8] c"fstat part fd failed\00"
@.str.7 = [17 x i8] c"read part failed\00"
@.str.8 = [17 x i8] c"incorrect offset\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i32
%22 = alloca i8*
%23 = alloca i32
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 4
br i1 %26, label %27, label %32
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage_exit(i32 1, i8* %30)
br label %32
32: ; preds = %27, %2
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %33
33: ; preds = %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %93
39: ; preds = %33
%40 = load i32, i32* %4
%41 = icmp ne i32 %40, 4
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 -1, i32* %6
br label %199
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = load i32, i32* @O_RDWR
%48 = load i32, i32* @O_CREAT
%49 = or i32 %47, %48
%50 = load i32, i32* @O_TRUNC
%51 = or i32 %49, %50
%52 = load i32, i32* @S_IRWXU
%53 = load i32, i32* @S_IRWXG
%54 = or i32 %52, %53
%55 = call i32 (i8*, i32, ...) @open(i8* %46, i32 %51, i32 %54)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp sle i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %43
%59 = call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
60: ; preds = %43
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 3
%63 = load i8*, i8** %62
%64 = call i32 @strtol(i8* %63, i32* null, i32 16)
store i32 %64, i32* %13
%65 = load i32, i32* %13
%66 = icmp sle i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %60
%68 = call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
69: ; preds = %60
%70 = load i32, i32* %13
%71 = call i32 @la2pa(i32 %70)
store i32 %71, i32* %11
%72 = load i32, i32* %13
%73 = call i8* @malloc(i32 %72)
store i8* %73, i8** %12
%74 = load i32, i32* %11
%75 = call i8* @malloc(i32 %74)
store i8* %75, i8** %10
%76 = load i8*, i8** %12
%77 = load i32, i32* %13
%78 = call i32 @memset(i8* %76, i32 255, i32 %77)
%79 = load i8*, i8** %10
%80 = load i32, i32* %11
%81 = call i32 @memset(i8* %79, i32 0, i32 %80)
%82 = load i8*, i8** %10
%83 = load i32, i32* %11
%84 = load i8*, i8** %12
%85 = load i32, i32* %13
%86 = load i32, i32* %13
%87 = sub nsw i32 %86, 1
%88 = call i32 @ecc_block_fill(i8* %82, i32 %83, i8* %84, i32 %85, i32 0, i32 %87)
%89 = load i32, i32* %7
%90 = load i8*, i8** %10
%91 = load i32, i32* %11
%92 = call i32 @write(i32 %89, i8* %90, i32 %91)
br label %198
93: ; preds = %33
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 1
%96 = load i8*, i8** %95
%97 = call i64 @strcmp(i8* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %192
99: ; preds = %93
%100 = load i8**, i8*** %5
%101 = getelementptr inbounds i8*, i8** %100, i64 2
%102 = load i8*, i8** %101
%103 = load i32, i32* @O_RDWR
%104 = call i32 (i8*, i32, ...) @open(i8* %102, i32 %103)
store i32 %104, i32* %7
%105 = load i32, i32* %7
%106 = icmp sle i32 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %99
%108 = call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
109: ; preds = %99
%110 = load i8**, i8*** %5
%111 = getelementptr inbounds i8*, i8** %110, i64 3
%112 = load i8*, i8** %111
%113 = load i32, i32* @O_RDONLY
%114 = call i32 (i8*, i32, ...) @open(i8* %112, i32 %113)
store i32 %114, i32* %8
%115 = load i32, i32* %8
%116 = icmp sle i32 %115, 0
br i1 %116, label %117, label %119
117: ; preds = %109
%118 = call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
119: ; preds = %109
%120 = load i32, i32* %7
%121 = call i32 @fstat(i32 %120, %struct.stat* %9)
store i32 %121, i32* %6
%122 = load i32, i32* %6
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %119
%125 = call i32 @err_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
126: ; preds = %119
%127 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%128 = load i32, i32* %127
store i32 %128, i32* %11
%129 = load i32, i32* %11
%130 = call i8* @malloc(i32 %129)
store i8* %130, i8** %10
%131 = load i32, i32* %7
%132 = load i8*, i8** %10
%133 = load i32, i32* %11
%134 = call i32 @read(i32 %131, i8* %132, i32 %133)
store i32 %134, i32* %6
%135 = load i32, i32* %6
%136 = load i32, i32* %11
%137 = icmp ne i32 %135, %136
br i1 %137, label %138, label %140
138: ; preds = %126
%139 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
140: ; preds = %126
%141 = load i32, i32* %8
%142 = call i32 @fstat(i32 %141, %struct.stat* %9)
store i32 %142, i32* %6
%143 = load i32, i32* %6
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %147
145: ; preds = %140
%146 = call i32 @err_msg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
147: ; preds = %140
%148 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%149 = load i32, i32* %148
store i32 %149, i32* %15
%150 = load i32, i32* %15
%151 = call i8* @malloc(i32 %150)
store i8* %151, i8** %14
%152 = load i32, i32* %8
%153 = load i8*, i8** %14
%154 = load i32, i32* %15
%155 = call i32 @read(i32 %152, i8* %153, i32 %154)
store i32 %155, i32* %6
%156 = load i32, i32* %6
%157 = load i32, i32* %15
%158 = icmp ne i32 %156, %157
br i1 %158, label %159, label %161
159: ; preds = %147
%160 = call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
161: ; preds = %147
%162 = load i8**, i8*** %5
%163 = getelementptr inbounds i8*, i8** %162, i64 4
%164 = load i8*, i8** %163
%165 = call i32 @strtol(i8* %164, i32* null, i32 16)
store i32 %165, i32* %16
%166 = load i8**, i8*** %5
%167 = getelementptr inbounds i8*, i8** %166, i64 5
%168 = load i8*, i8** %167
%169 = call i32 @strtol(i8* %168, i32* null, i32 16)
store i32 %169, i32* %17
%170 = load i32, i32* %16
%171 = icmp slt i32 %170, 0
br i1 %171, label %175, label %172
172: ; preds = %161
%173 = load i32, i32* %17
%174 = icmp slt i32 %173, 0
br i1 %174, label %175, label %177
175: ; preds = %172, %161
%176 = call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %6
br label %199
177: ; preds = %172
%178 = load i8*, i8** %10
%179 = load i32, i32* %11
%180 = load i8*, i8** %14
%181 = load i32, i32* %15
%182 = load i32, i32* %16
%183 = load i32, i32* %17
%184 = call i32 @ecc_block_fill(i8* %178, i32 %179, i8* %180, i32 %181, i32 %182, i32 %183)
%185 = load i32, i32* %7
%186 = load i32, i32* @SEEK_SET
%187 = call i32 @lseek(i32 %185, i32 0, i32 %186)
%188 = load i32, i32* %7
%189 = load i8*, i8** %10
%190 = load i32, i32* %11
%191 = call i32 @write(i32 %188, i8* %189, i32 %190)
br label %197
192: ; preds = %93
%193 = load i8**, i8*** %5
%194 = getelementptr inbounds i8*, i8** %193, i64 0
%195 = load i8*, i8** %194
%196 = call i32 @usage_exit(i32 1, i8* %195)
br label %197
197: ; preds = %192, %177
br label %198
198: ; preds = %197, %69
br label %199
199: ; preds = %198, %175, %159, %145, %138, %124, %117, %107, %67, %58, %42
%200 = load i32, i32* %7
%201 = icmp sgt i32 %200, 0
br i1 %201, label %202, label %205
202: ; preds = %199
%203 = load i32, i32* %7
%204 = call i32 @close(i32 %203)
br label %205
205: ; preds = %202, %199
%206 = load i32, i32* %8
%207 = icmp sgt i32 %206, 0
br i1 %207, label %208, label %211
208: ; preds = %205
%209 = load i32, i32* %8
%210 = call i32 @close(i32 %209)
br label %211
211: ; preds = %208, %205
%212 = load i32, i32* %6
ret i32 %212
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"create\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@.str.1 = [17 x i8] c"failed open file\00"
@.str.2 = [17 x i8] c"incorrect length\00"
@.str.3 = [5 x i8] c"fill\00"
@O_RDONLY = global i32 0
@.str.4 = [20 x i8] c"fstat ecc fd failed\00"
@.str.5 = [22 x i8] c"read ecc block failed\00"
@.str.6 = [21 x i8] c"fstat part fd failed\00"
@.str.7 = [17 x i8] c"read part failed\00"
@.str.8 = [17 x i8] c"incorrect offset\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage_exit(i32 1, i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %47
14: ; preds = %9
%15 = icmp eq i32 %0, 4
br i1 %15, label %16, label %120
16: ; preds = %14
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDWR
%20 = load i32, i32* @O_CREAT
%21 = or i32 %20, %19
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IRWXU
%25 = load i32, i32* @S_IRWXG
%26 = or i32 %25, %24
%27 = tail call i32 (i8*, i32, ...) @open(i8* %18, i32 %23, i32 %26)
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %16
%30 = tail call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %120
31: ; preds = %16
%32 = getelementptr inbounds i8*, i8** %1, i64 3
%33 = load i8*, i8** %32
%34 = tail call i32 @strtol(i8* nocapture %33, i32* null, i32 16)
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = tail call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %112
38: ; preds = %31
%39 = tail call i32 @la2pa(i32 %34)
%40 = tail call i8* @malloc(i32 %34)
%41 = tail call i8* @malloc(i32 %39)
%42 = tail call i32 @memset(i8* %40, i32 255, i32 %34)
%43 = tail call i32 @memset(i8* %41, i32 0, i32 %39)
%44 = add nsw i32 %34, -1
%45 = tail call i32 @ecc_block_fill(i8* %41, i32 %39, i8* %40, i32 %34, i32 0, i32 %44)
%46 = tail call i32 @write(i32 %27, i8* %41, i32 %39)
br label %112
47: ; preds = %9
%48 = load i8*, i8** %10
%49 = tail call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %109
51: ; preds = %47
%52 = getelementptr inbounds i8*, i8** %1, i64 2
%53 = load i8*, i8** %52
%54 = load i32, i32* @O_RDWR
%55 = tail call i32 (i8*, i32, ...) @open(i8* %53, i32 %54)
%56 = icmp slt i32 %55, 1
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = tail call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %120
59: ; preds = %51
%60 = getelementptr inbounds i8*, i8** %1, i64 3
%61 = load i8*, i8** %60
%62 = load i32, i32* @O_RDONLY
%63 = tail call i32 (i8*, i32, ...) @open(i8* %61, i32 %62)
%64 = icmp slt i32 %63, 1
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = tail call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %112
67: ; preds = %59
%68 = call i32 @fstat(i32 %55, %struct.stat* %3)
%69 = icmp eq i32 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %67
%71 = tail call i32 @err_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %116
72: ; preds = %67
%73 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%74 = load i32, i32* %73
%75 = tail call i8* @malloc(i32 %74)
%76 = tail call i32 @read(i32 %55, i8* %75, i32 %74)
%77 = icmp eq i32 %76, %74
br i1 %77, label %80, label %78
78: ; preds = %72
%79 = tail call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %116
80: ; preds = %72
%81 = call i32 @fstat(i32 %63, %struct.stat* %3)
%82 = icmp eq i32 %81, 0
br i1 %82, label %85, label %83
83: ; preds = %80
%84 = tail call i32 @err_msg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %116
85: ; preds = %80
%86 = load i32, i32* %73
%87 = tail call i8* @malloc(i32 %86)
%88 = tail call i32 @read(i32 %63, i8* %87, i32 %86)
%89 = icmp eq i32 %88, %86
br i1 %89, label %92, label %90
90: ; preds = %85
%91 = tail call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %116
92: ; preds = %85
%93 = getelementptr inbounds i8*, i8** %1, i64 4
%94 = load i8*, i8** %93
%95 = tail call i32 @strtol(i8* nocapture %94, i32* null, i32 16)
%96 = getelementptr inbounds i8*, i8** %1, i64 5
%97 = load i8*, i8** %96
%98 = tail call i32 @strtol(i8* nocapture %97, i32* null, i32 16)
%99 = icmp slt i32 %95, 0
%100 = icmp slt i32 %98, 0
%101 = select i1 %99, i1 true, i1 %100
br i1 %101, label %102, label %104
102: ; preds = %92
%103 = tail call i32 @err_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %116
104: ; preds = %92
%105 = tail call i32 @ecc_block_fill(i8* %75, i32 %74, i8* %87, i32 %86, i32 %95, i32 %98)
%106 = load i32, i32* @SEEK_SET
%107 = tail call i32 @lseek(i32 %55, i32 0, i32 %106)
%108 = tail call i32 @write(i32 %55, i8* %75, i32 %74)
br label %116
109: ; preds = %47
%110 = load i8*, i8** %1
%111 = tail call i32 @usage_exit(i32 1, i8* %110)
br label %120
112: ; preds = %65, %38, %36
%113 = phi i32 [ %55, %65 ], [ %27, %38 ], [ %27, %36 ]
%114 = phi i32 [ -1, %65 ], [ 0, %38 ], [ -1, %36 ]
%115 = tail call i32 @close(i32 %113)
br label %120
116: ; preds = %104, %102, %90, %83, %78, %70
%117 = phi i32 [ -1, %70 ], [ -1, %78 ], [ -1, %83 ], [ -1, %90 ], [ -1, %102 ], [ %86, %104 ]
%118 = tail call i32 @close(i32 %55)
%119 = tail call i32 @close(i32 %63)
br label %120
120: ; preds = %14, %109, %57, %29, %112, %116
%121 = phi i32 [ %117, %116 ], [ %114, %112 ], [ -1, %14 ], [ 0, %109 ], [ -1, %57 ], [ -1, %29 ]
ret i32 %121
}