#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
unsigned char *read256BMPpallet(char *filename) {
  FILE *f = fopen(filename, "rb");
  unsigned char info[54];
  fread(info, sizeof(unsigned char), 54, f);
  unsigned char pallet[1024];
  fread(pallet, sizeof(unsigned char), 1024, f);
  fclose(f);
  unsigned char *cpallet = malloc(sizeof(unsigned char) * 768);
  int i;
  for (i = 0; i < 1024; i += 4) {
    cpallet[i * 3 / 4] = pallet[i + 2];
    cpallet[i * 3 / 4 + 1] = pallet[i + 1];
    cpallet[i * 3 / 4 + 2] = pallet[i];
  }
  return cpallet;
  return NULL;
}


x86 assembly (clang, -O0):
<read256BMPpallet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x36,%edx
call   1030 <fread@plt>
lea    -0x450(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x300,%edi
call   1050 <malloc@plt>
mov    %rax,-0x458(%rbp)
movl   $0x0,-0x45c(%rbp)
cmpl   $0x400,-0x45c(%rbp)
jge    12bc <read256BMPpallet+0x17c>
mov    -0x45c(%rbp),%eax
add    $0x2,%eax
cltq
mov    -0x450(%rbp,%rax,1),%al
mov    %al,-0x489(%rbp)
mov    -0x458(%rbp),%rax
mov    %rax,-0x488(%rbp)
imul   $0x3,-0x45c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x489(%rbp),%dl
mov    %eax,%ecx
mov    -0x488(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x45c(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x450(%rbp,%rax,1),%al
mov    %al,-0x479(%rbp)
mov    -0x458(%rbp),%rax
mov    %rax,-0x478(%rbp)
imul   $0x3,-0x45c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x479(%rbp),%dl
mov    %eax,%ecx
mov    -0x478(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x45c(%rbp),%rax
mov    -0x450(%rbp,%rax,1),%al
mov    %al,-0x469(%rbp)
mov    -0x458(%rbp),%rax
mov    %rax,-0x468(%rbp)
imul   $0x3,-0x45c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x469(%rbp),%dl
mov    %eax,%ecx
mov    -0x468(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x45c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x45c(%rbp)
jmp    11b8 <read256BMPpallet+0x78>
mov    -0x458(%rbp),%rax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read256BMPpallet>:
push   %rbx
sub    $0x440,%rsp
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x36,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
lea    0x40(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x300,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
add    $0x2,%rcx
mov    $0xfffffffffffffffc,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x46(%rsp,%rdx,1),%ebx
mov    %bl,-0x2(%rcx)
movzbl 0x45(%rsp,%rdx,1),%ebx
mov    %bl,-0x1(%rcx)
movzbl 0x44(%rsp,%rdx,1),%ebx
mov    %bl,(%rcx)
add    $0x4,%rdx
add    $0x3,%rcx
cmp    $0x3fc,%rdx
jb     11b0 <read256BMPpallet+0x70>
add    $0x440,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i8* @read256BMPpallet(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [54 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = getelementptr inbounds [54 x i8], [54 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32 @fread(i8* %10, i32 1, i32 54, i32* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32 @fread(i8* %13, i32 1, i32 1024, i32* %14)
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
%18 = call i8* @malloc(i32 768)
store i8* %18, i8** %6
store i32 0, i32* %7
br label %19
19: ; preds = %57, %1
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 1024
br i1 %21, label %22, label %60
22: ; preds = %19
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = mul nsw i32 %29, 3
%31 = sdiv i32 %30, 4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
store i8 %27, i8* %33
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %6
%40 = load i32, i32* %7
%41 = mul nsw i32 %40, 3
%42 = sdiv i32 %41, 4
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %39, i64 %44
store i8 %38, i8* %45
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = load i8*, i8** %6
%51 = load i32, i32* %7
%52 = mul nsw i32 %51, 3
%53 = sdiv i32 %52, 4
%54 = add nsw i32 %53, 2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %50, i64 %55
store i8 %49, i8* %56
br label %57
57: ; preds = %22
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 4
store i32 %59, i32* %7
br label %19
60: ; preds = %19
%61 = load i8*, i8** %6
ret i8* %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define noalias i8* @read256BMPpallet(i8* nocapture %0) {
%2 = alloca [54 x i8]
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [54 x i8], [54 x i8]* %2, i64 0, i64 0
%6 = call i32 @fread(i8* %5, i32 1, i32 54, i32* %4)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @fread(i8* %7, i32 1, i32 1024, i32* %4)
%9 = tail call i32 @fclose(i32* %4)
%10 = tail call dereferenceable_or_null(768) i8* @malloc(i32 768)
br label %11
11: ; preds = %1, %11
%12 = phi i64 [ 0, %1 ], [ %28, %11 ]
%13 = or i64 %12, 2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = mul nuw nsw i64 %12, 3
%17 = lshr exact i64 %16, 2
%18 = getelementptr inbounds i8, i8* %10, i64 %17
store i8 %15, i8* %18
%19 = or i64 %12, 1
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = add nuw nsw i64 %17, 1
%23 = getelementptr inbounds i8, i8* %10, i64 %22
store i8 %21, i8* %23
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %12
%25 = load i8, i8* %24
%26 = add nuw nsw i64 %17, 2
%27 = getelementptr inbounds i8, i8* %10, i64 %26
store i8 %25, i8* %27
%28 = add nuw nsw i64 %12, 4
%29 = icmp ult i64 %12, 1020
br i1 %29, label %11, label %30
30: ; preds = %11
ret i8* %10
}