#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*/ isnan(double);
scalar_t__ issignaling(double);
int /*<<< orphan*/ puts(char const *);
scalar_t__ strcmp(char *, char *);
double strtod(char const *, char **);
int test_strtod(const char str[]) {
  char *endp;
  int result = 0;
  puts(str);
  double d = strtod(str, &endp);
  if (!isnan(d)) {
    puts("strto"
         "d"
         " did not return NAN");
    result = 1;
  }
  if (issignaling(d)) {
    puts("strto"
         "d"
         " returned a sNAN");
    result = 1;
  }
  if (strcmp(endp, "something") != 0) {
    puts("strto"
         "d"
         " set incorrect end pointer");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<test_strtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1070 <isnan@plt>
cmp    $0x0,%eax
jne    11a4 <test_strtod+0x54>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x14(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <issignaling@plt>
cmp    $0x0,%rax
je     11cb <test_strtod+0x7b>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f8 <test_strtod+0xa8>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strtod>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <strtod@plt>
movsd  %xmm0,(%rsp)
call   1070 <isnan@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    118b <test_strtod+0x3b>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
movsd  (%rsp),%xmm0
call   1060 <issignaling@plt>
test   %rax,%rax
je     11ab <test_strtod+0x5b>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    0x8(%rsp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d2 <test_strtod+0x82>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"strtod did not return NAN\00"
@.str.1 = [23 x i8] c"strtod returned a sNAN\00"
@.str.2 = [10 x i8] c"something\00"
@.str.3 = [33 x i8] c"strtod set incorrect end pointer\00"
define i32 @test_strtod(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
store i8* %0, i8** %2
store i32 0, i32* %4
%6 = load i8*, i8** %2
%7 = call i32 @puts(i8* %6)
%8 = load i8*, i8** %2
%9 = call double @strtod(i8* %8, i8** %3)
store double %9, double* %5
%10 = load double, double* %5
%11 = call i32 @isnan(double %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %15
15: ; preds = %13, %1
%16 = load double, double* %5
%17 = call i64 @issignaling(double %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [26 x i8] c"strtod did not return NAN\00"
@.str.1 = [23 x i8] c"strtod returned a sNAN\00"
@.str.2 = [10 x i8] c"something\00"
@.str.3 = [33 x i8] c"strtod set incorrect end pointer\00"
define i32 @test_strtod(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) %0)
%5 = call double @strtod(i8* %0, i8** %2)
%6 = tail call i32 @isnan(double %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = phi i32 [ 0, %1 ], [ 1, %8 ]
%12 = tail call i64 @issignaling(double %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = phi i32 [ 1, %14 ], [ %11, %10 ]
%18 = load i8*, i8** %2
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = phi i32 [ 1, %21 ], [ %17, %16 ]
ret i32 %24
}