#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*/ vga_getpalette(int, int *, int *, int *);
void gl_getpalettecolors(int s, int n, void *_dp) {
  unsigned char *dp = _dp;
  int i;
  for (i = s; i < s + n; i++) {
    int r, g, b;
    vga_getpalette(i, &r, &g, &b);
    *(dp++) = (unsigned char)r;
    *(dp++) = (unsigned char)g;
    *(dp++) = (unsigned char)b;
  }
}


x86 assembly (clang, -O0):
<gl_getpalettecolors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    11a5 <gl_getpalettecolors+0x95>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <vga_getpalette@plt>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <gl_getpalettecolors+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gl_getpalettecolors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    1173 <gl_getpalettecolors+0x63>
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
add    %edi,%r14d
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1030 <vga_getpalette@plt>
movzbl 0x14(%rsp),%eax
mov    %al,(%rbx)
movzbl 0x10(%rsp),%eax
mov    %al,0x1(%rbx)
movzbl 0xc(%rsp),%eax
mov    %al,0x2(%rbx)
add    $0x1,%ebp
add    $0x3,%rbx
cmp    %r14d,%ebp
jl     1140 <gl_getpalettecolors+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gl_getpalettecolors(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
store i8* %12, i8** %7
%13 = load i32, i32* %4
store i32 %13, i32* %8
br label %14
14: ; preds = %35, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = add nsw i32 %16, %17
%19 = icmp slt i32 %15, %18
br i1 %19, label %20, label %38
20: ; preds = %14
%21 = load i32, i32* %8
%22 = call i32 @vga_getpalette(i32 %21, i32* %9, i32* %10, i32* %11)
%23 = load i32, i32* %9
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
store i8 %24, i8* %25
%27 = load i32, i32* %10
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %7
store i8 %28, i8* %29
%31 = load i32, i32* %11
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
store i8 %32, i8* %33
br label %35
35: ; preds = %20
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %14
38: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @gl_getpalettecolors(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = add nsw i32 %1, %0
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %28
9: ; preds = %3
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
br label %13
13: ; preds = %9, %13
%14 = phi i32 [ %0, %9 ], [ %26, %13 ]
%15 = phi i8* [ %2, %9 ], [ %25, %13 ]
%16 = call i32 @vga_getpalette(i32 %14, i32* %4, i32* %5, i32* %6)
%17 = load i32, i32* %4
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %18, i8* %15
%20 = load i32, i32* %5
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %15, i64 2
store i8 %21, i8* %19
%23 = load i32, i32* %6
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds i8, i8* %15, i64 3
store i8 %24, i8* %22
%26 = add nsw i32 %14, 1
%27 = icmp slt i32 %26, %7
br i1 %27, label %13, label %28
28: ; preds = %13, %3
ret void
}