#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ malloc(int);
float *read_histogram(const char *filename, int *bins) {
  *bins = 0;
  FILE *f = fopen(filename, "rb");
  if (!f)
    return 0;
  while (!feof(f)) {
    fscanf(f, "%*f %*f %*f %*f %*f %*f %*f %*f %*f %*f\n");
    (*bins)++;
  }
  fseek(f, 0, SEEK_SET);
  float *hist = (float *)malloc(3 * sizeof(float) * (*bins));
  int k = 0;
  while (!feof(f)) {
    fscanf(f, "%*f %*f %*f %*f %*f %*f %*f %f %f %f\n", hist + 3 * k,
           hist + 3 * k + 1, hist + 3 * k + 2);
    k++;
  }
  fclose(f);
  return hist;
}


x86 assembly (clang, -O0):
<read_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <read_histogram+0x46>
movq   $0x0,-0x8(%rbp)
jmp    12a6 <read_histogram+0x146>
jmp    11ab <read_histogram+0x4b>
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c9 <read_histogram+0x69>
jmp    11eb <read_histogram+0x8b>
mov    -0x20(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11ab <read_histogram+0x4b>
mov    -0x20(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
imul   $0xc,%rax,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    123a <read_histogram+0xda>
jmp    1295 <read_histogram+0x135>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
imul   $0x3,-0x2c(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x28(%rbp),%rcx
imul   $0x3,-0x2c(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rcx
add    $0x4,%rcx
mov    -0x28(%rbp),%r8
imul   $0x3,-0x2c(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%r8
add    $0x8,%r8
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    121c <read_histogram+0xbc>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_histogram>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
movl   $0x0,(%rsi)
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1232 <read_histogram+0xd2>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11bd <read_histogram+0x5d>
lea    0xe67(%rip),%rbx
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
addl   $0x1,(%r14)
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11a0 <read_histogram+0x40>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    (%r14),%eax
shl    $0x2,%eax
lea    (%rax,%rax,2),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1228 <read_histogram+0xc8>
lea    0xe38(%rip),%r15
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
lea    0x4(%rbx),%rcx
lea    0x8(%rbx),%r8
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    %r12,%rdi
call   1050 <feof@plt>
add    $0xc,%rbx
test   %eax,%eax
je     1200 <read_histogram+0xa0>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    1235 <read_histogram+0xd5>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [41 x i8] c"%*f %*f %*f %*f %*f %*f %*f %*f %*f %*f\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [38 x i8] c"%*f %*f %*f %*f %*f %*f %*f %f %f %f\0A\00"
define float* @read_histogram(i8* %0, i32* %1) {
%3 = alloca float*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca float*
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %5
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store float* null, float** %3
br label %69
15: ; preds = %2
br label %16
16: ; preds = %21, %15
%17 = load i32*, i32** %6
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %22, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
store i32 %26, i32* %24
br label %16
27: ; preds = %16
%28 = load i32*, i32** %6
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = mul i64 12, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to float*
store float* %37, float** %7
store i32 0, i32* %8
br label %38
38: ; preds = %43, %27
%39 = load i32*, i32** %6
%40 = call i32 @feof(i32* %39)
%41 = icmp ne i32 %40, 0
%42 = xor i1 %41, true
br i1 %42, label %43, label %65
43: ; preds = %38
%44 = load i32*, i32** %6
%45 = load float*, float** %7
%46 = load i32, i32* %8
%47 = mul nsw i32 3, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds float, float* %45, i64 %48
%50 = load float*, float** %7
%51 = load i32, i32* %8
%52 = mul nsw i32 3, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds float, float* %50, i64 %53
%55 = getelementptr inbounds float, float* %54, i64 1
%56 = load float*, float** %7
%57 = load i32, i32* %8
%58 = mul nsw i32 3, %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds float, float* %56, i64 %59
%61 = getelementptr inbounds float, float* %60, i64 2
%62 = call i32 (i32*, i8*, ...) @fscanf(i32* %44, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), float* %49, float* %55, float* %61)
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %38
65: ; preds = %38
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = load float*, float** %7
store float* %68, float** %3
br label %69
69: ; preds = %65, %14
%70 = load float*, float** %3
ret float* %70
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [41 x i8] c"%*f %*f %*f %*f %*f %*f %*f %*f %*f %*f\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [38 x i8] c"%*f %*f %*f %*f %*f %*f %*f %f %f %f\0A\00"
define float* @read_histogram(i8* nocapture %0, i32* nocapture %1) {
store i32 0, i32* %1
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = tail call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5, %8
%9 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %3, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
%12 = tail call i32 @feof(i32* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %8, %5
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %3, i32 0, i32 %15)
%17 = load i32, i32* %1
%18 = mul i32 %17, 12
%19 = tail call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to float*
%21 = tail call i32 @feof(i32* %3)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %14, %23
%24 = phi i64 [ %30, %23 ], [ 0, %14 ]
%25 = mul nuw nsw i64 %24, 3
%26 = getelementptr inbounds float, float* %20, i64 %25
%27 = getelementptr inbounds float, float* %26, i64 1
%28 = getelementptr inbounds float, float* %26, i64 2
%29 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), float* %26, float* %27, float* %28)
%30 = add nuw i64 %24, 1
%31 = tail call i32 @feof(i32* %3)
%32 = icmp eq i32 %31, 0
br i1 %32, label %23, label %33
33: ; preds = %23, %14
%34 = tail call i32 @fclose(i32* %3)
br label %35
35: ; preds = %2, %33
%36 = phi float* [ %20, %33 ], [ null, %2 ]
ret float* %36
}