#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 convert_bgr2rgb(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int i, r, g, b, rgb, bgr;
  fprintf(stdout, "; 15-color BGR palette\n");
  for (i = 0; i < 256; i++) {
    if (i % 4 == 0) {
      fprintf(stdout, "; palette %d?\n", i / 4);
    }
    if (i % 4 == 3) {
      r = ((i / 4) & 1) ? 0 : 0xff;
      g = ((i / 4) & 2) ? 0 : 0xff;
      b = ((i / 4) & 4) ? 0 : 0xff;
      rgb = r << 16 | g << 8 | b;
      bgr = convert_bgr2rgb(rgb);
      fprintf(stdout, ".word $%04x\t; %06x\n", bgr, rgb);
    } else {
      fprintf(stdout, ".word $0000\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    0xeba(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    1278 <main+0x158>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1199 <main+0x79>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jne    124e <main+0x12e>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
and    $0x1,%edx
mov    $0xff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
and    $0x2,%edx
mov    $0xff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
and    $0x4,%edx
mov    $0xff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x10,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <convert_bgr2rgb@plt>
mov    %eax,-0x28(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1265 <main+0x145>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    126a <main+0x14a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <main+0x34>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2eae(%rip),%rbx
mov    (%rbx),%edi
lea    0xec5(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xede(%rip),%r14
lea    0xec8(%rip),%r15
lea    0xee4(%rip),%r12
xor    %r13d,%r13d
jmp    1179 <main+0x59>
nopl   0x0(%rax)
mov    (%rbx),%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r13d
cmp    $0x100,%r13d
je     11f3 <main+0xd3>
mov    %r13d,%eax
and    $0x3,%eax
cmp    $0x3,%eax
je     11a0 <main+0x80>
test   %eax,%eax
jne    1160 <main+0x40>
mov    (%rbx),%edi
mov    %r13d,%edx
shr    $0x2,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1160 <main+0x40>
nopl   0x0(%rax)
test   $0x4,%r13b
mov    $0x0,%eax
mov    $0xff0000,%ecx
cmove  %ecx,%eax
test   $0x8,%r13b
mov    $0x0,%ebp
mov    $0xff00,%ecx
cmove  %ecx,%ebp
test   $0x10,%r13b
mov    $0x0,%ecx
mov    $0xff,%edx
cmove  %edx,%ecx
or     %eax,%ebp
or     %ecx,%ebp
mov    %ebp,%edi
call   1030 <convert_bgr2rgb@plt>
mov    (%rbx),%edi
mov    %r14,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    116c <main+0x4c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [24 x i8] c"; 15-color BGR palette\0A\00"
@.str.1 = [15 x i8] c"; palette %d?\0A\00"
@.str.2 = [20 x i8] c".word $%04x\09; %06x\0A\00"
@.str.3 = [13 x i8] c".word $0000\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @stdout
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %14
14: ; preds = %66, %2
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 256
br i1 %16, label %17, label %69
17: ; preds = %14
%18 = load i32, i32* %6
%19 = srem i32 %18, 4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stdout
%23 = load i32, i32* %6
%24 = sdiv i32 %23, 4
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %21, %17
%27 = load i32, i32* %6
%28 = srem i32 %27, 4
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %62
30: ; preds = %26
%31 = load i32, i32* %6
%32 = sdiv i32 %31, 4
%33 = and i32 %32, 1
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 0, i32 255
store i32 %36, i32* %7
%37 = load i32, i32* %6
%38 = sdiv i32 %37, 4
%39 = and i32 %38, 2
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 0, i32 255
store i32 %42, i32* %8
%43 = load i32, i32* %6
%44 = sdiv i32 %43, 4
%45 = and i32 %44, 4
%46 = icmp ne i32 %45, 0
%47 = zext i1 %46 to i64
%48 = select i1 %46, i32 0, i32 255
store i32 %48, i32* %9
%49 = load i32, i32* %7
%50 = shl i32 %49, 16
%51 = load i32, i32* %8
%52 = shl i32 %51, 8
%53 = or i32 %50, %52
%54 = load i32, i32* %9
%55 = or i32 %53, %54
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = call i32 @convert_bgr2rgb(i32 %56)
store i32 %57, i32* %11
%58 = load i32, i32* @stdout
%59 = load i32, i32* %11
%60 = load i32, i32* %10
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %60)
br label %65
62: ; preds = %26
%63 = load i32, i32* @stdout
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %62, %30
br label %66
66: ; preds = %65
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %14
69: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [24 x i8] c"; 15-color BGR palette\0A\00"
@.str.1 = [15 x i8] c"; palette %d?\0A\00"
@.str.2 = [20 x i8] c".word $%04x\09; %06x\0A\00"
@.str.3 = [13 x i8] c".word $0000\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %2, %30
%6 = phi i32 [ 0, %2 ], [ %31, %30 ]
%7 = and i32 %6, 3
switch i32 %7, label %27 [
i32 0, label %8
i32 3, label %12
]
8: ; preds = %5
%9 = load i32, i32* @stdout
%10 = lshr i32 %6, 2
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %27
12: ; preds = %5
%13 = and i32 %6, 4
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 16711680, i32 0
%16 = and i32 %6, 8
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 65280, i32 0
%19 = and i32 %6, 16
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 255, i32 0
%22 = or i32 %15, %18
%23 = or i32 %22, %21
%24 = tail call i32 @convert_bgr2rgb(i32 %23)
%25 = load i32, i32* @stdout
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %23)
br label %30
27: ; preds = %8, %5
%28 = load i32, i32* @stdout
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %12, %27
%31 = add nuw nsw i32 %6, 1
%32 = icmp eq i32 %31, 256
br i1 %32, label %33, label %5
33: ; preds = %30
ret i32 0
}