#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*/ memcpy(char *, unsigned char *, long);
double strtod(char *, char **);
double rl_strtod(unsigned char *_str, long strlen, unsigned char **_eptr) {
  double d;
  char str[40];
  char *eptr;
  if (strlen > 39) {
    strlen = 39;
  }
  memcpy(str, _str, strlen);
  str[strlen] = 0;
  d = strtod(str, &eptr);
  if (_eptr) {
    *_eptr = _str + (eptr - str);
  }
  return d;
}


x86 assembly (clang, -O0):
<rl_strtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x27,-0x10(%rbp)
jle    1147 <rl_strtod+0x27>
movq   $0x27,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1197 <rl_strtod+0x77>
mov    -0x8(%rbp),%rcx
mov    -0x58(%rbp),%rax
lea    -0x50(%rbp),%rdx
sub    %rdx,%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movsd  -0x20(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_strtod>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rdi,%r12
cmp    $0x27,%rsi
mov    $0x27,%ebx
cmovl  %rsi,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1030 <strtod@plt>
test   %r14,%r14
je     1176 <rl_strtod+0x56>
mov    0x8(%rsp),%rax
sub    %r15,%rax
add    %rax,%r12
mov    %r12,(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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