#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*/ uint8_t;
typedef int uint32_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ L_tmpnam;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fil_sreadU32(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, size_t, int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, size_t, int,
                          int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ remove(char *);
char *tempnam(char *, char *);
int /*<<< orphan*/ *tmpnam(char *);
int __cole_extract_file(FILE **file, char **filename, uint32_t size,
                        uint32_t pps_start, uint8_t *BDepot, uint8_t *SDepot,
                        FILE *sbfile, FILE *inputfile) {
  FILE *ret;
  uint16_t BlockSize, Offset;
  uint8_t *Depot;
  FILE *infile;
  long FilePos;
  size_t bytes_to_copy;
  uint8_t Block[0x0200];
  *filename = malloc((size_t)(L_tmpnam + 1));
  if (*filename == NULL)
    return 1;
  if (tmpnam(*filename) == NULL) {
    free(*filename);
    return 2;
  };
  ret = fopen(*filename, "w+b");
  if (ret == NULL) {
    free(*filename);
    *filename = tempnam("./", "rtf2latex-tmp-");
    ;
    ret = fopen(*filename, "w+b");
    if (*filename == NULL)
      return 2;
  }
  *file = ret;
  if (ret == NULL) {
    free(*filename);
    return 3;
  }
  if (size >= 0x1000) {
    Offset = 1;
    BlockSize = 0x0200;
    infile = inputfile;
    Depot = BDepot;
  } else {
    Offset = 0;
    BlockSize = 0x40;
    infile = sbfile;
    Depot = SDepot;
  }
  while (pps_start < (uint32_t)0xfffffffd) {
    FilePos = (long)((pps_start + Offset) * BlockSize);
    if (FilePos < 0) {
      fclose(ret);
      remove(*filename);
      free(*filename);
      return 4;
    }
    bytes_to_copy = ((BlockSize) < (size) ? (BlockSize) : (size));
    if (fseek(infile, FilePos, SEEK_SET)) {
      fclose(ret);
      remove(*filename);
      free(*filename);
      return 4;
    }
    (void)fread(Block, bytes_to_copy, 1, infile);
    if (ferror(infile)) {
      fclose(ret);
      remove(*filename);
      free(*filename);
      return 5;
    }
    (void)fwrite(Block, bytes_to_copy, 1, ret);
    if (ferror(ret)) {
      fclose(ret);
      remove(*filename);
      free(*filename);
      return 6;
    }
    pps_start = fil_sreadU32(Depot + (pps_start * 4));
    size -= ((BlockSize) < (size) ? (BlockSize) : (size));
    if (size == 0)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<__cole_extract_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1220 <__cole_extract_file+0x60>
movl   $0x1,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <tmpnam@plt>
cmp    $0x0,%rax
jne    124e <__cole_extract_file+0x8e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xda4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12cf <__cole_extract_file+0x10f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    0xd81(%rip),%rdi
lea    0xd7d(%rip),%rsi
call   1080 <tempnam@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd59(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12ca <__cole_extract_file+0x10a>
movl   $0x2,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
jmp    12cf <__cole_extract_file+0x10f>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x38(%rbp)
jne    12fd <__cole_extract_file+0x13d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x3,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
cmpl   $0x1000,-0x1c(%rbp)
jl     132d <__cole_extract_file+0x16d>
movl   $0x1,-0x40(%rbp)
movl   $0x200,-0x3c(%rbp)
mov    0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    134b <__cole_extract_file+0x18b>
movl   $0x0,-0x40(%rbp)
movl   $0x40,-0x3c(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1350 <__cole_extract_file+0x190>
cmpl   $0xfffffffd,-0x20(%rbp)
jge    1530 <__cole_extract_file+0x370>
mov    -0x20(%rbp),%eax
add    -0x40(%rbp),%eax
imul   -0x3c(%rbp),%eax
cltq
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jge    13a2 <__cole_extract_file+0x1e2>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <remove@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13bc <__cole_extract_file+0x1fc>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x864(%rbp)
jmp    13c5 <__cole_extract_file+0x205>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x864(%rbp)
mov    -0x864(%rbp),%eax
cltq
mov    %rax,-0x60(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    0x2bf8(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     141e <__cole_extract_file+0x25e>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <remove@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
lea    -0x860(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x50(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fread@plt>
mov    -0x50(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1477 <__cole_extract_file+0x2b7>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <remove@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x5,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
lea    -0x860(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     14d0 <__cole_extract_file+0x310>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <remove@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x6,-0x4(%rbp)
jmp    1537 <__cole_extract_file+0x377>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   10e0 <fil_sreadU32@plt>
mov    %eax,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1505 <__cole_extract_file+0x345>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x868(%rbp)
jmp    150e <__cole_extract_file+0x34e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x868(%rbp)
mov    -0x868(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    152b <__cole_extract_file+0x36b>
jmp    1530 <__cole_extract_file+0x370>
jmp    1350 <__cole_extract_file+0x190>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__cole_extract_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%r15
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
mov    0x2df5(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1360 <__cole_extract_file+0x1a0>
mov    %rax,%rdi
call   10d0 <tmpnam@plt>
mov    (%r12),%rdi
test   %rax,%rax
je     136a <__cole_extract_file+0x1aa>
lea    0xde0(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1372 <__cole_extract_file+0x1b2>
mov    %rax,0x0(%rbp)
mov    0x878(%rsp),%r13
xor    %esi,%esi
cmp    $0x1000,%r14d
mov    $0x200,%ecx
mov    $0x40,%ebp
cmovge %ecx,%ebp
setge  %dl
cmovl  0x870(%rsp),%r13
mov    0x8(%rsp),%rcx
cmovge %r15,%rcx
mov    %rcx,0x8(%rsp)
xor    %ecx,%ecx
cmp    $0xfffffffc,%ebx
jg     13f6 <__cole_extract_file+0x236>
mov    %r14d,%edi
mov    %rax,0x18(%rsp)
mov    %r12,0x20(%rsp)
mov    %dl,%sil
mov    %rsi,0x28(%rsp)
mov    %ebp,0x10(%rsp)
xchg   %ax,%ax
lea    (%rbx,%rsi,1),%eax
imul   %ebp,%eax
mov    $0x4,%r14d
test   %eax,%eax
js     13d2 <__cole_extract_file+0x212>
mov    %eax,%esi
cmp    %edi,%ebp
mov    %edi,0x14(%rsp)
mov    %edi,%r12d
cmovl  %ebp,%r12d
mov    0x2d1e(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
call   10a0 <fseek@plt>
test   %rax,%rax
jne    13d2 <__cole_extract_file+0x212>
movslq %r12d,%r15
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fread@plt>
mov    %r13,%r14
mov    %r13,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    13c4 <__cole_extract_file+0x204>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    0x18(%rsp),%rbp
mov    %rbp,%rcx
call   10c0 <fwrite@plt>
mov    %rbp,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    13cc <__cole_extract_file+0x20c>
shl    $0x2,%ebx
movslq %ebx,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rdi
call   10e0 <fil_sreadU32@plt>
mov    0x14(%rsp),%edi
sub    %r12d,%edi
je     1359 <__cole_extract_file+0x199>
mov    %eax,%ebx
cmp    $0xfffffffd,%eax
mov    %r14,%r13
mov    0x28(%rsp),%rsi
mov    0x10(%rsp),%ebp
jl     1290 <__cole_extract_file+0xd0>
xor    %ecx,%ecx
jmp    13f6 <__cole_extract_file+0x236>
mov    $0x1,%ecx
jmp    13f6 <__cole_extract_file+0x236>
mov    $0x2,%r14d
jmp    13ee <__cole_extract_file+0x22e>
mov    (%r12),%rdi
call   1030 <free@plt>
lea    0xc82(%rip),%rdi
lea    0xc7e(%rip),%rsi
call   1080 <tempnam@plt>
mov    %rax,(%r12)
lea    0xc67(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
cmpq   $0x0,(%r12)
je     13bd <__cole_extract_file+0x1fd>
mov    %rax,0x0(%rbp)
test   %rax,%rax
jne    1232 <__cole_extract_file+0x72>
mov    $0x3,%r14d
jmp    13ea <__cole_extract_file+0x22a>
mov    $0x2,%ecx
jmp    13f6 <__cole_extract_file+0x236>
mov    $0x5,%r14d
jmp    13d2 <__cole_extract_file+0x212>
mov    $0x6,%r14d
mov    0x18(%rsp),%rdi
call   1070 <fclose@plt>
mov    0x20(%rsp),%r12
mov    (%r12),%rdi
call   1040 <remove@plt>
mov    (%r12),%rdi
call   1030 <free@plt>
mov    %r14d,%ecx
mov    %ecx,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@L_tmpnam = global i64 0
@.str = [4 x i8] c"w+b\00"
@.str.1 = [3 x i8] c"./\00"
@.str.2 = [15 x i8] c"rtf2latex-tmp-\00"
@SEEK_SET = global i32 0
define i32 @__cole_extract_file(i32** %0, i8** %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32**
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i64
%24 = alloca i64
%25 = alloca [512 x i32]
store i32** %0, i32*** %10
store i8** %1, i8*** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
%26 = load i64, i64* @L_tmpnam
%27 = add nsw i64 %26, 1
%28 = call i8* @malloc(i64 %27)
%29 = load i8**, i8*** %11
store i8* %28, i8** %29
%30 = load i8**, i8*** %11
%31 = load i8*, i8** %30
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %8
store i32 1, i32* %9
br label %185
34: ; preds = %8
%35 = load i8**, i8*** %11
%36 = load i8*, i8** %35
%37 = call i32* @tmpnam(i8* %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i8**, i8*** %11
%41 = load i8*, i8** %40
%42 = call i32 @free(i8* %41)
store i32 2, i32* %9
br label %185
43: ; preds = %34
%44 = load i8**, i8*** %11
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %46, i32** %18
%47 = load i32*, i32** %18
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %63
49: ; preds = %43
%50 = load i8**, i8*** %11
%51 = load i8*, i8** %50
%52 = call i32 @free(i8* %51)
%53 = call i8* @tempnam(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%54 = load i8**, i8*** %11
store i8* %53, i8** %54
%55 = load i8**, i8*** %11
%56 = load i8*, i8** %55
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %57, i32** %18
%58 = load i8**, i8*** %11
%59 = load i8*, i8** %58
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %62
61: ; preds = %49
store i32 2, i32* %9
br label %185
62: ; preds = %49
br label %63
63: ; preds = %62, %43
%64 = load i32*, i32** %18
%65 = load i32**, i32*** %10
store i32* %64, i32** %65
%66 = load i32*, i32** %18
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %72
68: ; preds = %63
%69 = load i8**, i8*** %11
%70 = load i8*, i8** %69
%71 = call i32 @free(i8* %70)
store i32 3, i32* %9
br label %185
72: ; preds = %63
%73 = load i32, i32* %12
%74 = icmp sge i32 %73, 4096
br i1 %74, label %75, label %78
75: ; preds = %72
store i32 1, i32* %20
store i32 512, i32* %19
%76 = load i32*, i32** %17
store i32* %76, i32** %22
%77 = load i32*, i32** %14
store i32* %77, i32** %21
br label %81
78: ; preds = %72
store i32 0, i32* %20
store i32 64, i32* %19
%79 = load i32*, i32** %16
store i32* %79, i32** %22
%80 = load i32*, i32** %15
store i32* %80, i32** %21
br label %81
81: ; preds = %78, %75
br label %82
82: ; preds = %183, %81
%83 = load i32, i32* %13
%84 = icmp slt i32 %83, -3
br i1 %84, label %85, label %184
85: ; preds = %82
%86 = load i32, i32* %13
%87 = load i32, i32* %20
%88 = add nsw i32 %86, %87
%89 = load i32, i32* %19
%90 = mul nsw i32 %88, %89
%91 = sext i32 %90 to i64
store i64 %91, i64* %23
%92 = load i64, i64* %23
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %103
94: ; preds = %85
%95 = load i32*, i32** %18
%96 = call i32 @fclose(i32* %95)
%97 = load i8**, i8*** %11
%98 = load i8*, i8** %97
%99 = call i32 @remove(i8* %98)
%100 = load i8**, i8*** %11
%101 = load i8*, i8** %100
%102 = call i32 @free(i8* %101)
store i32 4, i32* %9
br label %185
103: ; preds = %85
%104 = load i32, i32* %19
%105 = load i32, i32* %12
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %109
107: ; preds = %103
%108 = load i32, i32* %19
br label %111
109: ; preds = %103
%110 = load i32, i32* %12
br label %111
111: ; preds = %109, %107
%112 = phi i32 [ %108, %107 ], [ %110, %109 ]
%113 = sext i32 %112 to i64
store i64 %113, i64* %24
%114 = load i32*, i32** %22
%115 = load i64, i64* %23
%116 = load i32, i32* @SEEK_SET
%117 = call i64 @fseek(i32* %114, i64 %115, i32 %116)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %128
119: ; preds = %111
%120 = load i32*, i32** %18
%121 = call i32 @fclose(i32* %120)
%122 = load i8**, i8*** %11
%123 = load i8*, i8** %122
%124 = call i32 @remove(i8* %123)
%125 = load i8**, i8*** %11
%126 = load i8*, i8** %125
%127 = call i32 @free(i8* %126)
store i32 4, i32* %9
br label %185
128: ; preds = %111
%129 = getelementptr inbounds [512 x i32], [512 x i32]* %25, i64 0, i64 0
%130 = load i64, i64* %24
%131 = load i32*, i32** %22
%132 = call i32 @fread(i32* %129, i64 %130, i32 1, i32* %131)
%133 = load i32*, i32** %22
%134 = call i64 @ferror(i32* %133)
%135 = icmp ne i64 %134, 0
br i1 %135, label %136, label %145
136: ; preds = %128
%137 = load i32*, i32** %18
%138 = call i32 @fclose(i32* %137)
%139 = load i8**, i8*** %11
%140 = load i8*, i8** %139
%141 = call i32 @remove(i8* %140)
%142 = load i8**, i8*** %11
%143 = load i8*, i8** %142
%144 = call i32 @free(i8* %143)
store i32 5, i32* %9
br label %185
145: ; preds = %128
%146 = getelementptr inbounds [512 x i32], [512 x i32]* %25, i64 0, i64 0
%147 = load i64, i64* %24
%148 = load i32*, i32** %18
%149 = call i32 @fwrite(i32* %146, i64 %147, i32 1, i32* %148)
%150 = load i32*, i32** %18
%151 = call i64 @ferror(i32* %150)
%152 = icmp ne i64 %151, 0
br i1 %152, label %153, label %162
153: ; preds = %145
%154 = load i32*, i32** %18
%155 = call i32 @fclose(i32* %154)
%156 = load i8**, i8*** %11
%157 = load i8*, i8** %156
%158 = call i32 @remove(i8* %157)
%159 = load i8**, i8*** %11
%160 = load i8*, i8** %159
%161 = call i32 @free(i8* %160)
store i32 6, i32* %9
br label %185
162: ; preds = %145
%163 = load i32*, i32** %21
%164 = load i32, i32* %13
%165 = mul nsw i32 %164, 4
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i32, i32* %163, i64 %166
%168 = call i32 @fil_sreadU32(i32* %167)
store i32 %168, i32* %13
%169 = load i32, i32* %19
%170 = load i32, i32* %12
%171 = icmp slt i32 %169, %170
br i1 %171, label %172, label %174
172: ; preds = %162
%173 = load i32, i32* %19
br label %176
174: ; preds = %162
%175 = load i32, i32* %12
br label %176
176: ; preds = %174, %172
%177 = phi i32 [ %173, %172 ], [ %175, %174 ]
%178 = load i32, i32* %12
%179 = sub nsw i32 %178, %177
store i32 %179, i32* %12
%180 = load i32, i32* %12
%181 = icmp eq i32 %180, 0
br i1 %181, label %182, label %183
182: ; preds = %176
br label %184
183: ; preds = %176
br label %82
184: ; preds = %182, %82
store i32 0, i32* %9
br label %185
185: ; preds = %184, %153, %136, %119, %94, %68, %61, %39, %33
%186 = load i32, i32* %9
ret i32 %186
}

LLVM IR (-O2):
@L_tmpnam = global i64 0
@.str = [4 x i8] c"w+b\00"
@.str.1 = [3 x i8] c"./\00"
@.str.2 = [15 x i8] c"rtf2latex-tmp-\00"
@SEEK_SET = global i32 0
define i32 @__cole_extract_file(i32** nocapture writeonly %0, i8** nocapture %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* nocapture %6, i32* nocapture %7) {
%9 = alloca [512 x i32]
%10 = bitcast [512 x i32]* %9 to i8*
%11 = load i64, i64* @L_tmpnam
%12 = add nsw i64 %11, 1
%13 = tail call i8* @malloc(i64 %12)
store i8* %13, i8** %1
%14 = icmp eq i8* %13, null
br i1 %14, label %85, label %15
15: ; preds = %8
%16 = tail call i32* @tmpnam(i8* %13)
%17 = icmp eq i32* %16, null
%18 = load i8*, i8** %1
br i1 %17, label %81, label %19
19: ; preds = %15
%20 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %19
store i32* %20, i32** %0
br label %32
23: ; preds = %19
%24 = load i8*, i8** %1
%25 = tail call i32 @free(i8* %24)
%26 = tail call i8* @tempnam(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %1
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %1
%29 = icmp eq i8* %28, null
br i1 %29, label %85, label %30
30: ; preds = %23
store i32* %27, i32** %0
%31 = icmp eq i32* %27, null
br i1 %31, label %78, label %32
32: ; preds = %22, %30
%33 = phi i32* [ %20, %22 ], [ %27, %30 ]
%34 = icmp sgt i32 %2, 4095
%35 = select i1 %34, i32 512, i32 64
%36 = zext i1 %34 to i32
%37 = select i1 %34, i32* %4, i32* %5
%38 = select i1 %34, i32* %7, i32* %6
%39 = icmp slt i32 %3, -3
br i1 %39, label %40, label %85
40: ; preds = %32
%41 = getelementptr inbounds [512 x i32], [512 x i32]* %9, i64 0, i64 0
br label %42
42: ; preds = %40, %64
%43 = phi i32 [ %68, %64 ], [ %3, %40 ]
%44 = phi i32 [ %69, %64 ], [ %2, %40 ]
%45 = add nsw i32 %43, %36
%46 = mul nsw i32 %45, %35
%47 = icmp slt i32 %46, 0
br i1 %47, label %73, label %48
48: ; preds = %42
%49 = zext i32 %46 to i64
%50 = icmp slt i32 %35, %44
%51 = select i1 %50, i32 %35, i32 %44
%52 = sext i32 %51 to i64
%53 = load i32, i32* @SEEK_SET
%54 = tail call i64 @fseek(i32* %38, i64 %49, i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %73
56: ; preds = %48
%57 = call i32 @fread(i32* %41, i64 %52, i32 1, i32* %38)
%58 = tail call i64 @ferror(i32* %38)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %73
60: ; preds = %56
%61 = call i32 @fwrite(i32* %41, i64 %52, i32 1, i32* %33)
%62 = tail call i64 @ferror(i32* %33)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %73
64: ; preds = %60
%65 = shl nsw i32 %43, 2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %37, i64 %66
%68 = tail call i32 @fil_sreadU32(i32* %67)
%69 = sub nsw i32 %44, %51
%70 = icmp ne i32 %69, 0
%71 = icmp slt i32 %68, -3
%72 = select i1 %70, i1 %71, i1 false
br i1 %72, label %42, label %85
73: ; preds = %60, %56, %48, %42
%74 = phi i32 [ 4, %42 ], [ 4, %48 ], [ 5, %56 ], [ 6, %60 ]
%75 = tail call i32 @fclose(i32* %33)
%76 = load i8*, i8** %1
%77 = tail call i32 @remove(i8* %76)
br label %78
78: ; preds = %73, %30
%79 = phi i32 [ 3, %30 ], [ %74, %73 ]
%80 = load i8*, i8** %1
br label %81
81: ; preds = %78, %15
%82 = phi i8* [ %18, %15 ], [ %80, %78 ]
%83 = phi i32 [ 2, %15 ], [ %79, %78 ]
%84 = tail call i32 @free(i8* %82)
br label %85
85: ; preds = %64, %81, %32, %23, %8
%86 = phi i32 [ 1, %8 ], [ 2, %23 ], [ 0, %32 ], [ %83, %81 ], [ 0, %64 ]
ret i32 %86
}