#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__ errno;
double strtod(char *, char **);
int as_finite_double(char *str, double *d) {
  char *endptr = NULL;
  errno = 0;
  *d = strtod(str, &endptr);
  if (!endptr || *endptr)
    return 0;
  if (*d == *d && *d + 1 != *d)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<as_finite_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2eb1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1166 <as_finite_double+0x56>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1172 <as_finite_double+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11ca <as_finite_double+0xba>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
ucomisd (%rax),%xmm0
jne    11c3 <as_finite_double+0xb3>
jp     11c3 <as_finite_double+0xb3>
mov    -0x18(%rbp),%rax
movsd  0xe66(%rip),%xmm0
addsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
ucomisd (%rax),%xmm0
jne    11b7 <as_finite_double+0xa7>
jp     11b7 <as_finite_double+0xa7>
jmp    11c3 <as_finite_double+0xb3>
movl   $0x1,-0x4(%rbp)
jmp    11ca <as_finite_double+0xba>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<as_finite_double>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
mov    0x2eb8(%rip),%rax
movq   $0x0,(%rax)
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,(%rbx)
mov    0x8(%rsp),%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1172 <as_finite_double+0x62>
cmpb   $0x0,(%rcx)
jne    1172 <as_finite_double+0x62>
ucomisd %xmm0,%xmm0
setnp  %al
movsd  0xea3(%rip),%xmm1
addsd  %xmm0,%xmm1
ucomisd %xmm0,%xmm1
setp   %cl
setne  %dl
or     %cl,%dl
and    %al,%dl
movzbl %dl,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @as_finite_double(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
store i8* null, i8** %6
store i64 0, i64* @errno
%7 = load i8*, i8** %4
%8 = call double @strtod(i8* %7, i8** %6)
%9 = load double*, double** %5
store double %8, double* %9
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12, %2
store i32 0, i32* %3
br label %33
18: ; preds = %12
%19 = load double*, double** %5
%20 = load double, double* %19
%21 = load double*, double** %5
%22 = load double, double* %21
%23 = fcmp oeq double %20, %22
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = load double*, double** %5
%26 = load double, double* %25
%27 = fadd double %26, 1.000000e+00
%28 = load double*, double** %5
%29 = load double, double* %28
%30 = fcmp une double %27, %29
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %3
br label %33
32: ; preds = %24, %18
store i32 0, i32* %3
br label %33
33: ; preds = %32, %31, %17
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @as_finite_double(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
store i64 0, i64* @errno
%5 = call double @strtod(i8* %0, i8** %3)
store double %5, double* %1
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = fcmp ord double %5, 0.000000e+00
%13 = fadd double %5, 1.000000e+00
%14 = fcmp une double %13, %5
%15 = and i1 %12, %14
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %11, %2, %8
%18 = phi i32 [ 0, %8 ], [ 0, %2 ], [ %16, %11 ]
ret i32 %18
}