#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*/ free(char **);
char **malloc(int);
double strtod(char *, char **);
int string_to_float(char *string, double *float_ptr) {
  char **error_ptr;
  if (*string == 0)
    return -11;
  error_ptr = malloc(sizeof(char **));
  (*float_ptr) = strtod(string, error_ptr);
  if ((**error_ptr == '\0') || (**error_ptr == '\r')) {
    free(error_ptr);
    return 1;
  }
  (*float_ptr) = 0;
  free(error_ptr);
  return -11;
}


x86 assembly (clang, -O0):
<string_to_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115c <string_to_float+0x2c>
movl   $0xfffffff5,-0x4(%rbp)
jmp    11d5 <string_to_float+0xa5>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a5 <string_to_float+0x75>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11ba <string_to_float+0x8a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <string_to_float+0xa5>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffff5,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_float>:
push   %rbp
push   %r14
push   %rbx
cmpb   $0x0,(%rdi)
je     1184 <string_to_float+0x54>
mov    %rsi,%r14
mov    %rdi,%rbp
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <strtod@plt>
movsd  %xmm0,(%r14)
mov    (%rbx),%rax
mov    (%rax),%al
mov    $0x1,%ebp
test   %al,%al
je     117a <string_to_float+0x4a>
cmp    $0xd,%al
je     117a <string_to_float+0x4a>
movq   $0x0,(%r14)
mov    $0xfffffff5,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1189 <string_to_float+0x59>
mov    $0xfffffff5,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_to_float(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i8**
store i8* %0, i8** %4
store double* %1, double** %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -11, i32* %3
br label %36
12: ; preds = %2
%13 = call i8** @malloc(i32 8)
store i8** %13, i8*** %6
%14 = load i8*, i8** %4
%15 = load i8**, i8*** %6
%16 = call double @strtod(i8* %14, i8** %15)
%17 = load double*, double** %5
store double %16, double* %17
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %12
%24 = load i8**, i8*** %6
%25 = load i8*, i8** %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 13
br i1 %28, label %29, label %32
29: ; preds = %23, %12
%30 = load i8**, i8*** %6
%31 = call i32 @free(i8** %30)
store i32 1, i32* %3
br label %36
32: ; preds = %23
%33 = load double*, double** %5
store double 0.000000e+00, double* %33
%34 = load i8**, i8*** %6
%35 = call i32 @free(i8** %34)
store i32 -11, i32* %3
br label %36
36: ; preds = %32, %29, %11
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @string_to_float(i8* %0, double* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i8** @malloc(i32 8)
%7 = tail call double @strtod(i8* %0, i8** %6)
store double %7, double* %1
%8 = load i8*, i8** %6
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 0, label %11
i8 13, label %11
]
10: ; preds = %5
store double 0.000000e+00, double* %1
br label %11
11: ; preds = %5, %5, %10
%12 = phi i32 [ -11, %10 ], [ 1, %5 ], [ 1, %5 ]
%13 = tail call i32 @free(i8** %6)
br label %14
14: ; preds = %11, %2
%15 = phi i32 [ -11, %2 ], [ %12, %11 ]
ret i32 %15
}