#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_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void main(int iArgC, char **cArgV) {
  FILE *fTGA;
  unsigned char cTGAHeader[18];
  unsigned char cTGABuffer[768];
  FILE *fLMP;
  unsigned char cPalBuffer[768];
  short iPalLoop, iTGALoop;
  printf("TGA2PAL V%s by Marco Hladik\n", "1.0");
  printf("============================\n\n");
  if (iArgC <= 1) {
    printf("[ERROR] No .TGA file specified.\n\n");
    printf("Usage: tga2pal input.tga");
    return;
  }
  printf("Opening %s... ", cArgV[1]);
  fTGA = fopen(cArgV[1], "rb");
  if (!fTGA) {
    printf("[FAIL]\n[ERROR] Cannot find %s!\n", cArgV[1]);
    return;
  }
  fread(cTGAHeader, 1, 18, fTGA);
  printf("\nValidating TARGA Header... \n");
  if (cTGAHeader[16] != 24) {
    printf("[ERROR] %s is not 24bit!\n", cArgV[1]);
    return;
  }
  if (cTGAHeader[12] != 16) {
    printf("[ERROR] %s width is not 16!\n", cArgV[1]);
    return;
  } else if (cTGAHeader[14] != 16) {
    printf("[ERROR] %s height is not 16!\n", cArgV[1]);
    return;
  }
  fseek(fTGA, 18, SEEK_SET);
  printf("Reading TARGA buffer... \n");
  fread(cTGABuffer, 1, 768, fTGA);
  fclose(fTGA);
  printf("Flipping buffer and sorting BGR > RGB... \n");
  for (iTGALoop = 15; iTGALoop >= 0; iTGALoop--) {
    for (iPalLoop = 0; iPalLoop < 16; iPalLoop++) {
      cPalBuffer[((15 - iTGALoop) * 48) + (iPalLoop * 3) + 0] =
          cTGABuffer[(iTGALoop * 48) + (iPalLoop * 3) + 2];
      cPalBuffer[((15 - iTGALoop) * 48) + (iPalLoop * 3) + 1] =
          cTGABuffer[(iTGALoop * 48) + (iPalLoop * 3) + 1];
      cPalBuffer[((15 - iTGALoop) * 48) + (iPalLoop * 3) + 2] =
          cTGABuffer[(iTGALoop * 48) + (iPalLoop * 3) + 0];
    }
  }
  printf("Saving output to palette.lmp... \n");
  fLMP = fopen("palette.lmp", "w+b");
  fwrite(cPalBuffer, 1, 768, fLMP);
  fclose(fLMP);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
jg     11c0 <main+0x60>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14a3 <main+0x343>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1214 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14a3 <main+0x343>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x12,%edx
call   1030 <fread@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movzbl -0x20(%rbp),%eax
cmp    $0x18,%eax
je     1261 <main+0x101>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14a3 <main+0x343>
movzbl -0x24(%rbp),%eax
cmp    $0x10,%eax
je     1289 <main+0x129>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14a3 <main+0x343>
movzbl -0x22(%rbp),%eax
cmp    $0x10,%eax
je     12b1 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14a3 <main+0x343>
jmp    12b6 <main+0x156>
mov    -0x18(%rbp),%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    $0x12,%esi
call   1060 <fseek@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x330(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x300,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movw   $0xf,-0x644(%rbp)
movswl -0x644(%rbp),%eax
cmp    $0x0,%eax
jl     1452 <main+0x2f2>
movw   $0x0,-0x642(%rbp)
movswl -0x642(%rbp),%eax
cmp    $0x10,%eax
jge    1436 <main+0x2d6>
movswl -0x644(%rbp),%eax
imul   $0x30,%eax,%eax
movswl -0x642(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    -0x330(%rbp,%rax,1),%cl
movswl -0x644(%rbp),%edx
mov    $0xf,%eax
sub    %edx,%eax
imul   $0x30,%eax,%eax
movswl -0x642(%rbp),%edx
imul   $0x3,%edx,%edx
add    %edx,%eax
add    $0x0,%eax
cltq
mov    %cl,-0x640(%rbp,%rax,1)
movswl -0x644(%rbp),%eax
imul   $0x30,%eax,%eax
movswl -0x642(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    -0x330(%rbp,%rax,1),%cl
movswl -0x644(%rbp),%edx
mov    $0xf,%eax
sub    %edx,%eax
imul   $0x30,%eax,%eax
movswl -0x642(%rbp),%edx
imul   $0x3,%edx,%edx
add    %edx,%eax
add    $0x1,%eax
cltq
mov    %cl,-0x640(%rbp,%rax,1)
movswl -0x644(%rbp),%eax
imul   $0x30,%eax,%eax
movswl -0x642(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    %ecx,%eax
add    $0x0,%eax
cltq
mov    -0x330(%rbp,%rax,1),%cl
movswl -0x644(%rbp),%edx
mov    $0xf,%eax
sub    %edx,%eax
imul   $0x30,%eax,%eax
movswl -0x642(%rbp),%edx
imul   $0x3,%edx,%edx
add    %edx,%eax
add    $0x2,%eax
cltq
mov    %cl,-0x640(%rbp,%rax,1)
mov    -0x642(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x642(%rbp)
jmp    132e <main+0x1ce>
jmp    143b <main+0x2db>
mov    -0x644(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x644(%rbp)
jmp    1315 <main+0x1b5>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd20(%rip),%rdi
lea    0xd25(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x338(%rbp)
lea    -0x640(%rbp),%rdi
mov    -0x338(%rbp),%rcx
mov    $0x1,%esi
mov    $0x300,%edx
call   1080 <fwrite@plt>
mov    -0x338(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x620,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe79(%rip),%rdi
lea    0xe8f(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xf35(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jg     11cb <main+0x5b>
lea    0xfc3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
add    $0x620,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1330 <main+0x1c0>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x12,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x18,0x10(%rsp)
jne    133d <main+0x1cd>
cmpb   $0x10,0xc(%rsp)
jne    134a <main+0x1da>
cmpb   $0x10,0xe(%rsp)
jne    1357 <main+0x1e7>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x12,%esi
call   1070 <fseek@plt>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0x320(%rsp),%rdi
mov    $0x1,%esi
mov    $0x300,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
lea    0x22(%rsp),%rax
lea    0x5f2(%rsp),%rcx
mov    $0xf,%edx
nopl   (%rax)
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rcx,%rsi,1),%ebx
mov    %bl,-0x2(%rax,%rsi,1)
movzbl -0x1(%rcx,%rsi,1),%ebx
mov    %bl,-0x1(%rax,%rsi,1)
movzbl -0x2(%rcx,%rsi,1),%ebx
mov    %bl,(%rax,%rsi,1)
add    $0x3,%rsi
cmp    $0x30,%rsi
jne    12b0 <main+0x140>
lea    -0x1(%rdx),%esi
add    $0x30,%rax
add    $0xffffffffffffffd0,%rcx
test   %edx,%edx
mov    %esi,%edx
jg     12a0 <main+0x130>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
lea    0xdca(%rip),%rdi
lea    0xdcf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x300,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
add    $0x620,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fclose@plt>
mov    0x8(%rbx),%rsi
lea    0xd11(%rip),%rdi
jmp    1362 <main+0x1f2>
mov    0x8(%rbx),%rsi
lea    0xd24(%rip),%rdi
jmp    1362 <main+0x1f2>
mov    0x8(%rbx),%rsi
lea    0xd31(%rip),%rdi
jmp    1362 <main+0x1f2>
mov    0x8(%rbx),%rsi
lea    0xd41(%rip),%rdi
xor    %eax,%eax
add    $0x620,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"TGA2PAL V%s by Marco Hladik\0A\00"
@.str.1 = [4 x i8] c"1.0\00"
@.str.2 = [31 x i8] c"============================\0A\0A\00"
@.str.3 = [34 x i8] c"[ERROR] No .TGA file specified.\0A\0A\00"
@.str.4 = [25 x i8] c"Usage: tga2pal input.tga\00"
@.str.5 = [15 x i8] c"Opening %s... \00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [32 x i8] c"[FAIL]\0A[ERROR] Cannot find %s!\0A\00"
@.str.8 = [30 x i8] c"\0AValidating TARGA Header... \0A\00"
@.str.9 = [26 x i8] c"[ERROR] %s is not 24bit!\0A\00"
@.str.10 = [29 x i8] c"[ERROR] %s width is not 16!\0A\00"
@.str.11 = [30 x i8] c"[ERROR] %s height is not 16!\0A\00"
@SEEK_SET = global i32 0
@.str.12 = [26 x i8] c"Reading TARGA buffer... \0A\00"
@.str.13 = [43 x i8] c"Flipping buffer and sorting BGR > RGB... \0A\00"
@.str.14 = [34 x i8] c"Saving output to palette.lmp... \0A\00"
@.str.15 = [12 x i8] c"palette.lmp\00"
@.str.16 = [4 x i8] c"w+b\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [18 x i8]
%7 = alloca [768 x i8]
%8 = alloca i32*
%9 = alloca [768 x i8]
%10 = alloca i16
%11 = alloca i16
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = icmp sle i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %172
19: ; preds = %2
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %27, i32** %5
%28 = load i32*, i32** %5
%29 = icmp ne i32* %28, null
br i1 %29, label %35, label %30
30: ; preds = %19
%31 = load i8**, i8*** %4
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %33)
br label %172
35: ; preds = %19
%36 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%37 = load i32*, i32** %5
%38 = call i32 @fread(i8* %36, i32 1, i32 18, i32* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%40 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 16
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp ne i32 %42, 24
br i1 %43, label %44, label %49
44: ; preds = %35
%45 = load i8**, i8*** %4
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %47)
br label %172
49: ; preds = %35
%50 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 12
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp ne i32 %52, 16
br i1 %53, label %54, label %59
54: ; preds = %49
%55 = load i8**, i8*** %4
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %57)
br label %172
59: ; preds = %49
%60 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 14
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %62, 16
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load i8**, i8*** %4
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i8* %67)
br label %172
69: ; preds = %59
br label %70
70: ; preds = %69
%71 = load i32*, i32** %5
%72 = load i32, i32* @SEEK_SET
%73 = call i32 @fseek(i32* %71, i32 18, i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
%75 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 0
%76 = load i32*, i32** %5
%77 = call i32 @fread(i8* %75, i32 1, i32 768, i32* %76)
%78 = load i32*, i32** %5
%79 = call i32 @fclose(i32* %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0))
store i16 15, i16* %11
br label %81
81: ; preds = %161, %70
%82 = load i16, i16* %11
%83 = sext i16 %82 to i32
%84 = icmp sge i32 %83, 0
br i1 %84, label %85, label %164
85: ; preds = %81
store i16 0, i16* %10
br label %86
86: ; preds = %157, %85
%87 = load i16, i16* %10
%88 = sext i16 %87 to i32
%89 = icmp slt i32 %88, 16
br i1 %89, label %90, label %160
90: ; preds = %86
%91 = load i16, i16* %11
%92 = sext i16 %91 to i32
%93 = mul nsw i32 %92, 48
%94 = load i16, i16* %10
%95 = sext i16 %94 to i32
%96 = mul nsw i32 %95, 3
%97 = add nsw i32 %93, %96
%98 = add nsw i32 %97, 2
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = load i16, i16* %11
%103 = sext i16 %102 to i32
%104 = sub nsw i32 15, %103
%105 = mul nsw i32 %104, 48
%106 = load i16, i16* %10
%107 = sext i16 %106 to i32
%108 = mul nsw i32 %107, 3
%109 = add nsw i32 %105, %108
%110 = add nsw i32 %109, 0
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [768 x i8], [768 x i8]* %9, i64 0, i64 %111
store i8 %101, i8* %112
%113 = load i16, i16* %11
%114 = sext i16 %113 to i32
%115 = mul nsw i32 %114, 48
%116 = load i16, i16* %10
%117 = sext i16 %116 to i32
%118 = mul nsw i32 %117, 3
%119 = add nsw i32 %115, %118
%120 = add nsw i32 %119, 1
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 %121
%123 = load i8, i8* %122
%124 = load i16, i16* %11
%125 = sext i16 %124 to i32
%126 = sub nsw i32 15, %125
%127 = mul nsw i32 %126, 48
%128 = load i16, i16* %10
%129 = sext i16 %128 to i32
%130 = mul nsw i32 %129, 3
%131 = add nsw i32 %127, %130
%132 = add nsw i32 %131, 1
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds [768 x i8], [768 x i8]* %9, i64 0, i64 %133
store i8 %123, i8* %134
%135 = load i16, i16* %11
%136 = sext i16 %135 to i32
%137 = mul nsw i32 %136, 48
%138 = load i16, i16* %10
%139 = sext i16 %138 to i32
%140 = mul nsw i32 %139, 3
%141 = add nsw i32 %137, %140
%142 = add nsw i32 %141, 0
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [768 x i8], [768 x i8]* %7, i64 0, i64 %143
%145 = load i8, i8* %144
%146 = load i16, i16* %11
%147 = sext i16 %146 to i32
%148 = sub nsw i32 15, %147
%149 = mul nsw i32 %148, 48
%150 = load i16, i16* %10
%151 = sext i16 %150 to i32
%152 = mul nsw i32 %151, 3
%153 = add nsw i32 %149, %152
%154 = add nsw i32 %153, 2
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [768 x i8], [768 x i8]* %9, i64 0, i64 %155
store i8 %145, i8* %156
br label %157
157: ; preds = %90
%158 = load i16, i16* %10
%159 = add i16 %158, 1
store i16 %159, i16* %10
br label %86
160: ; preds = %86
br label %161
161: ; preds = %160
%162 = load i16, i16* %11
%163 = add i16 %162, -1
store i16 %163, i16* %11
br label %81
164: ; preds = %81
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.14, i64 0, i64 0))
%166 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0))
store i32* %166, i32** %8
%167 = getelementptr inbounds [768 x i8], [768 x i8]* %9, i64 0, i64 0
%168 = load i32*, i32** %8
%169 = call i32 @fwrite(i8* %167, i32 1, i32 768, i32* %168)
%170 = load i32*, i32** %8
%171 = call i32 @fclose(i32* %170)
br label %172
172: ; preds = %164, %64, %54, %44, %30, %16
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"TGA2PAL V%s by Marco Hladik\0A\00"
@.str.1 = [4 x i8] c"1.0\00"
@.str.4 = [25 x i8] c"Usage: tga2pal input.tga\00"
@.str.5 = [15 x i8] c"Opening %s... \00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [32 x i8] c"[FAIL]\0A[ERROR] Cannot find %s!\0A\00"
@.str.9 = [26 x i8] c"[ERROR] %s is not 24bit!\0A\00"
@.str.10 = [29 x i8] c"[ERROR] %s width is not 16!\0A\00"
@.str.11 = [30 x i8] c"[ERROR] %s height is not 16!\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [12 x i8] c"palette.lmp\00"
@.str.16 = [4 x i8] c"w+b\00"
@str = [30 x i8] c"============================\0A\00"
@str.17 = [29 x i8] c"\0AValidating TARGA Header... \00"
@str.18 = [25 x i8] c"Reading TARGA buffer... \00"
@str.19 = [42 x i8] c"Flipping buffer and sorting BGR > RGB... \00"
@str.20 = [33 x i8] c"Saving output to palette.lmp... \00"
@str.21 = [33 x i8] c"[ERROR] No .TGA file specified.\0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [18 x i8]
%4 = alloca [768 x i8]
%5 = alloca [768 x i8]
%6 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [768 x i8], [768 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [768 x i8], [768 x i8]* %5, i64 0, i64 0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.21, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %90
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %16
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i8*, i8** %16
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %23)
br label %90
25: ; preds = %15
%26 = call i32 @fread(i8* %6, i32 1, i32 18, i32* %20)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.17, i64 0, i64 0))
%28 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 16
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 24
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i8*, i8** %16
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %32)
br label %90
34: ; preds = %25
%35 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 12
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 16
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = load i8*, i8** %16
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %39)
br label %90
41: ; preds = %34
%42 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 14
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 16
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i8*, i8** %16
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i8* %46)
br label %90
48: ; preds = %41
%49 = load i32, i32* @SEEK_SET
%50 = tail call i32 @fseek(i32* %20, i32 18, i32 %49)
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.18, i64 0, i64 0))
%52 = call i32 @fread(i8* %7, i32 1, i32 768, i32* %20)
%53 = tail call i32 @fclose(i32* %20)
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.19, i64 0, i64 0))
br label %55
55: ; preds = %48, %81
%56 = phi i32 [ 15, %48 ], [ %82, %81 ]
%57 = phi i64 [ 15, %48 ], [ %84, %81 ]
%58 = mul nuw nsw i64 %57, 48
%59 = sub nuw nsw i64 15, %57
%60 = mul nuw nsw i64 %59, 48
br label %61
61: ; preds = %55, %61
%62 = phi i64 [ 0, %55 ], [ %79, %61 ]
%63 = mul nuw nsw i64 %62, 3
%64 = add nuw nsw i64 %63, %58
%65 = add nuw nsw i64 %64, 2
%66 = getelementptr inbounds [768 x i8], [768 x i8]* %4, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = add nuw nsw i64 %63, %60
%69 = getelementptr inbounds [768 x i8], [768 x i8]* %5, i64 0, i64 %68
store i8 %67, i8* %69
%70 = add nuw nsw i64 %64, 1
%71 = getelementptr inbounds [768 x i8], [768 x i8]* %4, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = add nuw nsw i64 %68, 1
%74 = getelementptr inbounds [768 x i8], [768 x i8]* %5, i64 0, i64 %73
store i8 %72, i8* %74
%75 = getelementptr inbounds [768 x i8], [768 x i8]* %4, i64 0, i64 %64
%76 = load i8, i8* %75
%77 = add nuw nsw i64 %68, 2
%78 = getelementptr inbounds [768 x i8], [768 x i8]* %5, i64 0, i64 %77
store i8 %76, i8* %78
%79 = add nuw nsw i64 %62, 1
%80 = icmp eq i64 %79, 16
br i1 %80, label %81, label %61
81: ; preds = %61
%82 = add nsw i32 %56, -1
%83 = icmp sgt i32 %56, 0
%84 = add nsw i64 %57, -1
br i1 %83, label %55, label %85
85: ; preds = %81
%86 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.20, i64 0, i64 0))
%87 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0))
%88 = call i32 @fwrite(i8* %8, i32 1, i32 768, i32* %87)
%89 = tail call i32 @fclose(i32* %87)
br label %90
90: ; preds = %85, %45, %38, %31, %22, %12
ret void
}