#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*/ SetColor(int, unsigned char, unsigned char, unsigned char);
void SetPalette(unsigned char *p) {
  int i;
  for (i = 0; i < 256; i++)
    SetColor(i, p[i * 3 + 0], p[i * 3 + 1], p[i * 3 + 2]);
}


x86 assembly (clang, -O0):
<SetPalette>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    1182 <SetPalette+0x72>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%sil
mov    -0x8(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movzbl %sil,%esi
movzbl %dl,%edx
movzbl (%rax,%rcx,1),%ecx
call   1030 <SetColor@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <SetPalette+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPalette>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0x2,%rbx
xor    %r14d,%r14d
xchg   %ax,%ax
movzbl -0x2(%rbx),%esi
movzbl -0x1(%rbx),%edx
movzbl (%rbx),%ecx
mov    %r14d,%edi
call   1030 <SetColor@plt>
add    $0x1,%r14
add    $0x3,%rbx
cmp    $0x100,%r14
jne    1120 <SetPalette+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @SetPalette(i8* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %15, %2 ]
%4 = mul nuw nsw i64 %3, 3
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = add nuw nsw i64 %4, 1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = add nuw nsw i64 %4, 2
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = trunc i64 %3 to i32
%14 = tail call i32 @SetColor(i32 %13, i8 zeroext %6, i8 zeroext %9, i8 zeroext %12)
%15 = add nuw nsw i64 %3, 1
%16 = icmp eq i64 %15, 256
br i1 %16, label %17, label %2
17: ; preds = %2
ret void
}