#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
void read_phantom(float *img, const char *file_name) {
  FILE *fin = fopen(file_name, "r");
  int i;
  for (i = 0; i < 512 * 512; ++i)
    fscanf(fin, "%f", img + i);
  fclose(fin);
}


x86 assembly (clang, -O0):
<read_phantom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x40000,-0x1c(%rbp)
jge    1195 <read_phantom+0x65>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe80(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <read_phantom+0x2b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_phantom>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xebb(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xea9(%rip),%r15
nopl   0x0(%rax)
lea    (%r14,%rbx,1),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
add    $0x4,%rbx
cmp    $0x100000,%rbx
jne    1160 <read_phantom+0x30>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%f\00"
define void @read_phantom(float* %0, i8* %1) {
%3 = alloca float*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store float* %0, float** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
store i32 0, i32* %6
br label %9
9: ; preds = %19, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 262144
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32*, i32** %5
%14 = load float*, float** %3
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds float, float* %14, i64 %16
%18 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %17)
br label %19
19: ; preds = %12
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %9
22: ; preds = %9
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%f\00"
define void @read_phantom(float* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %2, %4
%5 = phi i64 [ 0, %2 ], [ %8, %4 ]
%6 = getelementptr inbounds float, float* %0, i64 %5
%7 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %6)
%8 = add nuw nsw i64 %5, 1
%9 = icmp eq i64 %8, 262144
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = tail call i32 @fclose(i32* %3)
ret void
}