#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 */
scalar_t__ ERANGE;
scalar_t__ errno;
scalar_t__ isspace(char);
double strtod(char const *, char **);
int gut_parse_double(const char *s, double *result) {
  char *endptr;
  double val;
  errno = 0;
  val = strtod(s, &endptr);
  if (errno == ERANGE) {
    *result = val;
    return -3;
  } else if (errno != 0) {
    return -2;
  }
  if (endptr == s) {
    return -1;
  }
  while ((*endptr != '\0') && isspace(*endptr))
    endptr++;
  if (*endptr != '\0') {
    return -1;
  }
  *result = val;
  return 0;
}


x86 assembly (clang, -O0):
<gut_parse_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <gut_parse_double+0x63>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0xfffffffd,-0x4(%rbp)
jmp    1240 <gut_parse_double+0x120>
mov    0x2e4e(%rip),%rax
cmpq   $0x0,(%rax)
je     11a0 <gut_parse_double+0x80>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1240 <gut_parse_double+0x120>
jmp    11a5 <gut_parse_double+0x85>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11bf <gut_parse_double+0x9f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <gut_parse_double+0x120>
jmp    11c4 <gut_parse_double+0xa4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     11ef <gut_parse_double+0xcf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11ff <gut_parse_double+0xdf>
jmp    1210 <gut_parse_double+0xf0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c4 <gut_parse_double+0xa4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122c <gut_parse_double+0x10c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <gut_parse_double+0x120>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gut_parse_double>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e9f(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x0(%rbp),%rax
mov    0x2e92(%rip),%rcx
mov    $0xfffffffd,%r15d
cmp    (%rcx),%rax
jne    116b <gut_parse_double+0x4b>
movsd  %xmm0,(%r14)
mov    %r15d,%r12d
jmp    1176 <gut_parse_double+0x56>
mov    $0xfffffffe,%r12d
test   %rax,%rax
je     1186 <gut_parse_double+0x66>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rbp
mov    $0xffffffff,%r12d
cmp    %rbx,%rbp
je     1176 <gut_parse_double+0x56>
mov    0x0(%rbp),%al
xor    %r15d,%r15d
test   %al,%al
je     1161 <gut_parse_double+0x41>
movsd  %xmm0,(%rsp)
add    $0x1,%rbp
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11d0 <gut_parse_double+0xb0>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11b0 <gut_parse_double+0x90>
movsd  (%rsp),%xmm0
jmp    1161 <gut_parse_double+0x41>
cmpb   $0x0,-0x1(%rbp)
movsd  (%rsp),%xmm0
jne    1176 <gut_parse_double+0x56>
jmp    1161 <gut_parse_double+0x41>

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

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @gut_parse_double(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i64, i64* @errno
%7 = load i64, i64* @ERANGE
%8 = icmp eq i64 %6, %7
br i1 %8, label %29, label %9
9: ; preds = %2
%10 = icmp eq i64 %6, 0
br i1 %10, label %11, label %31
11: ; preds = %9
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, %0
br i1 %13, label %31, label %14
14: ; preds = %11
%15 = load i8, i8* %12
%16 = icmp eq i8 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %14, %22
%18 = phi i8 [ %24, %22 ], [ %15, %14 ]
%19 = phi i8* [ %23, %22 ], [ %12, %14 ]
%20 = tail call i64 @isspace(i8 signext %18)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %19, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %29, label %17
26: ; preds = %17
%27 = load i8, i8* %19
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22, %26, %14, %2
%30 = phi i32 [ -3, %2 ], [ 0, %14 ], [ 0, %26 ], [ 0, %22 ]
store double %5, double* %1
br label %31
31: ; preds = %29, %26, %11, %9
%32 = phi i32 [ -2, %9 ], [ -1, %11 ], [ -1, %26 ], [ %30, %29 ]
ret i32 %32
}