#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 */
unsigned int *CreateCLUTarry(unsigned char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ stderr;
unsigned int *ReplaceCLUT(char *iname) {
  FILE *stream;
  unsigned char *raw_clut;
  unsigned int *new_clut;
  if ((stream = fopen(iname, "rb")) == NULL) {
    fprintf(stderr, "Err: Could not open input clut file %s.\n\n", iname);
    exit(1);
  }
  raw_clut = (char *)calloc(256, 3);
  fread(raw_clut, 256, 3, stream);
  fclose(stream);
  new_clut = CreateCLUTarry(raw_clut);
  free(raw_clut);
  return new_clut;
}


x86 assembly (clang, -O0):
<ReplaceCLUT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cd <ReplaceCLUT+0x4d>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x100,%edi
mov    $0x3,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <CreateCLUTarry@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReplaceCLUT>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e7 <ReplaceCLUT+0x67>
mov    %rax,%r15
mov    $0x100,%edi
mov    $0x3,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x100,%esi
mov    $0x3,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   10a0 <CreateCLUTarry@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"Err: Could not open input clut file %s.\0A\0A\00"
define i32* @ReplaceCLUT(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = call i64 @calloc(i32 256, i32 3)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = load i32*, i32** %3
%19 = call i32 @fread(i8* %17, i32 256, i32 3, i32* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %4
%23 = call i32* @CreateCLUTarry(i8* %22)
store i32* %23, i32** %5
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
%26 = load i32*, i32** %5
ret i32* %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"Err: Could not open input clut file %s.\0A\0A\00"
define i32* @ReplaceCLUT(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i64 @calloc(i32 256, i32 3)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @fread(i8* %10, i32 256, i32 3, i32* %2)
%12 = tail call i32 @fclose(i32* %2)
%13 = tail call i32* @CreateCLUTarry(i8* %10)
%14 = tail call i32 @free(i8* %10)
ret i32* %13
}