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


x86 assembly (clang, -O0):
<gl_setpalettecolors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    11a3 <gl_setpalettecolors+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1e(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1f(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1d(%rbp),%cl
mov    -0x1e(%rbp),%al
movzbl %cl,%esi
movzbl %al,%edx
movzbl -0x1f(%rbp),%ecx
call   1030 <vga_setpalette@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <gl_setpalettecolors+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gl_setpalettecolors>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    114e <gl_setpalettecolors+0x3e>
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
add    %edi,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx),%esi
movzbl 0x1(%rbx),%edx
movzbl 0x2(%rbx),%ecx
mov    %ebp,%edi
call   1030 <vga_setpalette@plt>
add    $0x1,%ebp
add    $0x3,%rbx
cmp    %r14d,%ebp
jl     1130 <gl_setpalettecolors+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @gl_setpalettecolors(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
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 i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %7
%23 = load i8, i8* %21
store i8 %23, i8* %9
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
%26 = load i8, i8* %24
store i8 %26, i8* %10
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %7
%29 = load i8, i8* %27
store i8 %29, i8* %11
%30 = load i32, i32* %8
%31 = load i8, i8* %9
%32 = load i8, i8* %10
%33 = load i8, i8* %11
%34 = call i32 @vga_setpalette(i32 %30, i8 zeroext %31, i8 zeroext %32, i8 zeroext %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_setpalettecolors(i32 %0, i32 %1, i8* nocapture %2) {
%4 = add nsw i32 %1, %0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %3, %6
%7 = phi i8* [ %13, %6 ], [ %2, %3 ]
%8 = phi i32 [ %16, %6 ], [ %0, %3 ]
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = load i8, i8* %7
%11 = getelementptr inbounds i8, i8* %7, i64 2
%12 = load i8, i8* %9
%13 = getelementptr inbounds i8, i8* %7, i64 3
%14 = load i8, i8* %11
%15 = tail call i32 @vga_setpalette(i32 %8, i8 zeroext %10, i8 zeroext %12, i8 zeroext %14)
%16 = add nsw i32 %8, 1
%17 = icmp slt i32 %16, %4
br i1 %17, label %6, label %18
18: ; preds = %6, %3
ret void
}