#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 */
double atof(char *);
char *spcalloc(int, int);
int /*<<< orphan*/ spfree(char *);
double sp_extract_positional_float(const char *from, int size) {
  double result;
  char *buf = spcalloc(size + 1, 1);
  char *ptr = buf;
  int i = 0;
  while (i < size && *from) {
    *ptr++ = *from++;
    ++i;
  }
  buf[size] = '\0';
  ptr = buf;
  while (*ptr) {
    if (*ptr == 'D')
      *ptr = 'E';
    ++ptr;
  }
  result = atof(buf);
  spfree(buf);
  return result;
}


x86 assembly (clang, -O0):
<sp_extract_positional_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <spcalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    1183 <sp_extract_positional_float+0x53>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1193 <sp_extract_positional_float+0x63>
jmp    11c3 <sp_extract_positional_float+0x93>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1162 <sp_extract_positional_float+0x32>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     120c <sp_extract_positional_float+0xdc>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x44,%eax
jne    11fb <sp_extract_positional_float+0xcb>
mov    -0x28(%rbp),%rax
movb   $0x45,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11d7 <sp_extract_positional_float+0xa7>
mov    -0x20(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <spfree@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp_extract_positional_float>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x1(%r14),%edi
mov    $0x1,%esi
call   1040 <spcalloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    1174 <sp_extract_positional_float+0x44>
mov    %r14d,%eax
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rcx,1),%edx
test   %dl,%dl
je     1174 <sp_extract_positional_float+0x44>
mov    %dl,(%r15,%rcx,1)
add    $0x1,%rcx
cmp    %ecx,%eax
jne    1160 <sp_extract_positional_float+0x30>
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
jmp    1197 <sp_extract_positional_float+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x45,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x44,%cl
je     1190 <sp_extract_positional_float+0x60>
test   %cl,%cl
jne    1193 <sp_extract_positional_float+0x63>
mov    %r15,%rdi
call   1030 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1050 <spfree@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @sp_extract_positional_float(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = call i8* @spcalloc(i32 %10, i32 1)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
store i8* %12, i8** %7
store i32 0, i32* %8
br label %13
13: ; preds = %24, %2
%14 = load i32, i32* %8
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %17, %13
%23 = phi i1 [ false, %13 ], [ %21, %17 ]
br i1 %23, label %24, label %32
24: ; preds = %22
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = load i8, i8* %25
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %7
store i8 %27, i8* %28
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %13
32: ; preds = %22
%33 = load i8*, i8** %6
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %6
store i8* %37, i8** %7
br label %38
38: ; preds = %49, %32
%39 = load i8*, i8** %7
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 68
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = load i8*, i8** %7
store i8 69, i8* %48
br label %49
49: ; preds = %47, %42
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %7
br label %38
52: ; preds = %38
%53 = load i8*, i8** %6
%54 = call double @atof(i8* %53)
store double %54, double* %5
%55 = load i8*, i8** %6
%56 = call i32 @spfree(i8* %55)
%57 = load double, double* %5
ret double %57
}

LLVM IR (-O2):
define double @sp_extract_positional_float(i8* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, 1
%4 = tail call i8* @spcalloc(i32 %3, i32 1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %17
6: ; preds = %2, %12
%7 = phi i32 [ %15, %12 ], [ 0, %2 ]
%8 = phi i8* [ %14, %12 ], [ %4, %2 ]
%9 = phi i8* [ %13, %12 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %10, i8* %8
%15 = add nuw nsw i32 %7, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %6
17: ; preds = %6, %12, %2
%18 = sext i32 %1 to i64
%19 = getelementptr inbounds i8, i8* %4, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %24, %17
%21 = phi i8* [ %4, %17 ], [ %25, %24 ]
%22 = load i8, i8* %21
switch i8 %22, label %24 [
i8 0, label %26
i8 68, label %23
]
23: ; preds = %20
store i8 69, i8* %21
br label %24
24: ; preds = %20, %23
%25 = getelementptr inbounds i8, i8* %21, i64 1
br label %20
26: ; preds = %20
%27 = tail call double @atof(i8* %4)
%28 = tail call i32 @spfree(i8* %4)
ret double %27
}