#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;
double HUGE_VAL;
double HUGE_VALF;
double HUGE_VALL;
scalar_t__ errno;
int muggle_str_lstrip_idx(char *);
double strtod(char const *, char **);
int muggle_str_tod(const char *str, double *pval) {
  char *endptr;
  if (str == NULL || pval == NULL) {
    return 0;
  }
  errno = 0;
  *pval = strtod(str, &endptr);
  if (endptr == str) {
    return 0;
  } else if (*endptr != '\0') {
    if (muggle_str_lstrip_idx(endptr) != -1) {
      return 0;
    }
  } else if ((*pval == HUGE_VAL || *pval == HUGE_VALF || *pval == HUGE_VALL) &&
             errno == ERANGE) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<muggle_str_tod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <muggle_str_tod+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <muggle_str_tod+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1260 <muggle_str_tod+0x140>
mov    0x2e67(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    118f <muggle_str_tod+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    1260 <muggle_str_tod+0x140>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c2 <muggle_str_tod+0xa2>
mov    -0x20(%rbp),%rdi
call   1040 <muggle_str_lstrip_idx@plt>
cmp    $0xffffffff,%eax
je     11bd <muggle_str_tod+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    1260 <muggle_str_tod+0x140>
jmp    1254 <muggle_str_tod+0x134>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    0x2e07(%rip),%rax
ucomisd (%rax),%xmm0
jne    11e6 <muggle_str_tod+0xc6>
jp     11e6 <muggle_str_tod+0xc6>
jmp    1229 <muggle_str_tod+0x109>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    0x2df3(%rip),%rax
ucomisd (%rax),%xmm0
jne    120a <muggle_str_tod+0xea>
jp     120a <muggle_str_tod+0xea>
jmp    1229 <muggle_str_tod+0x109>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    0x2dd7(%rip),%rax
ucomisd (%rax),%xmm0
jne    124f <muggle_str_tod+0x12f>
jp     124f <muggle_str_tod+0x12f>
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    0x2d96(%rip),%rcx
cmp    (%rcx),%rax
jne    124f <muggle_str_tod+0x12f>
movl   $0x0,-0x4(%rbp)
jmp    1260 <muggle_str_tod+0x140>
jmp    1254 <muggle_str_tod+0x134>
jmp    1259 <muggle_str_tod+0x139>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_str_tod>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     11b5 <muggle_str_tod+0x95>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11b5 <muggle_str_tod+0x95>
mov    %rdi,%rbx
mov    0x2e7b(%rip),%r15
movq   $0x0,(%r15)
mov    %rsp,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,0x0(%rbp)
mov    (%rsp),%rdi
cmp    %rbx,%rdi
je     11b5 <muggle_str_tod+0x95>
cmpb   $0x0,(%rdi)
je     1173 <muggle_str_tod+0x53>
call   1040 <muggle_str_lstrip_idx@plt>
cmp    $0xffffffff,%eax
jne    11b5 <muggle_str_tod+0x95>
jmp    11af <muggle_str_tod+0x8f>
mov    0x2e5e(%rip),%rax
ucomisd (%rax),%xmm0
jne    1182 <muggle_str_tod+0x62>
jnp    11a0 <muggle_str_tod+0x80>
mov    0x2e5f(%rip),%rax
ucomisd (%rax),%xmm0
jne    1191 <muggle_str_tod+0x71>
jnp    11a0 <muggle_str_tod+0x80>
mov    0x2e58(%rip),%rax
ucomisd (%rax),%xmm0
jne    11af <muggle_str_tod+0x8f>
jp     11af <muggle_str_tod+0x8f>
mov    (%r15),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
je     11b5 <muggle_str_tod+0x95>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@HUGE_VAL = global double 0.000000e+00
@HUGE_VALF = global double 0.000000e+00
@HUGE_VALL = global double 0.000000e+00
@ERANGE = global i64 0
define i32 @muggle_str_tod(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 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load double*, double** %5
%11 = icmp eq double* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 0, i32* %3
br label %55
13: ; preds = %9
store i64 0, i64* @errno
%14 = load i8*, i8** %4
%15 = call double @strtod(i8* %14, i8** %6)
%16 = load double*, double** %5
store double %15, double* %16
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 0, i32* %3
br label %55
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i32 @muggle_str_lstrip_idx(i8* %27)
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %3
br label %55
31: ; preds = %26
br label %53
32: ; preds = %21
%33 = load double*, double** %5
%34 = load double, double* %33
%35 = load double, double* @HUGE_VAL
%36 = fcmp oeq double %34, %35
br i1 %36, label %47, label %37
37: ; preds = %32
%38 = load double*, double** %5
%39 = load double, double* %38
%40 = load double, double* @HUGE_VALF
%41 = fcmp oeq double %39, %40
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = load double*, double** %5
%44 = load double, double* %43
%45 = load double, double* @HUGE_VALL
%46 = fcmp oeq double %44, %45
br i1 %46, label %47, label %52
47: ; preds = %42, %37, %32
%48 = load i64, i64* @errno
%49 = load i64, i64* @ERANGE
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %47
store i32 0, i32* %3
br label %55
52: ; preds = %47, %42
br label %53
53: ; preds = %52, %31
br label %54
54: ; preds = %53
store i32 1, i32* %3
br label %55
55: ; preds = %54, %51, %30, %20, %12
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@errno = global i64 0
@HUGE_VAL = global double 0.000000e+00
@HUGE_VALF = global double 0.000000e+00
@HUGE_VALL = global double 0.000000e+00
@ERANGE = global i64 0
define i32 @muggle_str_tod(i8* %0, double* writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq double* %1, null
%7 = or i1 %5, %6
br i1 %7, label %32, label %8
8: ; preds = %2
store i64 0, i64* @errno
%9 = call double @strtod(i8* %0, i8** %3)
store double %9, double* %1
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, %0
br i1 %11, label %32, label %12
12: ; preds = %8
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @muggle_str_lstrip_idx(i8* %10)
%17 = icmp eq i32 %16, -1
br i1 %17, label %31, label %32
18: ; preds = %12
%19 = load double, double* @HUGE_VAL
%20 = fcmp oeq double %9, %19
%21 = load double, double* @HUGE_VALF
%22 = fcmp oeq double %9, %21
%23 = select i1 %20, i1 true, i1 %22
%24 = load double, double* @HUGE_VALL
%25 = fcmp oeq double %9, %24
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %31
27: ; preds = %18
%28 = load i64, i64* @errno
%29 = load i64, i64* @ERANGE
%30 = icmp eq i64 %28, %29
br i1 %30, label %32, label %31
31: ; preds = %18, %15, %27
br label %32
32: ; preds = %27, %15, %8, %2, %31
%33 = phi i32 [ 1, %31 ], [ 0, %2 ], [ 0, %8 ], [ 0, %15 ], [ 0, %27 ]
ret i32 %33
}