#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 /*<<< orphan*/ sscanf(char *, char *, double *);
char *strsep(char **, char *);
void vec_atod(double *vec, int N, char *vals) {
  char *val;
  int n = 0;
  while (n < N && (val = strsep(&vals, " "))) {
    sscanf(val, " %lg", &vec[n]);
    n++;
  }
  for (; n < N; n++)
    vec[n] = 0;
}


x86 assembly (clang, -O0):
<vec_atod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x25(%rbp)
jge    1169 <vec_atod+0x49>
lea    -0x18(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1179 <vec_atod+0x59>
jmp    11a6 <vec_atod+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe6f(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113a <vec_atod+0x1a>
jmp    11ab <vec_atod+0x8b>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d5 <vec_atod+0xb5>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ab <vec_atod+0x8b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_atod>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
test   %esi,%esi
mov    %rdi,0x8(%rsp)
jle    119d <vec_atod+0x6d>
mov    %esi,0x4(%rsp)
mov    %esi,%r15d
xor    %r14d,%r14d
lea    0xea3(%rip),%r12
lea    0x10(%rsp),%rbp
lea    0xe99(%rip),%r13
mov    %rdi,%rbx
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strsep@plt>
test   %rax,%rax
je     11a7 <vec_atod+0x77>
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
add    $0x1,%r14
add    $0x8,%rbx
cmp    %r14,%r15
jne    1170 <vec_atod+0x40>
jmp    11d1 <vec_atod+0xa1>
xor    %r14d,%r14d
cmp    %esi,%r14d
jl     11b0 <vec_atod+0x80>
jmp    11d1 <vec_atod+0xa1>
mov    0x4(%rsp),%esi
cmp    %esi,%r14d
jge    11d1 <vec_atod+0xa1>
mov    %r14d,%eax
mov    0x8(%rsp),%rdx
lea    (%rdx,%rax,8),%rdi
not    %r14d
add    %esi,%r14d
lea    0x8(,%r14,8),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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