#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int getc(int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int readtga(char *name, int *xres, int *yres, unsigned char **imgdata) {
  int format, width, height, w1, w2, h1, h2, depth, flags;
  int imgsize, bytesread, i, tmp;
  FILE *ifp;
  ifp = fopen(name, "r");
  if (ifp == NULL) {
    return 1;
  }
  getc(ifp);
  getc(ifp);
  format = getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  getc(ifp);
  w1 = getc(ifp);
  w2 = getc(ifp);
  h1 = getc(ifp);
  h2 = getc(ifp);
  depth = getc(ifp);
  flags = getc(ifp);
  if ((format != 2) || (depth != 24)) {
    fclose(ifp);
    return 2;
  }
  width = ((w2 << 8) | w1);
  height = ((h2 << 8) | h1);
  imgsize = 3 * width * height;
  *imgdata = malloc(imgsize);
  bytesread = fread(*imgdata, 1, imgsize, ifp);
  fclose(ifp);
  if (flags == 0x20) {
    int rowsize = 3 * width;
    unsigned char *copytmp;
    copytmp = malloc(rowsize);
    for (i = 0; i < height / 2; i++) {
      memcpy(copytmp, &((*imgdata)[rowsize * i]), rowsize);
      memcpy(&(*imgdata)[rowsize * i], &(*imgdata)[rowsize * (height - 1 - i)],
             rowsize);
      memcpy(&(*imgdata)[rowsize * (height - 1 - i)], copytmp, rowsize);
    }
    free(copytmp);
  }
  for (i = 0; i < imgsize; i += 3) {
    tmp = (*imgdata)[i];
    (*imgdata)[i] = (*imgdata)[i + 2];
    (*imgdata)[i + 2] = tmp;
  }
  *xres = width;
  *yres = height;
  if (bytesread != imgsize)
    return 4;
  return 0;
}


x86 assembly (clang, -O0):
<readtga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11b6 <readtga+0x46>
movl   $0x1,-0x4(%rbp)
jmp    1461 <readtga+0x2f1>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x38(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x40(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x44(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x48(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jne    1281 <readtga+0x111>
cmpl   $0x18,-0x48(%rbp)
je     1296 <readtga+0x126>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x2,-0x4(%rbp)
jmp    1461 <readtga+0x2f1>
mov    -0x3c(%rbp),%eax
shl    $0x8,%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x8,%eax
or     -0x40(%rbp),%eax
mov    %eax,-0x34(%rbp)
imul   $0x3,-0x30(%rbp),%eax
imul   -0x34(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x50(%rbp),%edx
mov    -0x68(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x54(%rbp)
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x20,-0x4c(%rbp)
jne    13c4 <readtga+0x254>
imul   $0x3,-0x30(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
cmp    %ecx,%eax
jge    13bb <readtga+0x24b>
mov    -0x78(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x6c(%rbp),%eax
imul   -0x58(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x6c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x6c(%rbp),%eax
imul   -0x58(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x6c(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x58(%rbp),%ecx
imul   %ecx,%eax
cltq
add    %rax,%rsi
mov    -0x6c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x6c(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x58(%rbp),%ecx
imul   %ecx,%eax
cltq
add    %rax,%rdi
mov    -0x78(%rbp),%rsi
mov    -0x6c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1313 <readtga+0x1a3>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1430 <readtga+0x2c0>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movslq -0x58(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    -0x58(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movslq -0x58(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x5c(%rbp),%eax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    -0x58(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x58(%rbp)
jmp    13cb <readtga+0x25b>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x54(%rbp),%eax
cmp    -0x50(%rbp),%eax
je     145a <readtga+0x2ea>
movl   $0x4,-0x4(%rbp)
jmp    1461 <readtga+0x2f1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readtga>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%rbp
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1380 <readtga+0x210>
mov    %rax,%r14
mov    %rbp,0x28(%rsp)
mov    %rbx,0x30(%rsp)
mov    %rax,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,0x10(%rsp)
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1090 <getc@plt>
cmpl   $0x2,0x10(%rsp)
jne    138a <readtga+0x21a>
cmp    $0x18,%r15d
jne    138a <readtga+0x21a>
shl    $0x8,%r12d
or     0x8(%rsp),%r12d
shl    $0x8,%ebp
or     %ebx,%ebp
mov    %r12,0x8(%rsp)
lea    (%r12,%r12,2),%r15d
mov    %ebp,%r12d
imul   %r15d,%r12d
mov    %r12d,%edi
mov    %eax,%ebx
call   1070 <malloc@plt>
mov    %rax,0x0(%r13)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,0x1c(%rsp)
mov    %r14,%rdi
call   1050 <fclose@plt>
cmp    $0x20,%ebx
jne    134a <readtga+0x1da>
mov    %r12d,0x18(%rsp)
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rbp,0x20(%rsp)
cmp    $0x2,%ebp
jl     1338 <readtga+0x1c8>
mov    0x20(%rsp),%rax
mov    %eax,%ebp
shr    %ebp
movslq %r15d,%rcx
mov    %rcx,0x10(%rsp)
add    $0xffffffff,%eax
imul   0x8(%rsp),%eax
lea    (%rax,%rax,2),%ebx
xor    %r12d,%r12d
nopl   (%rax)
mov    0x0(%r13),%rsi
add    %r12,%rsi
mov    %r14,%rdi
mov    %r15d,%edx
call   1060 <memcpy@plt>
mov    0x0(%r13),%rsi
lea    (%rsi,%r12,1),%rdi
movslq %ebx,%rbx
add    %rbx,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
mov    0x0(%r13),%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
sub    %r15d,%ebx
add    0x10(%rsp),%r12
add    $0xffffffffffffffff,%rbp
jne    12f0 <readtga+0x180>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rbp
mov    0x18(%rsp),%r12d
test   %r12d,%r12d
mov    0x28(%rsp),%r8
jle    1409 <readtga+0x299>
mov    %r12d,%ecx
add    $0xffffffffffffffff,%rcx
movabs $0xaaaaaaaaaaaaaaab,%rdx
aa aa aa
mov    %rcx,%rax
mul    %rdx
shr    %rdx
add    $0x1,%rdx
cmp    $0x3,%rcx
jae    139c <readtga+0x22c>
xor    %eax,%eax
jmp    13ee <readtga+0x27e>
mov    $0x1,%eax
jmp    1425 <readtga+0x2b5>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0x2,%eax
jmp    1425 <readtga+0x2b5>
movabs $0x7ffffffffffffffe,%rcx
ff ff 7f
and    %rdx,%rcx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%rsi
movzbl (%rsi,%rax,1),%edi
movzbl 0x2(%rsi,%rax,1),%ebx
mov    %bl,(%rsi,%rax,1)
mov    0x0(%r13),%rsi
mov    %dil,0x2(%rsi,%rax,1)
mov    0x0(%r13),%rsi
movzbl 0x3(%rsi,%rax,1),%edi
movzbl 0x5(%rsi,%rax,1),%ebx
mov    %bl,0x3(%rsi,%rax,1)
mov    0x0(%r13),%rsi
mov    %dil,0x5(%rsi,%rax,1)
add    $0x6,%rax
add    $0xfffffffffffffffe,%rcx
jne    13b0 <readtga+0x240>
test   $0x1,%dl
je     1409 <readtga+0x299>
mov    0x0(%r13),%rcx
mov    (%rcx,%rax,1),%dl
mov    0x2(%rcx,%rax,1),%bl
mov    %bl,(%rcx,%rax,1)
mov    0x0(%r13),%rcx
mov    %dl,0x2(%rcx,%rax,1)
mov    0x8(%rsp),%rax
mov    %eax,(%r8)
mov    0x30(%rsp),%rax
mov    %ebp,(%rax)
xor    %eax,%eax
cmp    %r12d,0x1c(%rsp)
setne  %al
shl    $0x2,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @readtga(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i8** nocapture %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %120, label %7
7: ; preds = %4
%8 = tail call i32 @getc(i32* %5)
%9 = tail call i32 @getc(i32* %5)
%10 = tail call i32 @getc(i32* %5)
%11 = tail call i32 @getc(i32* %5)
%12 = tail call i32 @getc(i32* %5)
%13 = tail call i32 @getc(i32* %5)
%14 = tail call i32 @getc(i32* %5)
%15 = tail call i32 @getc(i32* %5)
%16 = tail call i32 @getc(i32* %5)
%17 = tail call i32 @getc(i32* %5)
%18 = tail call i32 @getc(i32* %5)
%19 = tail call i32 @getc(i32* %5)
%20 = tail call i32 @getc(i32* %5)
%21 = tail call i32 @getc(i32* %5)
%22 = tail call i32 @getc(i32* %5)
%23 = tail call i32 @getc(i32* %5)
%24 = tail call i32 @getc(i32* %5)
%25 = tail call i32 @getc(i32* %5)
%26 = icmp ne i32 %10, 2
%27 = icmp ne i32 %24, 24
%28 = or i1 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %7
%30 = tail call i32 @fclose(i32* %5)
br label %120
31: ; preds = %7
%32 = shl i32 %21, 8
%33 = or i32 %32, %20
%34 = shl i32 %23, 8
%35 = or i32 %34, %22
%36 = mul nsw i32 %33, 3
%37 = mul nsw i32 %35, %36
%38 = tail call i8* @malloc(i32 %37)
store i8* %38, i8** %3
%39 = tail call i32 @fread(i8* %38, i32 1, i32 %37, i32* %5)
%40 = tail call i32 @fclose(i32* %5)
%41 = icmp eq i32 %25, 32
br i1 %41, label %42, label %71
42: ; preds = %31
%43 = tail call i8* @malloc(i32 %36)
%44 = icmp sgt i32 %35, 1
br i1 %44, label %45, label %69
45: ; preds = %42
%46 = lshr i32 %35, 1
%47 = sext i32 %36 to i64
%48 = zext i32 %46 to i64
br label %49
49: ; preds = %45, %49
%50 = phi i64 [ 0, %45 ], [ %67, %49 ]
%51 = load i8*, i8** %3
%52 = mul nsw i64 %50, %47
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = tail call i32 @memcpy(i8* %43, i8* %53, i32 %36)
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i64 %52
%57 = trunc i64 %50 to i32
%58 = xor i32 %57, -1
%59 = add i32 %35, %58
%60 = mul nsw i32 %59, %36
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %55, i64 %61
%63 = tail call i32 @memcpy(i8* %56, i8* %62, i32 %36)
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i64 %61
%66 = tail call i32 @memcpy(i8* %65, i8* %43, i32 %36)
%67 = add nuw nsw i64 %50, 1
%68 = icmp eq i64 %67, %48
br i1 %68, label %69, label %49
69: ; preds = %49, %42
%70 = tail call i32 @free(i8* %43)
br label %71
71: ; preds = %69, %31
%72 = icmp sgt i32 %37, 0
br i1 %72, label %73, label %117
73: ; preds = %71
%74 = zext i32 %37 to i64
%75 = add nsw i64 %74, -1
%76 = udiv i64 %75, 3
%77 = add nuw nsw i64 %76, 1
%78 = and i64 %77, 1
%79 = icmp ult i64 %75, 3
br i1 %79, label %105, label %80
80: ; preds = %73
%81 = and i64 %77, 9223372036854775806
br label %82
82: ; preds = %82, %80
%83 = phi i64 [ 0, %80 ], [ %102, %82 ]
%84 = phi i64 [ 0, %80 ], [ %103, %82 ]
%85 = load i8*, i8** %3
%86 = getelementptr inbounds i8, i8* %85, i64 %83
%87 = load i8, i8* %86
%88 = add nuw nsw i64 %83, 2
%89 = getelementptr inbounds i8, i8* %85, i64 %88
%90 = load i8, i8* %89
store i8 %90, i8* %86
%91 = load i8*, i8** %3
%92 = getelementptr inbounds i8, i8* %91, i64 %88
store i8 %87, i8* %92
%93 = add nuw nsw i64 %83, 3
%94 = load i8*, i8** %3
%95 = getelementptr inbounds i8, i8* %94, i64 %93
%96 = load i8, i8* %95
%97 = add nuw nsw i64 %83, 5
%98 = getelementptr inbounds i8, i8* %94, i64 %97
%99 = load i8, i8* %98
store i8 %99, i8* %95
%100 = load i8*, i8** %3
%101 = getelementptr inbounds i8, i8* %100, i64 %97
store i8 %96, i8* %101
%102 = add nuw nsw i64 %83, 6
%103 = add i64 %84, 2
%104 = icmp eq i64 %103, %81
br i1 %104, label %105, label %82
105: ; preds = %82, %73
%106 = phi i64 [ 0, %73 ], [ %102, %82 ]
%107 = icmp eq i64 %78, 0
br i1 %107, label %117, label %108
108: ; preds = %105
%109 = load i8*, i8** %3
%110 = getelementptr inbounds i8, i8* %109, i64 %106
%111 = load i8, i8* %110
%112 = add nuw nsw i64 %106, 2
%113 = getelementptr inbounds i8, i8* %109, i64 %112
%114 = load i8, i8* %113
store i8 %114, i8* %110
%115 = load i8*, i8** %3
%116 = getelementptr inbounds i8, i8* %115, i64 %112
store i8 %111, i8* %116
br label %117
117: ; preds = %108, %105, %71
store i32 %33, i32* %1
store i32 %35, i32* %2
%118 = icmp eq i32 %39, %37
%119 = select i1 %118, i32 0, i32 4
br label %120
120: ; preds = %117, %4, %29
%121 = phi i32 [ 2, %29 ], [ 1, %4 ], [ %119, %117 ]
ret i32 %121
}