#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(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, char, char, char);
int main(void) {
  char pal[768];
  FILE *file;
  int i;
  file = fopen("../our.pal", "rb");
  fread(pal, 1, 768, file);
  for (i = 0; i < 256; i++) {
    printf("color %d: %d %d %d\n", i, pal[i * 3], pal[i * 3 + 1],
           pal[i * 3 + 2]);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x318(%rbp)
lea    -0x310(%rbp),%rdi
mov    -0x318(%rbp),%rcx
mov    $0x1,%esi
mov    $0x300,%edx
call   1030 <fread@plt>
movl   $0x0,-0x31c(%rbp)
cmpl   $0x100,-0x31c(%rbp)
jge    1207 <main+0xc7>
mov    -0x31c(%rbp),%esi
imul   $0x3,-0x31c(%rbp),%eax
cltq
mov    -0x310(%rbp,%rax,1),%dl
imul   $0x3,-0x31c(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x310(%rbp,%rax,1),%cl
imul   $0x3,-0x31c(%rbp),%eax
add    $0x2,%eax
cltq
lea    0xe2f(%rip),%rdi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl -0x310(%rbp,%rax,1),%r8d
ff ff
call   1050 <printf@plt>
mov    -0x31c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x31c(%rbp)
jmp    1193 <main+0x53>
mov    -0x318(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x308,%rsp
lea    0xeab(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x300,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
lea    0x2(%rsp),%rbx
xor    %r12d,%r12d
lea    0xe86(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%edx
movsbl -0x1(%rbx),%ecx
movsbl (%rbx),%r8d
mov    %r15,%rdi
mov    %r12d,%esi
call   1050 <printf@plt>
add    $0x1,%r12
add    $0x3,%rbx
cmp    $0x100,%r12
jne    1190 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x308,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"../our.pal\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"color %d: %d %d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [768 x i8]
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = getelementptr inbounds [768 x i8], [768 x i8]* %2, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32 @fread(i8* %6, i32 1, i32 768, i32* %7)
store i32 0, i32* %4
br label %9
9: ; preds = %32, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 256
br i1 %11, label %12, label %35
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [768 x i8], [768 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = load i32, i32* %4
%20 = mul nsw i32 %19, 3
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [768 x i8], [768 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i32, i32* %4
%26 = mul nsw i32 %25, 3
%27 = add nsw i32 %26, 2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [768 x i8], [768 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %13, i8 signext %18, i8 signext %24, i8 signext %30)
br label %32
32: ; preds = %12
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %9
35: ; preds = %9
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [11 x i8] c"../our.pal\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"color %d: %d %d %d\0A\00"
define i32 @main() {
%1 = alloca [768 x i8]
%2 = getelementptr inbounds [768 x i8], [768 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @fread(i8* %2, i32 1, i32 768, i32* %3)
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %18, %5 ]
%7 = mul nuw nsw i64 %6, 3
%8 = getelementptr inbounds [768 x i8], [768 x i8]* %1, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = add nuw nsw i64 %7, 1
%11 = getelementptr inbounds [768 x i8], [768 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = add nuw nsw i64 %7, 2
%14 = getelementptr inbounds [768 x i8], [768 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = trunc i64 %6 to i32
%17 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8 signext %9, i8 signext %12, i8 signext %15)
%18 = add nuw nsw i64 %6, 1
%19 = icmp eq i64 %18, 256
br i1 %19, label %20, label %5
20: ; preds = %5
%21 = tail call i32 @fclose(i32* %3)
ret i32 0
}