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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  unsigned int size = 0;
  unsigned int overall_size = 0;
  unsigned int segments = 0;
  int in_fd = -1;
  int out_fd = -1;
  int state = -1;
  int i = 0;
  unsigned char byte = 0;
  unsigned char ignore_last = 0;
  if (argc != 3) {
    printf("Usage:\n\n\t lif_convert <input_file> <output_file>\n");
    exit(EXIT_FAILURE);
  }
  in_fd = open(argv[1], O_RDONLY);
  if (in_fd == -1) {
    printf("error opening %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  out_fd = open(argv[2], O_WRONLY | O_CREAT, S_IRWXU);
  if (out_fd == -1) {
    printf("error opening %s\n", argv[2]);
    exit(EXIT_FAILURE);
  }
  for (;;) {
    state = read(in_fd, &byte, 1);
    if (state == -1) {
      printf("error reading %s\n", argv[1]);
      exit(EXIT_FAILURE);
    }
    if (state == 0) {
      printf("end of %s reached\n", argv[1]);
      exit(EXIT_FAILURE);
    }
    size = byte << 8;
    state = read(in_fd, &byte, 1);
    if (state == -1) {
      printf("error reading %s\n", argv[1]);
      exit(EXIT_FAILURE);
    }
    if (state == 0) {
      printf("end of %s reached\n", argv[1]);
      break;
    }
    size |= byte;
    if (size == 0xFFFF)
      break;
    if (size & 0x1)
      ignore_last = 1;
    overall_size += size;
    segments++;
    for (i = 0; i < size; i++) {
      state = read(in_fd, &byte, 1);
      if (state == -1) {
        printf("error reading %s\n", argv[1]);
        exit(EXIT_FAILURE);
      }
      state = write(out_fd, &byte, 1);
      if (state == -1) {
        printf("error writing %s\n", argv[2]);
        exit(EXIT_FAILURE);
      }
    }
    if (ignore_last) {
      state = read(in_fd, &byte, 1);
      if (state == -1) {
        printf("error reading %s\n", argv[1]);
        exit(EXIT_FAILURE);
      }
      ignore_last = 0;
    }
  }
  close(in_fd);
  close(out_fd);
  printf("size[%x]\n", overall_size);
  printf("segments[%x]\n", segments);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x0,-0x2d(%rbp)
movb   $0x0,-0x2e(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d5 <main+0x75>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    121e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    0x2dc2(%rip),%rax
or     (%rax),%esi
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1279 <main+0x119>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    127e <main+0x11e>
mov    -0x20(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    12c0 <main+0x160>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x28(%rbp)
jne    12ee <main+0x18e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movzbl -0x2d(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    133a <main+0x1da>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x28(%rbp)
jne    135f <main+0x1ff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    149f <main+0x33f>
movzbl -0x2d(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jne    137b <main+0x21b>
jmp    149f <main+0x33f>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     138e <main+0x22e>
movb   $0x1,-0x2e(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    144a <main+0x2ea>
mov    -0x20(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    13f5 <main+0x295>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xc64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1437 <main+0x2d7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    143c <main+0x2dc>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    13a7 <main+0x247>
cmpb   $0x0,-0x2e(%rbp)
je     149a <main+0x33a>
mov    -0x20(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1496 <main+0x336>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xbc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movb   $0x0,-0x2e(%rbp)
jmp    127e <main+0x11e>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%esi
lea    0xbc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ae8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0x7(%rsp)
cmp    $0x3,%edi
jne    11aa <main+0x3a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    11b8 <main+0x48>
mov    0x8(%rbx),%rsi
jmp    11ec <main+0x7c>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
jmp    11fa <main+0x8a>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
mov    0x2deb(%rip),%rax
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    1208 <main+0x98>
mov    0x10(%rbx),%rsi
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%r13d
mov    %rbx,0x8(%rsp)
lea    0x7(%rsp),%rbx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
je     132c <main+0x1bc>
cmp    $0xffffffff,%eax
je     1302 <main+0x192>
mov    %r12d,0x10(%rsp)
movzbl 0x7(%rsp),%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
je     1341 <main+0x1d1>
cmp    $0xffffffff,%eax
je     1302 <main+0x192>
shl    $0x8,%r12d
movzbl 0x7(%rsp),%r15d
or     %r15d,%r12d
cmp    $0xffff,%r12d
je     1358 <main+0x1e8>
mov    %r14d,0x14(%rsp)
mov    %r12d,%r14d
test   %r12d,%r12d
je     12cf <main+0x15f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1302 <main+0x192>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1317 <main+0x1a7>
add    $0xffffffff,%r14d
jne    12a0 <main+0x130>
mov    0x14(%rsp),%r14d
add    %r12d,%r14d
mov    0x10(%rsp),%r12d
add    $0x1,%r12d
test   $0x1,%r15b
je     1220 <main+0xb0>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1220 <main+0xb0>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
lea    0xd00(%rip),%rdi
jmp    11f3 <main+0x83>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%rsi
lea    0xd10(%rip),%rdi
jmp    11f3 <main+0x83>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
lea    0xce8(%rip),%rdi
jmp    11f3 <main+0x83>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
lea    0xcd3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r13d,%edi
call   1060 <close@plt>
lea    0xcdb(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcd4(%rip),%rdi
mov    0x10(%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"Usage:\0A\0A\09 lif_convert <input_file> <output_file>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"error opening %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [18 x i8] c"error reading %s\0A\00"
@.str.3 = [19 x i8] c"end of %s reached\0A\00"
@.str.4 = [18 x i8] c"error writing %s\0A\00"
@.str.5 = [10 x i8] c"size[%x]\0A\00"
@.str.6 = [14 x i8] c"segments[%x]\0A\00"
@EXIT_SUCCESS = 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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 -1, i32* %9
store i32 -1, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %12
store i8 0, i8* %13
store i8 0, i8* %14
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 (i8*, i32, ...) @open(i8* %24, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %36
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %21
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_WRONLY
%41 = load i32, i32* @O_CREAT
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRWXU
%44 = call i32 (i8*, i32, ...) @open(i8* %39, i32 %42, i32 %43)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %36
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %36
br label %55
55: ; preds = %167, %54
%56 = load i32, i32* %9
%57 = call i32 @read(i32 %56, i8* %13, i32 1)
store i32 %57, i32* %11
%58 = load i32, i32* %11
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %67
60: ; preds = %55
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %55
%68 = load i32, i32* %11
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %67
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %73)
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %67
%78 = load i8, i8* %13
%79 = zext i8 %78 to i32
%80 = shl i32 %79, 8
store i32 %80, i32* %6
%81 = load i32, i32* %9
%82 = call i32 @read(i32 %81, i8* %13, i32 1)
store i32 %82, i32* %11
%83 = load i32, i32* %11
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %92
85: ; preds = %77
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 1
%88 = load i8*, i8** %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %88)
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %77
%93 = load i32, i32* %11
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %100
95: ; preds = %92
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 1
%98 = load i8*, i8** %97
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %98)
br label %168
100: ; preds = %92
%101 = load i8, i8* %13
%102 = zext i8 %101 to i32
%103 = load i32, i32* %6
%104 = or i32 %103, %102
store i32 %104, i32* %6
%105 = load i32, i32* %6
%106 = icmp eq i32 %105, 65535
br i1 %106, label %107, label %108
107: ; preds = %100
br label %168
108: ; preds = %100
%109 = load i32, i32* %6
%110 = and i32 %109, 1
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %108
store i8 1, i8* %14
br label %113
113: ; preds = %112, %108
%114 = load i32, i32* %6
%115 = load i32, i32* %7
%116 = add i32 %115, %114
store i32 %116, i32* %7
%117 = load i32, i32* %8
%118 = add i32 %117, 1
store i32 %118, i32* %8
store i32 0, i32* %12
br label %119
119: ; preds = %148, %113
%120 = load i32, i32* %12
%121 = load i32, i32* %6
%122 = icmp ult i32 %120, %121
br i1 %122, label %123, label %151
123: ; preds = %119
%124 = load i32, i32* %9
%125 = call i32 @read(i32 %124, i8* %13, i32 1)
store i32 %125, i32* %11
%126 = load i32, i32* %11
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %135
128: ; preds = %123
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 1
%131 = load i8*, i8** %130
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %131)
%133 = load i32, i32* @EXIT_FAILURE
%134 = call i32 @exit(i32 %133)
unreachable
135: ; preds = %123
%136 = load i32, i32* %10
%137 = call i32 @write(i32 %136, i8* %13, i32 1)
store i32 %137, i32* %11
%138 = load i32, i32* %11
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %147
140: ; preds = %135
%141 = load i8**, i8*** %5
%142 = getelementptr inbounds i8*, i8** %141, i64 2
%143 = load i8*, i8** %142
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %143)
%145 = load i32, i32* @EXIT_FAILURE
%146 = call i32 @exit(i32 %145)
unreachable
147: ; preds = %135
br label %148
148: ; preds = %147
%149 = load i32, i32* %12
%150 = add nsw i32 %149, 1
store i32 %150, i32* %12
br label %119
151: ; preds = %119
%152 = load i8, i8* %14
%153 = icmp ne i8 %152, 0
br i1 %153, label %154, label %167
154: ; preds = %151
%155 = load i32, i32* %9
%156 = call i32 @read(i32 %155, i8* %13, i32 1)
store i32 %156, i32* %11
%157 = load i32, i32* %11
%158 = icmp eq i32 %157, -1
br i1 %158, label %159, label %166
159: ; preds = %154
%160 = load i8**, i8*** %5
%161 = getelementptr inbounds i8*, i8** %160, i64 1
%162 = load i8*, i8** %161
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %162)
%164 = load i32, i32* @EXIT_FAILURE
%165 = call i32 @exit(i32 %164)
unreachable
166: ; preds = %154
store i8 0, i8* %14
br label %167
167: ; preds = %166, %151
br label %55
168: ; preds = %107, %95
%169 = load i32, i32* %9
%170 = call i32 @close(i32 %169)
%171 = load i32, i32* %10
%172 = call i32 @close(i32 %171)
%173 = load i32, i32* %7
%174 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %173)
%175 = load i32, i32* %8
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %175)
%177 = load i32, i32* @EXIT_SUCCESS
%178 = call i32 @exit(i32 %177)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"error opening %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [18 x i8] c"error reading %s\0A\00"
@.str.3 = [19 x i8] c"end of %s reached\0A\00"
@.str.4 = [18 x i8] c"error writing %s\0A\00"
@.str.5 = [10 x i8] c"size[%x]\0A\00"
@.str.6 = [14 x i8] c"segments[%x]\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [49 x i8] c"Usage:\0A\0A\09 lif_convert <input_file> <output_file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
store i8 0, i8* %3
%4 = icmp eq i32 %0, 3
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = load i8*, i8** %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_WRONLY
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = load i32, i32* @S_IRWXU
%27 = tail call i32 (i8*, i32, ...) @open(i8* %22, i32 %25, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %20
%30 = load i8*, i8** %21
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %20, %96
%35 = phi i32 [ %69, %96 ], [ 0, %20 ]
%36 = phi i32 [ %70, %96 ], [ 0, %20 ]
%37 = call i32 @read(i32 %13, i8* %3, i32 1)
switch i32 %37, label %48 [
i32 -1, label %38
i32 0, label %43
]
38: ; preds = %34
%39 = load i8*, i8** %10
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = load i8*, i8** %10
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %34
%49 = load i8, i8* %3
%50 = call i32 @read(i32 %13, i8* %3, i32 1)
switch i32 %50, label %59 [
i32 -1, label %51
i32 0, label %56
]
51: ; preds = %48
%52 = load i8*, i8** %10
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = tail call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = load i8*, i8** %10
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %102
59: ; preds = %48
%60 = zext i8 %49 to i32
%61 = shl nuw nsw i32 %60, 8
%62 = load i8, i8* %3
%63 = zext i8 %62 to i32
%64 = or i32 %61, %63
%65 = icmp eq i32 %64, 65535
br i1 %65, label %102, label %66
66: ; preds = %59
%67 = and i32 %63, 1
%68 = icmp eq i32 %67, 0
%69 = add i32 %64, %35
%70 = add i32 %36, 1
%71 = icmp eq i32 %64, 0
br i1 %71, label %92, label %74
72: ; preds = %83
%73 = icmp eq i32 %86, %64
br i1 %73, label %92, label %74
74: ; preds = %66, %72
%75 = phi i32 [ %86, %72 ], [ 0, %66 ]
%76 = call i32 @read(i32 %13, i8* %3, i32 1)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %83
78: ; preds = %74
%79 = load i8*, i8** %10
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %79)
%81 = load i32, i32* @EXIT_FAILURE
%82 = tail call i32 @exit(i32 %81)
unreachable
83: ; preds = %74
%84 = call i32 @write(i32 %27, i8* %3, i32 1)
%85 = icmp eq i32 %84, -1
%86 = add nuw nsw i32 %75, 1
br i1 %85, label %87, label %72
87: ; preds = %83
%88 = load i8*, i8** %21
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %88)
%90 = load i32, i32* @EXIT_FAILURE
%91 = tail call i32 @exit(i32 %90)
unreachable
92: ; preds = %72, %66
br i1 %68, label %96, label %93
93: ; preds = %92
%94 = call i32 @read(i32 %13, i8* %3, i32 1)
%95 = icmp eq i32 %94, -1
br i1 %95, label %97, label %96
96: ; preds = %93, %92
br label %34
97: ; preds = %93
%98 = load i8*, i8** %10
%99 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %98)
%100 = load i32, i32* @EXIT_FAILURE
%101 = tail call i32 @exit(i32 %100)
unreachable
102: ; preds = %59, %56
%103 = tail call i32 @close(i32 %13)
%104 = tail call i32 @close(i32 %27)
%105 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%106 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%107 = load i32, i32* @EXIT_SUCCESS
%108 = tail call i32 @exit(i32 %107)
unreachable
}