#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 *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void grab_double(double *out, char *line, int begin, int end) {
  char str[32];
  strncpy(str, &line[begin], end - begin + 1);
  str[end - begin + 1] = '\0';
  sscanf(str, "%lf", out);
}


x86 assembly (clang, -O0):
<grab_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
sub    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe8e(%rip),%rsi
call   1040 <sscanf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_double>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
movslq %edx,%rax
add    %rax,%rsi
sub    %eax,%ecx
movslq %ecx,%rbx
lea    0x1(%rbx),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <strncpy@plt>
movb   $0x0,0x1(%rsp,%rbx,1)
lea    0xeae(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define void @grab_double(double* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
store double* %0, double** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = call i32 @strncpy(i8* %10, i8* %14, i32 %18)
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = sub nsw i32 %20, %21
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%27 = load double*, double** %5
%28 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %27)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define void @grab_double(double* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = sub nsw i32 %3, %2
%10 = add nsw i32 %9, 1
%11 = call i32 @strncpy(i8* %6, i8* %8, i32 %10)
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %0)
ret void
}