#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 */
short fread(unsigned char *, int, short, int /*<<< orphan*/ *);
scalar_t__ malloc(short);
int /*<<< orphan*/ printf(char *, ...);
unsigned char *SHL_LoadCTGA(FILE *file, int width, int height,
                            short pixelDepth) {
  printf("W: %d H: %d\n", width, height);
  short bytesPrPxl = pixelDepth / 8;
  int imageSize = bytesPrPxl * width * height;
  printf("SZ: %d\n", imageSize);
  unsigned char *imageData = (unsigned char *)malloc(imageSize);
  if (imageData == NULL) {
    printf("\tSHL ERR: "
           "Failed to allocate memory for image!"
           "\n");
    ;
    return NULL;
  }
  unsigned int pixelC = width * height;
  unsigned int currPixel = 0;
  unsigned int currByte = 0;
  unsigned char *colorBuffer = (unsigned char *)malloc(bytesPrPxl);
  do {
    unsigned char chunkHeader = 0;
    fread(&chunkHeader, sizeof(unsigned char), 1, file);
    if (chunkHeader < 128) {
      chunkHeader++;
      for (short c = 0; c < chunkHeader; c++) {
        if (fread(colorBuffer, 1, bytesPrPxl, file) != bytesPrPxl) {
          printf("\tSHL ERR: "
                 "Could not read image data!"
                 "\n");
          ;
          return NULL;
        }
        imageData[currByte] = colorBuffer[2];
        imageData[currByte + 1] = colorBuffer[1];
        imageData[currByte + 2] = colorBuffer[0];
        if (bytesPrPxl == 4)
          imageData[currByte + 3] = colorBuffer[3];
        currByte += bytesPrPxl;
        currPixel++;
        if (currPixel > pixelC)
          printf("\tSHL ERR: "
                 "Too many pixels!"
                 "\n");
        ;
      }
    } else {
      chunkHeader -= 127;
      fread(colorBuffer, 1, bytesPrPxl, file);
      for (short c = 0; c < chunkHeader; c++) {
        imageData[currByte] = colorBuffer[2];
        imageData[currByte + 1] = colorBuffer[1];
        imageData[currByte + 2] = colorBuffer[0];
        if (bytesPrPxl == 4)
          imageData[currByte + 3] = colorBuffer[3];
        currByte += bytesPrPxl;
        currPixel++;
        if (currPixel > pixelC) {
          printf("\tSHL ERR: "
                 "TOO many pixel read"
                 "\n");
          ;
          return NULL;
        }
      }
    }
  } while (currPixel < pixelC);
  return imageData;
}


x86 assembly (clang, -O0):
<SHL_LoadCTGA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cx,%ax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movswl -0x1a(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %ax,-0x1c(%rbp)
movswl -0x1c(%rbp),%eax
imul   -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
movswl %ax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c2 <SHL_LoadCTGA+0x92>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    141a <SHL_LoadCTGA+0x2ea>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movswl -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
movb   $0x0,-0x41(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x41(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movzbl -0x41(%rbp),%eax
cmp    $0x80,%eax
jge    1314 <SHL_LoadCTGA+0x1e4>
mov    -0x41(%rbp),%al
add    $0x1,%al
mov    %al,-0x41(%rbp)
movw   $0x0,-0x44(%rbp)
movswl -0x44(%rbp),%eax
movzbl -0x41(%rbp),%ecx
cmp    %ecx,%eax
jge    130f <SHL_LoadCTGA+0x1df>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%ax
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
movswl %ax,%edx
call   1030 <fread@plt>
cwtl
movswl -0x1c(%rbp),%ecx
cmp    %ecx,%eax
je     126d <SHL_LoadCTGA+0x13d>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    141a <SHL_LoadCTGA+0x2ea>
mov    -0x40(%rbp),%rax
mov    0x2(%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    (%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
movswl -0x1c(%rbp),%eax
cmp    $0x4,%eax
jne    12cc <SHL_LoadCTGA+0x19c>
mov    -0x40(%rbp),%rax
mov    0x3(%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
movswl -0x1c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jbe    12f9 <SHL_LoadCTGA+0x1c9>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fe <SHL_LoadCTGA+0x1ce>
mov    -0x44(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x44(%rbp)
jmp    121c <SHL_LoadCTGA+0xec>
jmp    1401 <SHL_LoadCTGA+0x2d1>
movzbl -0x41(%rbp),%eax
sub    $0x7f,%eax
mov    %al,-0x41(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%ax
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
movswl %ax,%edx
call   1030 <fread@plt>
movw   $0x0,-0x46(%rbp)
movswl -0x46(%rbp),%eax
movzbl -0x41(%rbp),%ecx
cmp    %ecx,%eax
jge    13fc <SHL_LoadCTGA+0x2cc>
mov    -0x40(%rbp),%rax
mov    0x2(%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    (%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
movswl -0x1c(%rbp),%eax
cmp    $0x4,%eax
jne    13ac <SHL_LoadCTGA+0x27c>
mov    -0x40(%rbp),%rax
mov    0x3(%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
movswl -0x1c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jbe    13e6 <SHL_LoadCTGA+0x2b6>
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    141a <SHL_LoadCTGA+0x2ea>
jmp    13eb <SHL_LoadCTGA+0x2bb>
mov    -0x46(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x46(%rbp)
jmp    133d <SHL_LoadCTGA+0x20d>
jmp    1401 <SHL_LoadCTGA+0x2d1>
jmp    1406 <SHL_LoadCTGA+0x2d6>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jb     11e7 <SHL_LoadCTGA+0xb7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHL_LoadCTGA>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r12
lea    0xea1(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%r15),%eax
test   %r15w,%r15w
cmovns %r15d,%eax
movswl %ax,%r13d
sar    $0x3,%r13d
imul   %ebx,%ebp
mov    %ebp,0x14(%rsp)
imul   %r13d,%ebp
lea    0xe7e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movswl %bp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1333 <SHL_LoadCTGA+0x1f3>
mov    %rax,%rbx
mov    %r13d,0x10(%rsp)
mov    %r13d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
and    $0xfff8,%r15d
mov    %r15,0x20(%rsp)
lea    0xf(%rsp),%rdi
xor    %r15d,%r15d
mov    %r12,0x18(%rsp)
movb   $0x0,0xf(%rsp)
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
movzbl 0xf(%rsp),%r13d
test   %r13b,%r13b
js     12a0 <SHL_LoadCTGA+0x160>
add    $0x1,%r13d
mov    $0x1,%r12w
mov    0x10(%rsp),%edx
jmp    1224 <SHL_LoadCTGA+0xe4>
nopw   0x0(%rax,%rax,1)
add    %edx,%r15d
movswl %r12w,%eax
add    $0x1,%r12d
cmp    %r13d,%eax
jge    131c <SHL_LoadCTGA+0x1dc>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    0x18(%rsp),%rcx
call   1040 <fread@plt>
mov    0x10(%rsp),%edx
cmp    %dx,%ax
jne    133c <SHL_LoadCTGA+0x1fc>
lea    0x1(%r15),%eax
lea    0x2(%r15),%ecx
mov    %rbx,%rdi
movzbl 0x2(%rbp),%ebx
mov    %r15d,%esi
mov    %bl,(%rdi,%rsi,1)
movzbl 0x1(%rbp),%ebx
mov    %bl,(%rdi,%rax,1)
mov    %rdi,%rbx
movzbl 0x0(%rbp),%eax
mov    %al,(%rdi,%rcx,1)
cmpw   $0x20,0x20(%rsp)
jne    127c <SHL_LoadCTGA+0x13c>
movzbl 0x3(%rbp),%eax
lea    0x3(%r15),%ecx
mov    %al,(%rbx,%rcx,1)
add    $0x1,%r14d
cmp    0x14(%rsp),%r14d
jbe    1210 <SHL_LoadCTGA+0xd0>
lea    0xda5(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%edx
jmp    1210 <SHL_LoadCTGA+0xd0>
nopl   0x0(%rax)
add    $0x81,%r13b
mov    %r13b,0xf(%rsp)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12,%rcx
mov    0x10(%rsp),%r12d
mov    %r12d,%edx
call   1040 <fread@plt>
movzbl %r13b,%r8d
mov    $0x1,%cx
nopl   0x0(%rax)
lea    0x1(%r15),%edx
lea    0x2(%r15),%esi
movzbl 0x2(%rbp),%eax
mov    %r15d,%edi
mov    %al,(%rbx,%rdi,1)
movzbl 0x1(%rbp),%eax
mov    %al,(%rbx,%rdx,1)
movzbl 0x0(%rbp),%eax
mov    %al,(%rbx,%rsi,1)
cmpw   $0x20,0x20(%rsp)
jne    1303 <SHL_LoadCTGA+0x1c3>
movzbl 0x3(%rbp),%eax
lea    0x3(%r15),%edx
mov    %al,(%rbx,%rdx,1)
add    $0x1,%r14d
cmp    0x14(%rsp),%r14d
ja     1345 <SHL_LoadCTGA+0x205>
add    %r12d,%r15d
movswl %cx,%eax
add    $0x1,%ecx
cmp    %r8d,%eax
jl     12d0 <SHL_LoadCTGA+0x190>
cmp    0x14(%rsp),%r14d
mov    0x18(%rsp),%r12
lea    0xf(%rsp),%rdi
jb     11d5 <SHL_LoadCTGA+0x95>
jmp    1353 <SHL_LoadCTGA+0x213>
lea    0xd39(%rip),%rdi
jmp    134c <SHL_LoadCTGA+0x20c>
lea    0xd0b(%rip),%rdi
jmp    134c <SHL_LoadCTGA+0x20c>
lea    0xcc9(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"W: %d H: %d\0A\00"
@.str.1 = [8 x i8] c"SZ: %d\0A\00"
@str = [30 x i8] c"\09SHL ERR: TOO many pixel read\00"
@str.6 = [27 x i8] c"\09SHL ERR: Too many pixels!\00"
@str.7 = [37 x i8] c"\09SHL ERR: Could not read image data!\00"
@str.8 = [47 x i8] c"\09SHL ERR: Failed to allocate memory for image!\00"
define i8* @SHL_LoadCTGA(i32* nocapture %0, i32 %1, i32 %2, i16 signext %3) {
%5 = alloca i8
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%7 = sdiv i16 %3, 8
%8 = sext i16 %7 to i32
%9 = mul i32 %2, %1
%10 = mul i32 %9, %8
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = trunc i32 %10 to i16
%13 = tail call i64 @malloc(i16 signext %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.8, i64 0, i64 0))
br label %107
18: ; preds = %4
%19 = tail call i64 @malloc(i16 signext %7)
%20 = inttoptr i64 %19 to i8*
%21 = getelementptr inbounds i8, i8* %20, i64 2
%22 = getelementptr inbounds i8, i8* %20, i64 1
%23 = and i16 %3, -8
%24 = icmp eq i16 %23, 32
%25 = getelementptr inbounds i8, i8* %20, i64 3
br label %26
26: ; preds = %103, %18
%27 = phi i32 [ 0, %18 ], [ %104, %103 ]
%28 = phi i32 [ 0, %18 ], [ %105, %103 ]
store i8 0, i8* %5
%29 = call signext i16 @fread(i8* %5, i32 1, i16 signext 1, i32* %0)
%30 = load i8, i8* %5
%31 = icmp sgt i8 %30, -1
br i1 %31, label %32, label %68
32: ; preds = %26
%33 = add nuw i8 %30, 1
%34 = zext i8 %33 to i32
br label %35
35: ; preds = %32, %64
%36 = phi i16 [ 0, %32 ], [ %65, %64 ]
%37 = phi i32 [ %28, %32 ], [ %59, %64 ]
%38 = phi i32 [ %27, %32 ], [ %60, %64 ]
%39 = tail call signext i16 @fread(i8* %20, i32 1, i16 signext %7, i32* %0)
%40 = icmp eq i16 %39, %7
br i1 %40, label %41, label %100
41: ; preds = %35
%42 = load i8, i8* %21
%43 = zext i32 %37 to i64
%44 = getelementptr inbounds i8, i8* %14, i64 %43
store i8 %42, i8* %44
%45 = load i8, i8* %22
%46 = add i32 %37, 1
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %14, i64 %47
store i8 %45, i8* %48
%49 = load i8, i8* %20
%50 = add i32 %37, 2
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %14, i64 %51
store i8 %49, i8* %52
br i1 %24, label %53, label %58
53: ; preds = %41
%54 = load i8, i8* %25
%55 = add i32 %37, 3
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %14, i64 %56
store i8 %54, i8* %57
br label %58
58: ; preds = %53, %41
%59 = add i32 %37, %8
%60 = add i32 %38, 1
%61 = icmp ugt i32 %60, %9
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
br label %64
64: ; preds = %58, %62
%65 = add i16 %36, 1
%66 = sext i16 %65 to i32
%67 = icmp slt i32 %66, %34
br i1 %67, label %35, label %103
68: ; preds = %26
%69 = add i8 %30, -127
store i8 %69, i8* %5
%70 = tail call signext i16 @fread(i8* %20, i32 1, i16 signext %7, i32* %0)
%71 = zext i8 %69 to i32
br label %72
72: ; preds = %68, %95
%73 = phi i16 [ %97, %95 ], [ 0, %68 ]
%74 = phi i32 [ %96, %95 ], [ %28, %68 ]
%75 = phi i32 [ %93, %95 ], [ %27, %68 ]
%76 = load i8, i8* %21
%77 = zext i32 %74 to i64
%78 = getelementptr inbounds i8, i8* %14, i64 %77
store i8 %76, i8* %78
%79 = load i8, i8* %22
%80 = add i32 %74, 1
%81 = zext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %14, i64 %81
store i8 %79, i8* %82
%83 = load i8, i8* %20
%84 = add i32 %74, 2
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %14, i64 %85
store i8 %83, i8* %86
br i1 %24, label %87, label %92
87: ; preds = %72
%88 = load i8, i8* %25
%89 = add i32 %74, 3
%90 = zext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %14, i64 %90
store i8 %88, i8* %91
br label %92
92: ; preds = %87, %72
%93 = add i32 %75, 1
%94 = icmp ugt i32 %93, %9
br i1 %94, label %100, label %95
95: ; preds = %92
%96 = add i32 %74, %8
%97 = add i16 %73, 1
%98 = sext i16 %97 to i32
%99 = icmp slt i32 %98, %71
br i1 %99, label %72, label %103
100: ; preds = %92, %35
%101 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @str.7, i64 0, i64 0), %35 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0), %92 ]
%102 = tail call i32 @puts(i8* dereferenceable(1) %101)
br label %107
103: ; preds = %95, %64
%104 = phi i32 [ %60, %64 ], [ %93, %95 ]
%105 = phi i32 [ %59, %64 ], [ %96, %95 ]
%106 = icmp ult i32 %104, %9
br i1 %106, label %26, label %107
107: ; preds = %103, %100, %16
%108 = phi i8* [ null, %16 ], [ null, %100 ], [ %14, %103 ]
ret i8* %108
}