#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*/ isdigit(char);
int sscanf(char *, char *, double *);
int read_double(char *ptr, double *val) {
  int nvals;
  while (*ptr != '-' && *ptr != '.' && !isdigit(*ptr) && *ptr != '\0') {
    ptr++;
  }
  nvals = sscanf(ptr, "%lf", val);
  if (nvals != 1) {
    return (0);
  } else {
    return (1);
  }
}


x86 assembly (clang, -O0):
<read_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2d,%ecx
mov    %al,-0x1d(%rbp)
je     1186 <read_double+0x66>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x1d(%rbp)
je     1186 <read_double+0x66>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1186 <read_double+0x66>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1196 <read_double+0x76>
jmp    11a7 <read_double+0x87>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <read_double+0x10>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     11d4 <read_double+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    11db <read_double+0xbb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_double>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%al
lea    -0x2d(%rax),%ecx
cmp    $0x2,%cl
jb     1161 <read_double+0x41>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    1161 <read_double+0x41>
cmpb   $0x0,(%rbx)
je     1161 <read_double+0x41>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
lea    -0x2d(%rax),%ecx
cmp    $0x1,%cl
ja     1140 <read_double+0x20>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i32 @read_double(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
br label %7
7: ; preds = %29, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 45
br i1 %11, label %12, label %27
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 46
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = call i32 @isdigit(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br label %27
27: ; preds = %22, %17, %12, %7
%28 = phi i1 [ false, %17 ], [ false, %12 ], [ false, %7 ], [ %26, %22 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
br label %7
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = load double*, double** %5
%35 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 0, i32* %3
br label %40
39: ; preds = %32
store i32 1, i32* %3
br label %40
40: ; preds = %39, %38
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i32 @read_double(i8* nocapture %0, double* %1) {
%3 = load i8, i8* %0
%4 = add i8 %3, -45
%5 = icmp ult i8 %4, 2
br i1 %5, label %19, label %6
6: ; preds = %2, %14
%7 = phi i8 [ %16, %14 ], [ %3, %2 ]
%8 = phi i8* [ %15, %14 ], [ %0, %2 ]
%9 = tail call i32 @isdigit(i8 signext %7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i8, i8* %8
%13 = icmp eq i8 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = load i8, i8* %15
%17 = add i8 %16, -45
%18 = icmp ult i8 %17, 2
br i1 %18, label %19, label %6
19: ; preds = %11, %6, %14, %2
%20 = phi i8* [ %0, %2 ], [ %15, %14 ], [ %8, %6 ], [ %8, %11 ]
%21 = tail call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %1)
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
ret i32 %23
}