#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 */

/* Variables and functions */
int sscanf(char const *, char *, double *, int *);
int parse_doubles(double *t, int nmax, const char *s) {
  int i = 0, w;
  while (i < nmax && 1 == sscanf(s, "%lg %n", t + i, &w)) {
    i += 1;
    s += w;
  }
  return i;
}


x86 assembly (clang, -O0):
<parse_doubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    116d <parse_doubles+0x5d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xeab(%rip),%rsi
lea    -0x20(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117d <parse_doubles+0x6d>
jmp    119c <parse_doubles+0x8c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    112a <parse_doubles+0x1a>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_doubles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1170 <parse_doubles+0x60>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %esi,%ebp
xor    %r15d,%r15d
lea    0xecf(%rip),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1173 <parse_doubles+0x63>
add    $0x1,%r15
movslq 0x4(%rsp),%rax
add    %rax,%r14
add    $0x8,%rbx
cmp    %r15,%rbp
jne    1140 <parse_doubles+0x30>
mov    %ebp,%r15d
jmp    1173 <parse_doubles+0x63>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%lg %n\00"
define i32 @parse_doubles(double* %0, i32 %1, i8* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i8*, i8** %6
%15 = load double*, double** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %18, i32* %8)
%20 = icmp eq i32 1, %19
br label %21
21: ; preds = %13, %9
%22 = phi i1 [ false, %9 ], [ %20, %13 ]
br i1 %22, label %23, label %30
23: ; preds = %21
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
%26 = load i32, i32* %8
%27 = load i8*, i8** %6
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %6
br label %9
30: ; preds = %21
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"%lg %n\00"
define i32 @parse_doubles(double* %0, i32 %1, i8* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %23
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %15
%10 = phi i64 [ 0, %7 ], [ %16, %15 ]
%11 = phi i8* [ %2, %7 ], [ %19, %15 ]
%12 = getelementptr inbounds double, double* %0, i64 %10
%13 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %12, i32* %4)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = add nuw nsw i64 %10, 1
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %11, i64 %18
%20 = icmp eq i64 %16, %8
br i1 %20, label %23, label %9
21: ; preds = %9
%22 = trunc i64 %10 to i32
br label %23
23: ; preds = %15, %21, %3
%24 = phi i32 [ 0, %3 ], [ %22, %21 ], [ %1, %15 ]
ret i32 %24
}