#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 LoadEFlags();
int /*<<< orphan*/ OpCLI();
int /*<<< orphan*/ OpOut8(int, unsigned char);
int /*<<< orphan*/ StoreEFlags(int);
void SetPalette(int start, int end, unsigned char *rgb) {
  int i, eflags;
  eflags = LoadEFlags();
  OpCLI();
  OpOut8(0x03c8, start);
  for (i = start; i <= end; i++) {
    OpOut8(0x03c9, rgb[0] / 4);
    OpOut8(0x03c9, rgb[1] / 4);
    OpOut8(0x03c9, rgb[2] / 4);
    rgb += 3;
  }
  StoreEFlags(eflags);
  return;
}


x86 assembly (clang, -O0):
<SetPalette>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x0,%al
call   1050 <LoadEFlags@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <OpCLI@plt>
mov    -0x4(%rbp),%eax
mov    $0x3c8,%edi
movzbl %al,%esi
call   1040 <OpOut8@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f5 <SetPalette+0xb5>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x3c9,%edi
movzbl %al,%esi
call   1040 <OpOut8@plt>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x3c9,%edi
movzbl %al,%esi
call   1040 <OpOut8@plt>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x3c9,%edi
movzbl %al,%esi
call   1040 <OpOut8@plt>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <SetPalette+0x39>
mov    -0x18(%rbp),%edi
call   1060 <StoreEFlags@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPalette>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
xor    %eax,%eax
call   1050 <LoadEFlags@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <OpCLI@plt>
movzbl %r15b,%esi
mov    $0x3c8,%edi
call   1040 <OpOut8@plt>
cmp    %ebp,%r15d
jg     11c4 <SetPalette+0x84>
sub    %r15d,%ebp
add    $0x1,%ebp
nopl   0x0(%rax)
movzbl (%rbx),%eax
shr    $0x2,%al
movzbl %al,%esi
mov    $0x3c9,%edi
call   1040 <OpOut8@plt>
movzbl 0x1(%rbx),%eax
shr    $0x2,%al
movzbl %al,%esi
mov    $0x3c9,%edi
call   1040 <OpOut8@plt>
movzbl 0x2(%rbx),%eax
shr    $0x2,%al
movzbl %al,%esi
mov    $0x3c9,%edi
call   1040 <OpOut8@plt>
add    $0x3,%rbx
add    $0xffffffff,%ebp
jne    1180 <SetPalette+0x40>
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <StoreEFlags@plt>

LLVM IR (-O0):
define void @SetPalette(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = call i32 (...) @LoadEFlags()
store i32 %9, i32* %8
%10 = call i32 (...) @OpCLI()
%11 = load i32, i32* %4
%12 = trunc i32 %11 to i8
%13 = call i32 @OpOut8(i32 968, i8 zeroext %12)
%14 = load i32, i32* %4
store i32 %14, i32* %7
br label %15
15: ; preds = %43, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %5
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %46
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = sdiv i32 %23, 4
%25 = trunc i32 %24 to i8
%26 = call i32 @OpOut8(i32 969, i8 zeroext %25)
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = sdiv i32 %30, 4
%32 = trunc i32 %31 to i8
%33 = call i32 @OpOut8(i32 969, i8 zeroext %32)
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = sdiv i32 %37, 4
%39 = trunc i32 %38 to i8
%40 = call i32 @OpOut8(i32 969, i8 zeroext %39)
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 3
store i8* %42, i8** %6
br label %43
43: ; preds = %19
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %15
46: ; preds = %15
%47 = load i32, i32* %8
%48 = call i32 @StoreEFlags(i32 %47)
ret void
}

LLVM IR (-O2):
define void @SetPalette(i32 %0, i32 %1, i8* nocapture %2) {
%4 = tail call i32 (...) @LoadEFlags()
%5 = tail call i32 (...) @OpCLI()
%6 = trunc i32 %0 to i8
%7 = tail call i32 @OpOut8(i32 968, i8 zeroext %6)
%8 = icmp sgt i32 %0, %1
br i1 %8, label %26, label %9
9: ; preds = %3, %9
%10 = phi i8* [ %23, %9 ], [ %2, %3 ]
%11 = phi i32 [ %24, %9 ], [ %0, %3 ]
%12 = load i8, i8* %10
%13 = lshr i8 %12, 2
%14 = tail call i32 @OpOut8(i32 969, i8 zeroext %13)
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = load i8, i8* %15
%17 = lshr i8 %16, 2
%18 = tail call i32 @OpOut8(i32 969, i8 zeroext %17)
%19 = getelementptr inbounds i8, i8* %10, i64 2
%20 = load i8, i8* %19
%21 = lshr i8 %20, 2
%22 = tail call i32 @OpOut8(i32 969, i8 zeroext %21)
%23 = getelementptr inbounds i8, i8* %10, i64 3
%24 = add i32 %11, 1
%25 = icmp eq i32 %11, %1
br i1 %25, label %26, label %9
26: ; preds = %9, %3
%27 = tail call i32 @StoreEFlags(i32 %4)
ret void
}