#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 */
double atof(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int freada(double *p, const int bl, FILE *fp) {
  int c;
  char buf[256];
  c = 0;
  while (c < bl) {
    if (fgets(buf, 256, fp) == NULL)
      break;
    p[c] = atof(buf);
    c++;
  }
  return (c);
}


x86 assembly (clang, -O0):
<freada>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <freada+0x74>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    116d <freada+0x4d>
jmp    1194 <freada+0x74>
lea    -0x120(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <freada+0x1d>
mov    -0x1c(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freada>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
test   %esi,%esi
jle    1181 <freada+0x61>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%r13d
xor    %ebx,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1183 <freada+0x63>
mov    %r12,%rdi
call   1030 <atof@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <freada+0x30>
mov    %r13d,%ebx
jmp    1183 <freada+0x63>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @freada(double* %0, i32 %1, i32* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [256 x i8]
store double* %0, double** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %9
9: ; preds = %19, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%15 = load i32*, i32** %6
%16 = call i32* @fgets(i8* %14, i32 256, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
br label %28
19: ; preds = %13
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%21 = call double @atof(i8* %20)
%22 = load double*, double** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double %21, double* %25
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %9
28: ; preds = %18, %9
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
define i32 @freada(double* nocapture writeonly %0, i32 %1, i32* nocapture %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %13
%10 = phi i64 [ 0, %7 ], [ %16, %13 ]
%11 = call i32* @fgets(i8* %5, i32 256, i32* %2)
%12 = icmp eq i32* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = call double @atof(i8* %5)
%15 = getelementptr inbounds double, double* %0, i64 %10
store double %14, double* %15
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %20, label %9
18: ; preds = %9
%19 = trunc i64 %10 to i32
br label %20
20: ; preds = %13, %18, %3
%21 = phi i32 [ 0, %3 ], [ %19, %18 ], [ %1, %13 ]
ret i32 %21
}