#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *, float *,
                          float *, float *);
int /*<<< orphan*/ printf(char *, int);
int read_cmap_from_file(char *fname, int n, int *rr, int *gg, int *bb) {
  float x, r[1000], g[1000], b[1000];
  int i = 0;
  int m;
  int j;
  FILE *fp;
  fp = fopen(fname, "r");
  if (fp == NULL)
    return 0;
  while (!feof(fp)) {
    fscanf(fp, "%g %g %g %g \n", &x, &r[i], &g[i], &b[i]);
    i++;
  }
  fclose(fp);
  m = i;
  printf(" read %d entries \n", m);
  for (i = 0; i < n; i++) {
    j = i * m / n;
    rr[i] = 256 * 255 * r[j];
    bb[i] = 256 * 255 * b[j];
    gg[i] = 256 * 255 * g[j];
  }
  return m;
}


x86 assembly (clang, -O0):
<read_cmap_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x2f24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x2f38(%rbp)
cmpq   $0x0,-0x2f38(%rbp)
jne    11a9 <read_cmap_from_file+0x59>
movl   $0x0,-0x4(%rbp)
jmp    132e <read_cmap_from_file+0x1de>
jmp    11ae <read_cmap_from_file+0x5e>
mov    -0x2f38(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cf <read_cmap_from_file+0x7f>
jmp    1239 <read_cmap_from_file+0xe9>
mov    -0x2f38(%rbp),%rdi
movslq -0x2f24(%rbp),%rax
lea    -0xfe0(%rbp),%rcx
shl    $0x2,%rax
add    %rax,%rcx
movslq -0x2f24(%rbp),%rax
lea    -0x1f80(%rbp),%r8
shl    $0x2,%rax
add    %rax,%r8
movslq -0x2f24(%rbp),%rax
lea    -0x2f20(%rbp),%r9
shl    $0x2,%rax
add    %rax,%r9
lea    0xdea(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x2f24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2f24(%rbp)
jmp    11ae <read_cmap_from_file+0x5e>
mov    -0x2f38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2f24(%rbp),%eax
mov    %eax,-0x2f28(%rbp)
mov    -0x2f28(%rbp),%esi
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x2f24(%rbp)
mov    -0x2f24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1325 <read_cmap_from_file+0x1d5>
mov    -0x2f24(%rbp),%eax
imul   -0x2f28(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x2f2c(%rbp)
movslq -0x2f2c(%rbp),%rax
movss  0xd5e(%rip),%xmm0
mulss  -0xfe0(%rbp,%rax,4),%xmm0
ff ff
cvttss2si %xmm0,%edx
mov    -0x20(%rbp),%rax
movslq -0x2f24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x2f2c(%rbp),%rax
movss  0xd34(%rip),%xmm0
mulss  -0x2f20(%rbp,%rax,4),%xmm0
ff ff
cvttss2si %xmm0,%edx
mov    -0x30(%rbp),%rax
movslq -0x2f24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x2f2c(%rbp),%rax
movss  0xd0a(%rip),%xmm0
mulss  -0x1f80(%rbp,%rax,4),%xmm0
ff ff
cvttss2si %xmm0,%edx
mov    -0x28(%rbp),%rax
movslq -0x2f24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2f24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2f24(%rbp)
jmp    126d <read_cmap_from_file+0x11d>
mov    -0x2f28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2f40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cmap_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2f08,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r13
mov    %esi,%ebp
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1280 <read_cmap_from_file+0x130>
mov    %rax,%rbx
mov    %ebp,0x4(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rax,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11f8 <read_cmap_from_file+0xa8>
lea    0x20(%rsp),%r12
lea    0xfc0(%rsp),%r14
lea    0x1f60(%rsp),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe3c(%rip),%rsi
lea    0x1c(%rsp),%rdx
mov    %r15,%rcx
mov    %r14,%r8
mov    %r12,%r9
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
add    $0x4,%r12
add    $0x4,%r14
add    $0x4,%r15
add    $0x1,%ebp
test   %eax,%eax
je     11c0 <read_cmap_from_file+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe0d(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1282 <read_cmap_from_file+0x132>
mov    %eax,%esi
xor    %ecx,%ecx
movss  0xdde(%rip),%xmm0
xor    %edi,%edi
mov    0x10(%rsp),%r8
mov    0x8(%rsp),%rbx
xchg   %ax,%ax
mov    %ecx,%eax
cltd
idiv   %esi
cltq
movss  0x1f60(%rsp,%rax,4),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%edx
mov    %edx,0x0(%r13,%rdi,4)
movss  0x20(%rsp,%rax,4),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%edx
mov    %edx,(%r8,%rdi,4)
movss  0xfc0(%rsp,%rax,4),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %eax,(%rbx,%rdi,4)
add    $0x1,%rdi
add    %ebp,%ecx
cmp    %rdi,%rsi
jne    1230 <read_cmap_from_file+0xe0>
jmp    1282 <read_cmap_from_file+0x132>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x2f08,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [14 x i8] c"%g %g %g %g \0A\00"
@.str.2 = [19 x i8] c" read %d entries \0A\00"
define i32 @read_cmap_from_file(i8* %0, i32 %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca float
%13 = alloca [1000 x float]
%14 = alloca [1000 x float]
%15 = alloca [1000 x float]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 0, i32* %16
%20 = load i8*, i8** %7
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %19
%22 = load i32*, i32** %19
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %5
store i32 0, i32* %6
br label %96
25: ; preds = %5
br label %26
26: ; preds = %31, %25
%27 = load i32*, i32** %19
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %45
31: ; preds = %26
%32 = load i32*, i32** %19
%33 = load i32, i32* %16
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [1000 x float], [1000 x float]* %13, i64 0, i64 %34
%36 = load i32, i32* %16
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1000 x float], [1000 x float]* %14, i64 0, i64 %37
%39 = load i32, i32* %16
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1000 x float], [1000 x float]* %15, i64 0, i64 %40
%42 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), float* %12, float* %35, float* %38, float* %41)
%43 = load i32, i32* %16
%44 = add nsw i32 %43, 1
store i32 %44, i32* %16
br label %26
45: ; preds = %26
%46 = load i32*, i32** %19
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %16
store i32 %48, i32* %17
%49 = load i32, i32* %17
%50 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %49)
store i32 0, i32* %16
br label %51
51: ; preds = %91, %45
%52 = load i32, i32* %16
%53 = load i32, i32* %8
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %94
55: ; preds = %51
%56 = load i32, i32* %16
%57 = load i32, i32* %17
%58 = mul nsw i32 %56, %57
%59 = load i32, i32* %8
%60 = sdiv i32 %58, %59
store i32 %60, i32* %18
%61 = load i32, i32* %18
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x float], [1000 x float]* %13, i64 0, i64 %62
%64 = load float, float* %63
%65 = fmul float 6.528000e+04, %64
%66 = fptosi float %65 to i32
%67 = load i32*, i32** %9
%68 = load i32, i32* %16
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
store i32 %66, i32* %70
%71 = load i32, i32* %18
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [1000 x float], [1000 x float]* %15, i64 0, i64 %72
%74 = load float, float* %73
%75 = fmul float 6.528000e+04, %74
%76 = fptosi float %75 to i32
%77 = load i32*, i32** %11
%78 = load i32, i32* %16
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 %76, i32* %80
%81 = load i32, i32* %18
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [1000 x float], [1000 x float]* %14, i64 0, i64 %82
%84 = load float, float* %83
%85 = fmul float 6.528000e+04, %84
%86 = fptosi float %85 to i32
%87 = load i32*, i32** %10
%88 = load i32, i32* %16
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
store i32 %86, i32* %90
br label %91
91: ; preds = %55
%92 = load i32, i32* %16
%93 = add nsw i32 %92, 1
store i32 %93, i32* %16
br label %51
94: ; preds = %51
%95 = load i32, i32* %17
store i32 %95, i32* %6
br label %96
96: ; preds = %94, %24
%97 = load i32, i32* %6
ret i32 %97
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [14 x i8] c"%g %g %g %g \0A\00"
@.str.2 = [19 x i8] c" read %d entries \0A\00"
define i32 @read_cmap_from_file(i8* nocapture %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = alloca float
%7 = alloca [1000 x float]
%8 = alloca [1000 x float]
%9 = alloca [1000 x float]
%10 = bitcast float* %6 to i8*
%11 = bitcast [1000 x float]* %7 to i8*
%12 = bitcast [1000 x float]* %8 to i8*
%13 = bitcast [1000 x float]* %9 to i8*
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %60, label %16
16: ; preds = %5
%17 = call i32 @feof(i32* %14)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %16, %19
%20 = phi i64 [ %25, %19 ], [ 0, %16 ]
%21 = getelementptr inbounds [1000 x float], [1000 x float]* %7, i64 0, i64 %20
%22 = getelementptr inbounds [1000 x float], [1000 x float]* %8, i64 0, i64 %20
%23 = getelementptr inbounds [1000 x float], [1000 x float]* %9, i64 0, i64 %20
%24 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), float* %6, float* %21, float* %22, float* %23)
%25 = add nuw i64 %20, 1
%26 = call i32 @feof(i32* %14)
%27 = icmp eq i32 %26, 0
br i1 %27, label %19, label %28
28: ; preds = %19
%29 = trunc i64 %25 to i32
br label %30
30: ; preds = %28, %16
%31 = phi i32 [ 0, %16 ], [ %29, %28 ]
%32 = call i32 @fclose(i32* %14)
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%34 = icmp sgt i32 %1, 0
br i1 %34, label %35, label %60
35: ; preds = %30
%36 = zext i32 %1 to i64
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %58, %37 ]
%39 = trunc i64 %38 to i32
%40 = mul i32 %31, %39
%41 = sdiv i32 %40, %1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x float], [1000 x float]* %7, i64 0, i64 %42
%44 = load float, float* %43
%45 = fmul float %44, 6.528000e+04
%46 = fptosi float %45 to i32
%47 = getelementptr inbounds i32, i32* %2, i64 %38
store i32 %46, i32* %47
%48 = getelementptr inbounds [1000 x float], [1000 x float]* %9, i64 0, i64 %42
%49 = load float, float* %48
%50 = fmul float %49, 6.528000e+04
%51 = fptosi float %50 to i32
%52 = getelementptr inbounds i32, i32* %4, i64 %38
store i32 %51, i32* %52
%53 = getelementptr inbounds [1000 x float], [1000 x float]* %8, i64 0, i64 %42
%54 = load float, float* %53
%55 = fmul float %54, 6.528000e+04
%56 = fptosi float %55 to i32
%57 = getelementptr inbounds i32, i32* %3, i64 %38
store i32 %56, i32* %57
%58 = add nuw nsw i64 %38, 1
%59 = icmp eq i64 %58, %36
br i1 %59, label %60, label %37
60: ; preds = %37, %30, %5
%61 = phi i32 [ 0, %5 ], [ %31, %30 ], [ %31, %37 ]
ret i32 %61
}