#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 uint8_t;

/* Variables and functions */
double strtod(char *, char **);
int read_double(char *line, uint8_t *char_counter, double *double_ptr) {
  char *start = line + *char_counter;
  char *end;
  *double_ptr = strtod(start, &end);
  if (end == start) {
    return (0);
  };
  *char_counter = end - line;
  return (1);
}


x86 assembly (clang, -O0):
<read_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1165 <read_double+0x55>
movl   $0x0,-0x4(%rbp)
jmp    117f <read_double+0x6f>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_double>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
movslq (%rsi),%rbx
add    %rdi,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strtod@plt>
movsd  %xmm0,(%r15)
mov    (%rsp),%rax
cmp    %rbx,%rax
je     114d <read_double+0x3d>
sub    %r12d,%eax
mov    %eax,(%r14)
mov    $0x1,%eax
jmp    114f <read_double+0x3f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @read_double(i8* %0, i32* %1, double* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca double*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store double* %2, double** %7
%10 = load i8*, i8** %5
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = call double @strtod(i8* %15, i8** %9)
%17 = load double*, double** %7
store double %16, double* %17
%18 = load i8*, i8** %9
%19 = load i8*, i8** %8
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 0, i32* %4
br label %30
22: ; preds = %3
%23 = load i8*, i8** %9
%24 = load i8*, i8** %5
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = load i32*, i32** %6
store i32 %28, i32* %29
store i32 1, i32* %4
br label %30
30: ; preds = %22, %21
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @read_double(i8* %0, i32* nocapture %1, double* nocapture writeonly %2) {
%4 = alloca i8*
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = bitcast i8** %4 to i8*
%9 = call double @strtod(i8* %7, i8** %4)
store double %9, double* %2
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, %7
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %1
br label %17
17: ; preds = %3, %12
%18 = phi i32 [ 1, %12 ], [ 0, %3 ]
ret i32 %18
}