#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*/ decl(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *,
                        char *, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ outS(unsigned char *, int /*<<< orphan*/, int,
                        int /*<<< orphan*/ *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void outPalette(unsigned short *palette, int startInd, int palSize, FILE *fs,
                FILE *fh, char *id, int global) {
  char temp[2048];
  int size;
  size = (((64 - startInd) < (palSize)) ? (64 - startInd) : (palSize));
  strcpy(temp, id);
  strcat(temp, "_pal");
  decl(fs, fh, 0, temp, 2, 0);
  outS((unsigned char *)palette, 0, size * 2, fs, 2);
  fprintf(fs, "\n");
  decl(fs, fh, "Palette", id, 2, global);
  fprintf(fs, "    dc.w    %d, %d\n", startInd, size);
  fprintf(fs, "    dc.l    %s\n", temp);
  fprintf(fs, "\n");
}


x86 assembly (clang, -O0):
<outPalette>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    $0x40,%eax
sub    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1198 <outPalette+0x48>
mov    $0x40,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x838(%rbp)
jmp    11a1 <outPalette+0x51>
mov    -0x10(%rbp),%eax
mov    %eax,-0x838(%rbp)
mov    -0x838(%rbp),%eax
mov    %eax,-0x834(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x830(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x830(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
mov    $0x2,%r8d
xor    %r9d,%r9d
call   1040 <decl@plt>
mov    -0x8(%rbp),%rdi
mov    -0x834(%rbp),%edx
shl    $0x1,%edx
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
mov    $0x2,%r8d
call   1070 <outS@plt>
mov    -0x18(%rbp),%rdi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    0x10(%rbp),%r9d
lea    0xdcd(%rip),%rdx
mov    $0x2,%r8d
call   1040 <decl@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x834(%rbp),%ecx
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x830(%rbp),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outPalette>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %r9,%r12
mov    %r8,%r13
mov    %rcx,%rbx
mov    %esi,%r15d
mov    %rdi,0x8(%rsp)
mov    $0x40,%ebp
sub    %esi,%ebp
cmp    %edx,%ebp
cmovge %edx,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r9,%rsi
call   1030 <strcpy@plt>
lea    0xe5b(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x2,%r8d
xor    %r9d,%r9d
call   1040 <decl@plt>
lea    0x0(%rbp,%rbp,1),%edx
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rcx
mov    $0x2,%r8d
call   1080 <outS@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
lea    0xe12(%rip),%rdx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rcx
mov    $0x2,%r8d
mov    0x850(%rsp),%r9d
call   1040 <decl@plt>
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"_pal\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [8 x i8] c"Palette\00"
@.str.3 = [20 x i8] c" dc.w %d, %d\0A\00"
@.str.4 = [16 x i8] c" dc.l %s\0A\00"
define void @outPalette(i16* %0, i32 %1, i32 %2, i32* %3, i32* %4, i8* %5, i32 %6) {
%8 = alloca i16*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca [2048 x i8]
%16 = alloca i32
store i16* %0, i16** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%17 = load i32, i32* %9
%18 = sub nsw i32 64, %17
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %7
%22 = load i32, i32* %9
%23 = sub nsw i32 64, %22
br label %26
24: ; preds = %7
%25 = load i32, i32* %10
br label %26
26: ; preds = %24, %21
%27 = phi i32 [ %23, %21 ], [ %25, %24 ]
store i32 %27, i32* %16
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%29 = load i8*, i8** %13
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%33 = load i32*, i32** %11
%34 = load i32*, i32** %12
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%36 = call i32 @decl(i32* %33, i32* %34, i8* null, i8* %35, i32 2, i32 0)
%37 = load i16*, i16** %8
%38 = bitcast i16* %37 to i8*
%39 = load i32, i32* %16
%40 = mul nsw i32 %39, 2
%41 = load i32*, i32** %11
%42 = call i32 @outS(i8* %38, i32 0, i32 %40, i32* %41, i32 2)
%43 = load i32*, i32** %11
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32*, i32** %11
%46 = load i32*, i32** %12
%47 = load i8*, i8** %13
%48 = load i32, i32* %14
%49 = call i32 @decl(i32* %45, i32* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %47, i32 2, i32 %48)
%50 = load i32*, i32** %11
%51 = load i32, i32* %9
%52 = load i32, i32* %16
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %51, i32 %52)
%54 = load i32*, i32** %11
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load i32*, i32** %11
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"_pal\00"
@.str.2 = [8 x i8] c"Palette\00"
@.str.3 = [20 x i8] c" dc.w %d, %d\0A\00"
@.str.4 = [16 x i8] c" dc.l %s\0A\00"
define void @outPalette(i16* %0, i32 %1, i32 %2, i32* %3, i32* %4, i8* %5, i32 %6) {
%8 = alloca [2048 x i8]
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%10 = sub nsw i32 64, %1
%11 = icmp slt i32 %10, %2
%12 = select i1 %11, i32 %10, i32 %2
%13 = call i32 @strcpy(i8* %9, i8* %5)
%14 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @decl(i32* %3, i32* %4, i8* null, i8* %9, i32 2, i32 0)
%16 = bitcast i16* %0 to i8*
%17 = shl nsw i32 %12, 1
%18 = call i32 @outS(i8* %16, i32 0, i32 %17, i32* %3, i32 2)
%19 = call i32 @fputc(i32 10, i32* %3)
%20 = call i32 @decl(i32* %3, i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 2, i32 %6)
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %12)
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%23 = call i32 @fputc(i32 10, i32* %3)
ret void
}