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

/* Variables and functions */
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int ReadColorMap(FILE *fd, int number, unsigned char (*buffer)[256]) {
  int i;
  unsigned char rgb[3];
  for (i = 0; i < number; ++i) {
    if (!(fread(rgb, sizeof(rgb), 1, fd) != 0)) {
      return 1;
    }
    buffer[0][i] = rgb[0];
    buffer[1][i] = rgb[1];
    buffer[2][i] = rgb[2];
  }
  return 0;
}


x86 assembly (clang, -O0):
<ReadColorMap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <ReadColorMap+0x93>
lea    -0x27(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    1163 <ReadColorMap+0x53>
movl   $0x1,-0x4(%rbp)
jmp    11aa <ReadColorMap+0x9a>
mov    -0x27(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x26(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,0x100(%rax,%rcx,1)
mov    -0x25(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,0x200(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112a <ReadColorMap+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadColorMap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1187 <ReadColorMap+0x77>
mov    %rdx,%r13
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0x5(%rsp),%r15
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1189 <ReadColorMap+0x79>
movzbl 0x5(%rsp),%eax
mov    %al,0x0(%r13,%rbx,1)
movzbl 0x6(%rsp),%eax
mov    %al,0x100(%r13,%rbx,1)
movzbl 0x7(%rsp),%eax
mov    %al,0x200(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <ReadColorMap+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ReadColorMap(i32* %0, i32 %1, [256 x i8]* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [256 x i8]*
%8 = alloca i32
%9 = alloca [3 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store [256 x i8]* %2, [256 x i8]** %7
store i32 0, i32* %8
br label %10
10: ; preds = %42, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i64 @fread(i8* %15, i32 3, i32 1, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %14
store i32 1, i32* %4
br label %46
20: ; preds = %14
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%22 = load i8, i8* %21
%23 = load [256 x i8]*, [256 x i8]** %7
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i64 0
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %24, i64 0, i64 %26
store i8 %22, i8* %27
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
%29 = load i8, i8* %28
%30 = load [256 x i8]*, [256 x i8]** %7
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %30, i64 1
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %31, i64 0, i64 %33
store i8 %29, i8* %34
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 2
%36 = load i8, i8* %35
%37 = load [256 x i8]*, [256 x i8]** %7
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %37, i64 2
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %38, i64 0, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %20
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %10
45: ; preds = %10
store i32 0, i32* %4
br label %46
46: ; preds = %45, %19
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @ReadColorMap(i32* nocapture %0, i32 %1, [256 x i8]* nocapture writeonly %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %24
7: ; preds = %3
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %7, %15
%12 = phi i64 [ 0, %7 ], [ %22, %15 ]
%13 = call i64 @fread(i8* %5, i32 3, i32 1, i32* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %11
%16 = load i8, i8* %5
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %12
store i8 %16, i8* %17
%18 = load i8, i8* %8
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 1, i64 %12
store i8 %18, i8* %19
%20 = load i8, i8* %9
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 2, i64 %12
store i8 %20, i8* %21
%22 = add nuw nsw i64 %12, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %24, label %11
24: ; preds = %11, %15, %3
%25 = phi i32 [ 0, %3 ], [ 0, %15 ], [ 1, %11 ]
ret i32 %25
}