#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 *gray) {
  int i;
  unsigned char rgb[3];
  int flag;
  flag = 1;
  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];
    flag &= (rgb[0] == rgb[1] && rgb[1] == rgb[2]);
  }
  *gray = flag;
  return 0;
}


x86 assembly (clang, -O0):
<readColorMap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e1 <readColorMap+0xd1>
lea    -0x2f(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    116e <readColorMap+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <readColorMap+0xe1>
mov    -0x2f(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2e(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,0x100(%rax,%rcx,1)
mov    -0x2d(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,0x200(%rax,%rcx,1)
movzbl -0x2f(%rbp),%ecx
movzbl -0x2e(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x35(%rbp)
jne    11c5 <readColorMap+0xb5>
movzbl -0x2e(%rbp),%eax
movzbl -0x2d(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
and    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1135 <readColorMap+0x25>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readColorMap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
mov    %rcx,0x10(%rsp)
jle    1196 <readColorMap+0x86>
mov    %rdx,%rbx
mov    %rdi,%rbp
mov    %esi,%r13d
xor    %r14d,%r14d
lea    0xd(%rsp),%r12
mov    $0x1,%r15d
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11a8 <readColorMap+0x98>
movzbl 0xd(%rsp),%eax
mov    %al,(%rbx,%r14,1)
movzbl 0xe(%rsp),%ecx
mov    %cl,0x100(%rbx,%r14,1)
movzbl 0xf(%rsp),%edx
mov    %dl,0x200(%rbx,%r14,1)
xor    %cl,%al
xor    %dl,%cl
xor    %edx,%edx
or     %al,%cl
sete   %dl
and    %edx,%r15d
add    $0x1,%r14
cmp    %r14,%r13
jne    1140 <readColorMap+0x30>
jmp    119c <readColorMap+0x8c>
mov    $0x1,%r15d
mov    0x10(%rsp),%rax
mov    %r15d,(%rax)
xor    %eax,%eax
jmp    11ad <readColorMap+0x9d>
mov    $0x1,%eax
add    $0x18,%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, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [256 x i8]*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [3 x i8]
%12 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store [256 x i8]* %2, [256 x i8]** %8
store i32* %3, i32** %9
store i32 1, i32* %12
store i32 0, i32* %10
br label %13
13: ; preds = %65, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %68
17: ; preds = %13
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i64 @fread(i8* %18, i32 3, i32 1, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %17
store i32 1, i32* %5
br label %71
23: ; preds = %17
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%25 = load i8, i8* %24
%26 = load [256 x i8]*, [256 x i8]** %8
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %26, i64 0
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %27, i64 0, i64 %29
store i8 %25, i8* %30
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 1
%32 = load i8, i8* %31
%33 = load [256 x i8]*, [256 x i8]** %8
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %33, i64 1
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %34, i64 0, i64 %36
store i8 %32, i8* %37
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 2
%39 = load i8, i8* %38
%40 = load [256 x i8]*, [256 x i8]** %8
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %40, i64 2
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %41, i64 0, i64 %43
store i8 %39, i8* %44
%45 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 1
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %47, %50
br i1 %51, label %52, label %60
52: ; preds = %23
%53 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 1
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 2
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp eq i32 %55, %58
br label %60
60: ; preds = %52, %23
%61 = phi i1 [ false, %23 ], [ %59, %52 ]
%62 = zext i1 %61 to i32
%63 = load i32, i32* %12
%64 = and i32 %63, %62
store i32 %64, i32* %12
br label %65
65: ; preds = %60
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %13
68: ; preds = %13
%69 = load i32, i32* %12
%70 = load i32*, i32** %9
store i32 %69, i32* %70
store i32 0, i32* %5
br label %71
71: ; preds = %68, %22
%72 = load i32, i32* %5
ret i32 %72
}

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