#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 */

/* Variables and functions */
int /*<<< orphan*/ CloseOutput();
int /*<<< orphan*/ DumpBytes(int *, int);
int /*<<< orphan*/ ErrorLine(char *);
int /*<<< orphan*/ OpenOutput(char *, int);
int /*<<< orphan*/ ParsePaletteFile(char *, int **, int *);
char *PchGetString(char *);
int WGetId(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
void ParseDumpPalette() {
  char *pchFileName;
  int id;
  id = WGetId("Data ResourceId");
  pchFileName = PchGetString("Palette Filename");
  if ((pchFileName == NULL) || (strcmp(pchFileName, "") == 0))
    ErrorLine("Empty or no file name provided");
  else {
    int palette[256][3];
    int nColors;
    int c;
    OpenOutput("PALT", id);
    ParsePaletteFile(pchFileName, palette, &nColors);
    for (c = 0; c < nColors; c++) {
      DumpBytes(&c, 1);
      DumpBytes(&palette[c][0], 1);
      DumpBytes(&palette[c][1], 1);
      DumpBytes(&palette[c][2], 1);
    }
    CloseOutput();
  }
  if (pchFileName != NULL) {
    free(pchFileName);
  }
}


x86 assembly (clang, -O0):
<ParseDumpPalette>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
lea    0xe5e(%rip),%rdi
call   1070 <WGetId@plt>
mov    %eax,-0xc(%rbp)
lea    0xe5f(%rip),%rdi
call   1090 <PchGetString@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11df <ParseDumpPalette+0x4f>
mov    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11f0 <ParseDumpPalette+0x60>
lea    0xe3b(%rip),%rdi
call   1040 <ErrorLine@plt>
jmp    12c3 <ParseDumpPalette+0x133>
mov    -0xc(%rbp),%esi
lea    0xe46(%rip),%rdi
call   10b0 <OpenOutput@plt>
mov    -0x8(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
lea    -0xc14(%rbp),%rdx
call   1060 <ParsePaletteFile@plt>
movl   $0x0,-0xc18(%rbp)
mov    -0xc18(%rbp),%eax
cmp    -0xc14(%rbp),%eax
jge    12bc <ParseDumpPalette+0x12c>
lea    -0xc18(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
movslq -0xc18(%rbp),%rax
lea    -0xc10(%rbp),%rdi
imul   $0xc,%rax,%rax
add    %rax,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
movslq -0xc18(%rbp),%rax
lea    -0xc10(%rbp),%rdi
imul   $0xc,%rax,%rax
add    %rax,%rdi
add    $0x4,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
movslq -0xc18(%rbp),%rax
lea    -0xc10(%rbp),%rdi
imul   $0xc,%rax,%rax
add    %rax,%rdi
add    $0x8,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
mov    -0xc18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc18(%rbp)
jmp    1220 <ParseDumpPalette+0x90>
mov    $0x0,%al
call   1050 <CloseOutput@plt>
cmpq   $0x0,-0x8(%rbp)
je     12d7 <ParseDumpPalette+0x147>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseDumpPalette>:
push   %r14
push   %rbx
sub    $0xc18,%rsp
lea    0xe5f(%rip),%rdi
call   1070 <WGetId@plt>
mov    %eax,%ebx
lea    0xe61(%rip),%rdi
call   1090 <PchGetString@plt>
mov    %rax,%r14
test   %rax,%rax
je     128d <ParseDumpPalette+0xfd>
lea    0xe7d(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     128d <ParseDumpPalette+0xfd>
lea    0xe61(%rip),%rdi
mov    %ebx,%esi
call   10b0 <OpenOutput@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1060 <ParsePaletteFile@plt>
movl   $0x0,0x8(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    127f <ParseDumpPalette+0xef>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
movslq 0x8(%rsp),%rax
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,4),%rdi
add    $0x10,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
movslq 0x8(%rsp),%rax
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,4),%rdi
add    $0x14,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
movslq 0x8(%rsp),%rax
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,4),%rdi
add    $0x18,%rdi
mov    $0x1,%esi
call   10a0 <DumpBytes@plt>
mov    0x8(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x8(%rsp)
cmp    0xc(%rsp),%eax
jl     1210 <ParseDumpPalette+0x80>
xor    %eax,%eax
call   1050 <CloseOutput@plt>
test   %r14,%r14
jne    129e <ParseDumpPalette+0x10e>
jmp    12a6 <ParseDumpPalette+0x116>
lea    0xd8d(%rip),%rdi
call   1040 <ErrorLine@plt>
test   %r14,%r14
je     12a6 <ParseDumpPalette+0x116>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0xc18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Data ResourceId\00"
@.str.1 = [17 x i8] c"Palette Filename\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [31 x i8] c"Empty or no file name provided\00"
@.str.4 = [5 x i8] c"PALT\00"
define void @ParseDumpPalette() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [256 x [3 x i32]]
%4 = alloca i32
%5 = alloca i32
%6 = call i32 @WGetId(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %2
%7 = call i8* @PchGetString(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = load i8*, i8** %1
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10, %0
%15 = call i32 @ErrorLine(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %49
16: ; preds = %10
%17 = load i32, i32* %2
%18 = call i32 @OpenOutput(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %1
%20 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %3, i64 0, i64 0
%21 = bitcast [3 x i32]* %20 to i32**
%22 = call i32 @ParsePaletteFile(i8* %19, i32** %21, i32* %4)
store i32 0, i32* %5
br label %23
23: ; preds = %44, %16
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %47
27: ; preds = %23
%28 = call i32 @DumpBytes(i32* %5, i32 1)
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %3, i64 0, i64 %30
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %31, i64 0, i64 0
%33 = call i32 @DumpBytes(i32* %32, i32 1)
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %3, i64 0, i64 %35
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %36, i64 0, i64 1
%38 = call i32 @DumpBytes(i32* %37, i32 1)
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %3, i64 0, i64 %40
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %41, i64 0, i64 2
%43 = call i32 @DumpBytes(i32* %42, i32 1)
br label %44
44: ; preds = %27
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %23
47: ; preds = %23
%48 = call i32 (...) @CloseOutput()
br label %49
49: ; preds = %47, %14
%50 = load i8*, i8** %1
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i8*, i8** %1
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %52, %49
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Data ResourceId\00"
@.str.1 = [17 x i8] c"Palette Filename\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [31 x i8] c"Empty or no file name provided\00"
@.str.4 = [5 x i8] c"PALT\00"
define void @ParseDumpPalette() {
%1 = alloca [256 x [3 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @WGetId(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @PchGetString(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7, %0
%11 = tail call i32 @ErrorLine(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %41
12: ; preds = %7
%13 = bitcast [256 x [3 x i32]]* %1 to i8*
%14 = bitcast i32* %2 to i8*
%15 = bitcast i32* %3 to i8*
%16 = tail call i32 @OpenOutput(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %4)
%17 = bitcast [256 x [3 x i32]]* %1 to i32**
%18 = call i32 @ParsePaletteFile(i8* %5, i32** %17, i32* %2)
store i32 0, i32* %3
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %12, %21
%22 = call i32 @DumpBytes(i32* %3, i32 1)
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %1, i64 0, i64 %24, i64 0
%26 = call i32 @DumpBytes(i32* %25, i32 1)
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %1, i64 0, i64 %28, i64 1
%30 = call i32 @DumpBytes(i32* %29, i32 1)
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x [3 x i32]], [256 x [3 x i32]]* %1, i64 0, i64 %32, i64 2
%34 = call i32 @DumpBytes(i32* %33, i32 1)
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
%37 = load i32, i32* %2
%38 = icmp slt i32 %36, %37
br i1 %38, label %21, label %39
39: ; preds = %21, %12
%40 = call i32 (...) @CloseOutput()
br label %41
41: ; preds = %39, %10
br i1 %6, label %44, label %42
42: ; preds = %41
%43 = call i32 @free(i8* %5)
br label %44
44: ; preds = %42, %41
ret void
}