#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 /*<<< orphan*/ str;

/* Variables and functions */
int sscanf(char *, char *, double *);
scalar_t__ strlen(char const *);
extern double str2num(const char *s, int i, int n) {
  double value;
  char str[256], *p = str;
  if (i < 0 || (int)strlen(s) < i || (int)sizeof(str) - 1 < n)
    return 0.0;
  for (s += i; *s && --n >= 0; s++)
    *p++ = *s == 'd' || *s == 'D' ? 'E' : *s;
  *p = '\0';
  return sscanf(str, "%lf", &value) == 1 ? value : 0.0;
}


x86 assembly (clang, -O0):
<str2num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     116d <str2num+0x4d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x14(%rbp),%eax
jl     116d <str2num+0x4d>
mov    $0xff,%eax
cmp    -0x18(%rbp),%eax
jge    117a <str2num+0x5a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1291 <str2num+0x171>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x129(%rbp)
je     11b8 <str2num+0x98>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
setge  %al
mov    %al,-0x129(%rbp)
mov    -0x129(%rbp),%al
test   $0x1,%al
jne    11cb <str2num+0xab>
jmp    1238 <str2num+0x118>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
je     11eb <str2num+0xcb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x44,%eax
jne    11fb <str2num+0xdb>
mov    $0x45,%eax
mov    %eax,-0x130(%rbp)
jmp    1208 <str2num+0xe8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x130(%rbp)
mov    -0x130(%rbp),%eax
mov    %al,%cl
mov    -0x128(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x128(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118b <str2num+0x6b>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
lea    0xdb0(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1274 <str2num+0x154>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x138(%rbp)
ff
jmp    1284 <str2num+0x164>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x138(%rbp)
ff
jmp    1284 <str2num+0x164>
movsd  -0x138(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2num>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
xorps  %xmm0,%xmm0
test   %esi,%esi
js     11c3 <str2num+0xa3>
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0xff,%ebp
jg     11b8 <str2num+0x98>
cmp    %ebx,%eax
xorps  %xmm0,%xmm0
jl     11c3 <str2num+0xa3>
mov    %ebx,%ecx
mov    (%r14,%rcx,1),%bl
lea    0x10(%rsp),%rax
test   %bl,%bl
je     119a <str2num+0x7a>
add    %r14,%rcx
add    $0x1,%rcx
jmp    1185 <str2num+0x65>
nopl   0x0(%rax)
mov    %sil,(%rax)
add    $0x1,%rax
movzbl (%rcx),%ebx
add    $0x1,%rcx
add    $0xffffffff,%ebp
test   %bl,%bl
je     119a <str2num+0x7a>
test   %ebp,%ebp
jle    119a <str2num+0x7a>
mov    $0x45,%sil
mov    %ebx,%edx
or     $0x20,%dl
cmp    $0x64,%dl
je     1170 <str2num+0x50>
mov    %ebx,%esi
jmp    1170 <str2num+0x50>
movb   $0x0,(%rax)
lea    0xe5c(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11bd <str2num+0x9d>
xorps  %xmm0,%xmm0
jmp    11c3 <str2num+0xa3>
movsd  0x8(%rsp),%xmm0
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define double @str2num(i8* %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca [256 x i8]
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
store i8* %11, i8** %10
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
%17 = trunc i64 %16 to i32
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = load i32, i32* %7
%22 = icmp slt i32 255, %21
br i1 %22, label %23, label %24
23: ; preds = %20, %14, %3
store double 0.000000e+00, double* %4
br label %73
24: ; preds = %20
%25 = load i32, i32* %6
%26 = load i8*, i8** %5
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %5
br label %29
29: ; preds = %60, %24
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
%37 = icmp sge i32 %36, 0
br label %38
38: ; preds = %34, %29
%39 = phi i1 [ false, %29 ], [ %37, %34 ]
br i1 %39, label %40, label %63
40: ; preds = %38
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 100
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 68
br i1 %49, label %50, label %51
50: ; preds = %45, %40
br label %55
51: ; preds = %45
%52 = load i8*, i8** %5
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
br label %55
55: ; preds = %51, %50
%56 = phi i32 [ 69, %50 ], [ %54, %51 ]
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %10
store i8 %57, i8* %58
br label %60
60: ; preds = %55
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %5
br label %29
63: ; preds = %38
%64 = load i8*, i8** %10
store i8 0, i8* %64
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%66 = call i32 @sscanf(i8* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %8)
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = load double, double* %8
br label %71
70: ; preds = %63
br label %71
71: ; preds = %70, %68
%72 = phi double [ %69, %68 ], [ 0.000000e+00, %70 ]
store double %72, double* %4
br label %73
73: ; preds = %71, %23
%74 = load double, double* %4
ret double %74
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define double @str2num(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca [256 x i8]
%6 = bitcast double* %4 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = icmp slt i32 %1, 0
br i1 %8, label %41, label %9
9: ; preds = %3
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = trunc i64 %10 to i32
%12 = icmp slt i32 %11, %1
%13 = icmp sgt i32 %2, 255
%14 = or i1 %13, %12
br i1 %14, label %41, label %15
15: ; preds = %9
%16 = zext i32 %1 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %35, label %20
20: ; preds = %15, %29
%21 = phi i8 [ %33, %29 ], [ %18, %15 ]
%22 = phi i8* [ %31, %29 ], [ %7, %15 ]
%23 = phi i32 [ %25, %29 ], [ %2, %15 ]
%24 = phi i8* [ %32, %29 ], [ %17, %15 ]
%25 = add nsw i32 %23, -1
%26 = icmp sgt i32 %23, 0
br i1 %26, label %27, label %35
27: ; preds = %20
switch i8 %21, label %28 [
i8 100, label %29
i8 68, label %29
]
28: ; preds = %27
br label %29
29: ; preds = %27, %27, %28
%30 = phi i8 [ %21, %28 ], [ 69, %27 ], [ 69, %27 ]
%31 = getelementptr inbounds i8, i8* %22, i64 1
store i8 %30, i8* %22
%32 = getelementptr inbounds i8, i8* %24, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %20
35: ; preds = %20, %29, %15
%36 = phi i8* [ %7, %15 ], [ %31, %29 ], [ %22, %20 ]
store i8 0, i8* %36
%37 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %4)
%38 = icmp eq i32 %37, 1
%39 = load double, double* %4
%40 = select i1 %38, double %39, double 0.000000e+00
br label %41
41: ; preds = %3, %9, %35
%42 = phi double [ %40, %35 ], [ 0.000000e+00, %9 ], [ 0.000000e+00, %3 ]
ret double %42
}