#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
scalar_t__ strtod(char *, char **);
char *strtok(char *, char *);
int parse_double_array(char *s, double *arr, int n) {
  char *line, *endptr;
  int i = 0;
  double v;
  assert(s != NULL && "Invalid input string");
  line = strtok(s, "\n");
  while (line != NULL && i < n) {
    endptr = line;
    v = (double)(strtod(line, &endptr));
    if ((*endptr) != (char)0) {
      fprintf(stderr, "Invalid input: line %d of section\n", i);
    }
    arr[i] = v;
    i++;
    line[strlen(line)] = '\n';
    line = strtok(NULL, "\n");
  }
  if (line != NULL) {
    line[strlen(line)] = '\n';
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_double_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x39(%rbp)
je     1184 <parse_double_array+0x34>
mov    $0x1,%al
mov    %al,-0x39(%rbp)
jmp    1184 <parse_double_array+0x34>
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x3a(%rbp)
je     11c1 <parse_double_array+0x71>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    11d1 <parse_double_array+0x81>
jmp    1268 <parse_double_array+0x118>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1218 <parse_double_array+0xc8>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xe02(%rip),%rsi
call   1060 <fprintf@plt>
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xddc(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11a5 <parse_double_array+0x55>
cmpq   $0x0,-0x20(%rbp)
je     128f <parse_double_array+0x13f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_double_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1050 <assert@plt>
lea    0xea9(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
setne  %al
je     120b <parse_double_array+0xbb>
test   %ebx,%ebx
jle    120b <parse_double_array+0xbb>
mov    %ebx,%r12d
xor    %ebx,%ebx
lea    0xe82(%rip),%r13
nop
mov    %r15,(%rsp)
mov    %r15,%rdi
mov    %rsp,%rsi
call   1030 <strtod@plt>
mov    %rax,%rbp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11d2 <parse_double_array+0x82>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
mov    %r15,%rdi
call   1040 <strlen@plt>
movb   $0xa,(%r15,%rax,1)
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
setne  %al
je     120b <parse_double_array+0xbb>
add    $0x1,%rbx
cmp    %r12,%rbx
jb     11a0 <parse_double_array+0x50>
test   %al,%al
je     121c <parse_double_array+0xcc>
mov    %r15,%rdi
call   1040 <strlen@plt>
movb   $0xa,(%r15,%rax,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Invalid input string\00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Invalid input: line %d of section\0A\00"
define i32 @parse_double_array(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %9
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
br label %14
14: ; preds = %13, %3
%15 = phi i1 [ false, %3 ], [ true, %13 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %4
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %7
br label %20
20: ; preds = %42, %14
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br label %27
27: ; preds = %23, %20
%28 = phi i1 [ false, %20 ], [ %26, %23 ]
br i1 %28, label %29, label %55
29: ; preds = %27
%30 = load i8*, i8** %7
store i8* %30, i8** %8
%31 = load i8*, i8** %7
%32 = call i64 @strtod(i8* %31, i8** %8)
%33 = sitofp i64 %32 to double
store double %33, double* %10
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = load i32, i32* %9
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38, %29
%43 = load double, double* %10
%44 = load double*, double** %5
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = load i8*, i8** %7
%51 = load i8*, i8** %7
%52 = call i64 @strlen(i8* %51)
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 10, i8* %53
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %54, i8** %7
br label %20
55: ; preds = %27
%56 = load i8*, i8** %7
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i8*, i8** %7
%60 = load i8*, i8** %7
%61 = call i64 @strlen(i8* %60)
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 10, i8* %62
br label %63
63: ; preds = %58, %55
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Invalid input: line %d of section\0A\00"
define i32 @parse_double_array(i8* %0, double* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i8* %9, null
%11 = icmp sgt i32 %2, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %3
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %27
%16 = phi i64 [ 0, %13 ], [ %29, %27 ]
%17 = phi i8* [ %9, %13 ], [ %32, %27 ]
store i8* %17, i8** %4
%18 = call i64 @strtod(i8* %17, i8** %4)
%19 = sitofp i64 %18 to double
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = trunc i64 %16 to i32
%26 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %15
%28 = getelementptr inbounds double, double* %1, i64 %16
store double %19, double* %28
%29 = add nuw nsw i64 %16, 1
%30 = tail call i64 @strlen(i8* %17)
%31 = getelementptr inbounds i8, i8* %17, i64 %30
store i8 10, i8* %31
%32 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp ne i8* %32, null
%34 = icmp ult i64 %29, %14
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %15, label %36
36: ; preds = %27, %3
%37 = phi i8* [ %9, %3 ], [ %32, %27 ]
%38 = phi i1 [ %10, %3 ], [ %33, %27 ]
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = tail call i64 @strlen(i8* %37)
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 10, i8* %41
br label %42
42: ; preds = %39, %36
ret i32 0
}