#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 fscanf(int /*<<< orphan*/ *, char *, double *);
size_t read_from_stream(FILE *stream, double *buffer, size_t count) {
  size_t n;
  for (n = 0; count > 0; --count, ++buffer, ++n) {
    if (fscanf(stream, "%lf", buffer) != 1)
      break;
  }
  return n;
}


x86 assembly (clang, -O0):
<read_from_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1187 <read_from_stream+0x77>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeba(%rip),%rsi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     1159 <read_from_stream+0x49>
jmp    1187 <read_from_stream+0x77>
jmp    115e <read_from_stream+0x4e>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <read_from_stream+0x1c>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_stream>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     1165 <read_from_stream+0x55>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %r15d,%r15d
lea    0xecf(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    1168 <read_from_stream+0x58>
add    $0x8,%rbx
add    $0x1,%r15
cmp    %r15,%r14
jne    1140 <read_from_stream+0x30>
mov    %r14,%r15
jmp    1168 <read_from_stream+0x58>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i64 @read_from_stream(i32* %0, double* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca double*
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %4
store double* %1, double** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %8
8: ; preds = %18, %3
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32*, i32** %4
%13 = load double*, double** %5
%14 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %13)
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %11
br label %25
17: ; preds = %11
br label %18
18: ; preds = %17
%19 = load i64, i64* %6
%20 = add i64 %19, -1
store i64 %20, i64* %6
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i32 1
store double* %22, double** %5
%23 = load i64, i64* %7
%24 = add i64 %23, 1
store i64 %24, i64* %7
br label %8
25: ; preds = %16, %8
%26 = load i64, i64* %7
ret i64 %26
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i64 @read_from_stream(i32* nocapture %0, double* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3, %11
%6 = phi i64 [ %14, %11 ], [ 0, %3 ]
%7 = phi i64 [ %12, %11 ], [ %2, %3 ]
%8 = phi double* [ %13, %11 ], [ %1, %3 ]
%9 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = add i64 %7, -1
%13 = getelementptr inbounds double, double* %8, i64 1
%14 = add nuw i64 %6, 1
%15 = icmp eq i64 %12, 0
br i1 %15, label %16, label %5
16: ; preds = %11, %5, %3
%17 = phi i64 [ 0, %3 ], [ %6, %5 ], [ %2, %11 ]
ret i64 %17
}