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

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
unsigned int chksum_crc32(unsigned char *, int);
int /*<<< orphan*/ chksum_crc32gentab();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ int2le(int, unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
int mi4_encode(char *iname, char *oname, int version, int magic, char *model,
               char *type) {
  size_t len;
  int length;
  int mi4length;
  FILE *file;
  unsigned int crc = 0;
  unsigned char *outbuf;
  file = fopen(iname, "rb");
  if (!file) {
    perror(iname);
    return -1;
  }
  fseek(file, 0, SEEK_END);
  length = ftell(file);
  fseek(file, 0, SEEK_SET);
  mi4length = (length + 4 + 0x200 + 0x3ff) & ~0x3ff;
  outbuf = malloc(mi4length);
  if (!outbuf) {
    printf("out of memory!\n");
    return -1;
  }
  memset(outbuf, 0, mi4length);
  len = fread(outbuf + 0x200, 1, length, file);
  if (len < (size_t)length) {
    perror(iname);
    return -2;
  }
  fclose(file);
  int2le(0x00000100, &outbuf[0x2e0]);
  int2le(magic, &outbuf[0x2e4]);
  int2le(length + 4, &outbuf[0x2e8]);
  int2le(0xaa55aa55, &outbuf[0x200 + length]);
  strncpy((char *)outbuf + 0x1f8, type, 4);
  strncpy((char *)outbuf + 0x1fc, model, 4);
  chksum_crc32gentab();
  crc = chksum_crc32(outbuf + 0x200, mi4length - 0x200);
  strncpy((char *)outbuf, "PPOS", 4);
  int2le(version, &outbuf[0x04]);
  int2le(length + 4, &outbuf[0x08]);
  int2le(crc, &outbuf[0x0c]);
  int2le(0x00000002, &outbuf[0x10]);
  int2le(mi4length, &outbuf[0x14]);
  int2le(mi4length - 0x200, &outbuf[0x18]);
  if (version == 0x00010301) {
    outbuf[0x2f] = 0x01;
  }
  file = fopen(oname, "wb");
  if (!file) {
    perror(oname);
    return -3;
  }
  len = fwrite(outbuf, 1, mi4length, file);
  if (len < (size_t)length) {
    perror(oname);
    return -4;
  }
  fclose(file);
  fprintf(stderr, "File encoded successfully\n");
  return 0;
}


x86 assembly (clang, -O0):
<mi4_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1249 <mi4_encode+0x59>
mov    -0x10(%rbp),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fc <mi4_encode+0x30c>
mov    -0x48(%rbp),%rdi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x48(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x3c(%rbp),%eax
add    $0x4,%eax
add    $0x200,%eax
add    $0x3ff,%eax
and    $0xfffffc00,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    12c4 <mi4_encode+0xd4>
lea    0xd50(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fc <mi4_encode+0x30c>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x58(%rbp),%rdi
add    $0x200,%rdi
mov    -0x3c(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmp    %rcx,%rax
jae    1318 <mi4_encode+0x128>
mov    -0x10(%rbp),%rdi
call   10f0 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    14fc <mi4_encode+0x30c>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x58(%rbp),%rsi
add    $0x2e0,%rsi
mov    $0x100,%edi
call   1100 <int2le@plt>
mov    -0x20(%rbp),%edi
mov    -0x58(%rbp),%rsi
add    $0x2e4,%rsi
call   1100 <int2le@plt>
mov    -0x3c(%rbp),%edi
add    $0x4,%edi
mov    -0x58(%rbp),%rsi
add    $0x2e8,%rsi
call   1100 <int2le@plt>
mov    -0x58(%rbp),%rsi
mov    -0x3c(%rbp),%eax
add    $0x200,%eax
cltq
add    %rax,%rsi
mov    $0xaa55aa55,%edi
call   1100 <int2le@plt>
mov    -0x58(%rbp),%rdi
add    $0x1f8,%rdi
mov    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
mov    -0x58(%rbp),%rdi
add    $0x1fc,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
mov    $0x0,%al
call   10b0 <chksum_crc32gentab@plt>
mov    -0x58(%rbp),%rdi
add    $0x200,%rdi
mov    -0x40(%rbp),%esi
sub    $0x200,%esi
call   1030 <chksum_crc32@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xc39(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
mov    -0x1c(%rbp),%edi
mov    -0x58(%rbp),%rsi
add    $0x4,%rsi
call   1100 <int2le@plt>
mov    -0x3c(%rbp),%edi
add    $0x4,%edi
mov    -0x58(%rbp),%rsi
add    $0x8,%rsi
call   1100 <int2le@plt>
mov    -0x4c(%rbp),%edi
mov    -0x58(%rbp),%rsi
add    $0xc,%rsi
call   1100 <int2le@plt>
mov    -0x58(%rbp),%rsi
add    $0x10,%rsi
mov    $0x2,%edi
call   1100 <int2le@plt>
mov    -0x40(%rbp),%edi
mov    -0x58(%rbp),%rsi
add    $0x14,%rsi
call   1100 <int2le@plt>
mov    -0x40(%rbp),%edi
sub    $0x200,%edi
mov    -0x58(%rbp),%rsi
add    $0x18,%rsi
call   1100 <int2le@plt>
cmpl   $0x10301,-0x1c(%rbp)
jne    1464 <mi4_encode+0x274>
mov    -0x58(%rbp),%rax
movb   $0x1,0x2f(%rax)
mov    -0x18(%rbp),%rdi
lea    0xba9(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1498 <mi4_encode+0x2a8>
mov    -0x18(%rbp),%rdi
call   10f0 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    14fc <mi4_encode+0x30c>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmp    %rcx,%rax
jae    14d7 <mi4_encode+0x2e7>
mov    -0x18(%rbp),%rdi
call   10f0 <perror@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    14fc <mi4_encode+0x30c>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2af1(%rip),%rax
mov    (%rax),%edi
lea    0xb2b(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mi4_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r12
mov    %r8,%r14
mov    %ecx,0x8(%rsp)
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xde9(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     144b <mi4_encode+0x25b>
mov    %rax,%r13
mov    %r12,0x20(%rsp)
mov    %r14,0x28(%rsp)
mov    %ebp,0x14(%rsp)
mov    %rbx,0x30(%rsp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %r13,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r14d
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
lea    0x603(%r14),%r12d
and    $0xfffffc00,%r12d
mov    %r12d,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     142b <mi4_encode+0x23b>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1080 <memset@plt>
lea    0x200(%rbp),%rdi
mov    %rdi,0x18(%rsp)
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r13,%rcx
call   1060 <fread@plt>
movslq %r14d,%rbx
cmp    %rbx,%rax
jb     1455 <mi4_encode+0x265>
lea    0x4(%rbx),%r15d
mov    %r13,%rdi
call   1070 <fclose@plt>
lea    0x2e0(%rbp),%rsi
mov    $0x100,%edi
call   1100 <int2le@plt>
lea    0x2e4(%rbp),%rsi
mov    0x8(%rsp),%edi
call   1100 <int2le@plt>
lea    0x2e8(%rbp),%rsi
mov    %r15d,%edi
call   1100 <int2le@plt>
mov    %rbx,0x8(%rsp)
lea    (%rbx,%rbp,1),%rsi
add    $0x200,%rsi
mov    $0xaa55aa55,%edi
call   1100 <int2le@plt>
lea    0x1f8(%rbp),%rdi
mov    0x20(%rsp),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
lea    0x1fc(%rbp),%rdi
mov    0x28(%rsp),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
xor    %eax,%eax
call   10b0 <chksum_crc32gentab@plt>
lea    -0x200(%r12),%r14d
ff
mov    0x18(%rsp),%rdi
mov    %r14d,%esi
call   1030 <chksum_crc32@plt>
mov    %eax,%r13d
lea    0xc98(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1040 <strncpy@plt>
lea    0x4(%rbp),%rsi
mov    0x14(%rsp),%ebx
mov    %ebx,%edi
call   1100 <int2le@plt>
lea    0x8(%rbp),%rsi
mov    %r15d,%edi
call   1100 <int2le@plt>
lea    0xc(%rbp),%rsi
mov    %r13d,%edi
call   1100 <int2le@plt>
lea    0x10(%rbp),%rsi
mov    $0x2,%edi
call   1100 <int2le@plt>
lea    0x14(%rbp),%rsi
mov    %r12d,%edi
call   1100 <int2le@plt>
mov    %rbp,%rsi
add    $0x18,%rsi
mov    %r14d,%edi
call   1100 <int2le@plt>
cmp    $0x10301,%ebx
jne    13d4 <mi4_encode+0x1e4>
movb   $0x1,0x2f(%rbp)
lea    0xc2d(%rip),%rsi
mov    0x30(%rsp),%r14
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1464 <mi4_encode+0x274>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
cmp    0x8(%rsp),%rax
jb     1473 <mi4_encode+0x283>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
lea    0xbe9(%rip),%rsi
call   1090 <fprintf@plt>
xor    %eax,%eax
jmp    143c <mi4_encode+0x24c>
lea    0xbf4(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   10f0 <perror@plt>
jmp    1437 <mi4_encode+0x247>
mov    %r15,%rdi
call   10f0 <perror@plt>
mov    $0xfffffffe,%eax
jmp    143c <mi4_encode+0x24c>
mov    %r14,%rdi
call   10f0 <perror@plt>
mov    $0xfffffffd,%eax
jmp    143c <mi4_encode+0x24c>
mov    %r14,%rdi
call   10f0 <perror@plt>
mov    $0xfffffffc,%eax
jmp    143c <mi4_encode+0x24c>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [16 x i8] c"out of memory!\0A\00"
@.str.2 = [5 x i8] c"PPOS\00"
@.str.3 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.4 = [27 x i8] c"File encoded successfully\0A\00"
define i32 @mi4_encode(i8* %0, i8* %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i8*
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 0, i32* %18
%20 = load i8*, i8** %8
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %17
%22 = load i32*, i32** %17
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %6
%25 = load i8*, i8** %8
%26 = call i32 @perror(i8* %25)
store i32 -1, i32* %7
br label %155
27: ; preds = %6
%28 = load i32*, i32** %17
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32*, i32** %17
%32 = call i32 @ftell(i32* %31)
store i32 %32, i32* %15
%33 = load i32*, i32** %17
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32, i32* %15
%37 = add nsw i32 %36, 4
%38 = add nsw i32 %37, 512
%39 = add nsw i32 %38, 1023
%40 = and i32 %39, -1024
store i32 %40, i32* %16
%41 = load i32, i32* %16
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** %19
%43 = load i8*, i8** %19
%44 = icmp ne i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %27
%46 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %155
47: ; preds = %27
%48 = load i8*, i8** %19
%49 = load i32, i32* %16
%50 = call i32 @memset(i8* %48, i32 0, i32 %49)
%51 = load i8*, i8** %19
%52 = getelementptr inbounds i8, i8* %51, i64 512
%53 = load i32, i32* %15
%54 = load i32*, i32** %17
%55 = call i64 @fread(i8* %52, i32 1, i32 %53, i32* %54)
store i64 %55, i64* %14
%56 = load i64, i64* %14
%57 = load i32, i32* %15
%58 = sext i32 %57 to i64
%59 = icmp ult i64 %56, %58
br i1 %59, label %60, label %63
60: ; preds = %47
%61 = load i8*, i8** %8
%62 = call i32 @perror(i8* %61)
store i32 -2, i32* %7
br label %155
63: ; preds = %47
%64 = load i32*, i32** %17
%65 = call i32 @fclose(i32* %64)
%66 = load i8*, i8** %19
%67 = getelementptr inbounds i8, i8* %66, i64 736
%68 = call i32 @int2le(i32 256, i8* %67)
%69 = load i32, i32* %11
%70 = load i8*, i8** %19
%71 = getelementptr inbounds i8, i8* %70, i64 740
%72 = call i32 @int2le(i32 %69, i8* %71)
%73 = load i32, i32* %15
%74 = add nsw i32 %73, 4
%75 = load i8*, i8** %19
%76 = getelementptr inbounds i8, i8* %75, i64 744
%77 = call i32 @int2le(i32 %74, i8* %76)
%78 = load i8*, i8** %19
%79 = load i32, i32* %15
%80 = add nsw i32 512, %79
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %78, i64 %81
%83 = call i32 @int2le(i32 -1437226411, i8* %82)
%84 = load i8*, i8** %19
%85 = getelementptr inbounds i8, i8* %84, i64 504
%86 = load i8*, i8** %13
%87 = call i32 @strncpy(i8* %85, i8* %86, i32 4)
%88 = load i8*, i8** %19
%89 = getelementptr inbounds i8, i8* %88, i64 508
%90 = load i8*, i8** %12
%91 = call i32 @strncpy(i8* %89, i8* %90, i32 4)
%92 = call i32 (...) @chksum_crc32gentab()
%93 = load i8*, i8** %19
%94 = getelementptr inbounds i8, i8* %93, i64 512
%95 = load i32, i32* %16
%96 = sub nsw i32 %95, 512
%97 = call i32 @chksum_crc32(i8* %94, i32 %96)
store i32 %97, i32* %18
%98 = load i8*, i8** %19
%99 = call i32 @strncpy(i8* %98, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%100 = load i32, i32* %10
%101 = load i8*, i8** %19
%102 = getelementptr inbounds i8, i8* %101, i64 4
%103 = call i32 @int2le(i32 %100, i8* %102)
%104 = load i32, i32* %15
%105 = add nsw i32 %104, 4
%106 = load i8*, i8** %19
%107 = getelementptr inbounds i8, i8* %106, i64 8
%108 = call i32 @int2le(i32 %105, i8* %107)
%109 = load i32, i32* %18
%110 = load i8*, i8** %19
%111 = getelementptr inbounds i8, i8* %110, i64 12
%112 = call i32 @int2le(i32 %109, i8* %111)
%113 = load i8*, i8** %19
%114 = getelementptr inbounds i8, i8* %113, i64 16
%115 = call i32 @int2le(i32 2, i8* %114)
%116 = load i32, i32* %16
%117 = load i8*, i8** %19
%118 = getelementptr inbounds i8, i8* %117, i64 20
%119 = call i32 @int2le(i32 %116, i8* %118)
%120 = load i32, i32* %16
%121 = sub nsw i32 %120, 512
%122 = load i8*, i8** %19
%123 = getelementptr inbounds i8, i8* %122, i64 24
%124 = call i32 @int2le(i32 %121, i8* %123)
%125 = load i32, i32* %10
%126 = icmp eq i32 %125, 66305
br i1 %126, label %127, label %130
127: ; preds = %63
%128 = load i8*, i8** %19
%129 = getelementptr inbounds i8, i8* %128, i64 47
store i8 1, i8* %129
br label %130
130: ; preds = %127, %63
%131 = load i8*, i8** %9
%132 = call i32* @fopen(i8* %131, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %132, i32** %17
%133 = load i32*, i32** %17
%134 = icmp ne i32* %133, null
br i1 %134, label %138, label %135
135: ; preds = %130
%136 = load i8*, i8** %9
%137 = call i32 @perror(i8* %136)
store i32 -3, i32* %7
br label %155
138: ; preds = %130
%139 = load i8*, i8** %19
%140 = load i32, i32* %16
%141 = load i32*, i32** %17
%142 = call i64 @fwrite(i8* %139, i32 1, i32 %140, i32* %141)
store i64 %142, i64* %14
%143 = load i64, i64* %14
%144 = load i32, i32* %15
%145 = sext i32 %144 to i64
%146 = icmp ult i64 %143, %145
br i1 %146, label %147, label %150
147: ; preds = %138
%148 = load i8*, i8** %9
%149 = call i32 @perror(i8* %148)
store i32 -4, i32* %7
br label %155
150: ; preds = %138
%151 = load i32*, i32** %17
%152 = call i32 @fclose(i32* %151)
%153 = load i32, i32* @stderr
%154 = call i32 @fprintf(i32 %153, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
br label %155
155: ; preds = %150, %147, %135, %60, %45, %24
%156 = load i32, i32* %7
ret i32 %156
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [5 x i8] c"PPOS\00"
@.str.3 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.4 = [27 x i8] c"File encoded successfully\0A\00"
@str = [15 x i8] c"out of memory!\00"
define i32 @mi4_encode(i8* nocapture %0, i8* nocapture %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @perror(i8* %0)
br label %81
11: ; preds = %6
%12 = load i32, i32* @SEEK_END
%13 = tail call i32 @fseek(i32* %7, i32 0, i32 %12)
%14 = tail call i32 @ftell(i32* %7)
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %7, i32 0, i32 %15)
%17 = add nsw i32 %14, 4
%18 = add nsw i32 %14, 1539
%19 = and i32 %18, -1024
%20 = tail call i8* @malloc(i32 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %81
24: ; preds = %11
%25 = tail call i32 @memset(i8* %20, i32 0, i32 %19)
%26 = getelementptr inbounds i8, i8* %20, i64 512
%27 = tail call i64 @fread(i8* %26, i32 1, i32 %14, i32* %7)
%28 = sext i32 %14 to i64
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call i32 @perror(i8* %0)
br label %81
32: ; preds = %24
%33 = tail call i32 @fclose(i32* %7)
%34 = getelementptr inbounds i8, i8* %20, i64 736
%35 = tail call i32 @int2le(i32 256, i8* %34)
%36 = getelementptr inbounds i8, i8* %20, i64 740
%37 = tail call i32 @int2le(i32 %3, i8* %36)
%38 = getelementptr inbounds i8, i8* %20, i64 744
%39 = tail call i32 @int2le(i32 %17, i8* %38)
%40 = add nsw i32 %14, 512
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %20, i64 %41
%43 = tail call i32 @int2le(i32 -1437226411, i8* %42)
%44 = getelementptr inbounds i8, i8* %20, i64 504
%45 = tail call i32 @strncpy(i8* %44, i8* %5, i32 4)
%46 = getelementptr inbounds i8, i8* %20, i64 508
%47 = tail call i32 @strncpy(i8* %46, i8* %4, i32 4)
%48 = tail call i32 (...) @chksum_crc32gentab()
%49 = add nsw i32 %19, -512
%50 = tail call i32 @chksum_crc32(i8* %26, i32 %49)
%51 = tail call i32 @strncpy(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%52 = getelementptr inbounds i8, i8* %20, i64 4
%53 = tail call i32 @int2le(i32 %2, i8* %52)
%54 = getelementptr inbounds i8, i8* %20, i64 8
%55 = tail call i32 @int2le(i32 %17, i8* %54)
%56 = getelementptr inbounds i8, i8* %20, i64 12
%57 = tail call i32 @int2le(i32 %50, i8* %56)
%58 = getelementptr inbounds i8, i8* %20, i64 16
%59 = tail call i32 @int2le(i32 2, i8* %58)
%60 = getelementptr inbounds i8, i8* %20, i64 20
%61 = tail call i32 @int2le(i32 %19, i8* %60)
%62 = getelementptr inbounds i8, i8* %20, i64 24
%63 = tail call i32 @int2le(i32 %49, i8* %62)
%64 = icmp eq i32 %2, 66305
br i1 %64, label %65, label %67
65: ; preds = %32
%66 = getelementptr inbounds i8, i8* %20, i64 47
store i8 1, i8* %66
br label %67
67: ; preds = %65, %32
%68 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = tail call i32 @perror(i8* %1)
br label %81
72: ; preds = %67
%73 = tail call i64 @fwrite(i8* %20, i32 1, i32 %19, i32* %68)
%74 = icmp ult i64 %73, %28
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = tail call i32 @perror(i8* %1)
br label %81
77: ; preds = %72
%78 = tail call i32 @fclose(i32* %68)
%79 = load i32, i32* @stderr
%80 = tail call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %77, %75, %70, %30, %22, %9
%82 = phi i32 [ -2, %30 ], [ -4, %75 ], [ 0, %77 ], [ -3, %70 ], [ -1, %22 ], [ -1, %9 ]
ret i32 %82
}