#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 */
char EOF;
char getchar();
int scanf(char *, double *);
void stub1();
int ReadDouble(double *OutResult, void (*OnInvalidInput)(void)) {
  if (!OutResult) {
    return 1;
  }
  while (scanf("%Lf", OutResult) < 1) {
    char c = '\0';
    while ((c = getchar()) != '\n' && c != EOF) {
      continue;
    }
    if (OnInvalidInput)
      (*OnInvalidInput)();
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<ReadDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <ReadDouble+0x27>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <ReadDouble+0xb0>
jmp    114c <ReadDouble+0x2c>
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jge    11c2 <ReadDouble+0xa2>
movb   $0x0,-0x19(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1a(%rbp)
je     119a <ReadDouble+0x7a>
movsbl -0x19(%rbp),%eax
mov    0x2e59(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11aa <ReadDouble+0x8a>
jmp    11af <ReadDouble+0x8f>
jmp    1169 <ReadDouble+0x49>
cmpq   $0x0,-0x18(%rbp)
je     11bd <ReadDouble+0x9d>
call   *-0x18(%rbp)
jmp    114c <ReadDouble+0x2c>
mov    $0x0,%al
call   1030 <getchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadDouble>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1151 <ReadDouble+0x31>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xec6(%rip),%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
test   %eax,%eax
jle    1164 <ReadDouble+0x44>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
jmp    1156 <ReadDouble+0x36>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e7d(%rip),%r12
lea    0xe8e(%rip),%r15
jmp    118f <ReadDouble+0x6f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
test   %eax,%eax
jg     1146 <ReadDouble+0x26>
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     11a0 <ReadDouble+0x80>
cmp    (%r12),%al
jne    118f <ReadDouble+0x6f>
test   %rbx,%rbx
je     1180 <ReadDouble+0x60>
call   *%rbx
jmp    1180 <ReadDouble+0x60>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%Lf\00"
@EOF = global i8 0
define i32 @ReadDouble(double* %0, void ()* %1) {
%3 = icmp eq double* %0, null
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %0)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = icmp eq void ()* %1, null
br label %9
9: ; preds = %15, %7
%10 = tail call signext i8 (...) @getchar()
%11 = icmp ne i8 %10, 10
%12 = load i8, i8* @EOF
%13 = icmp ne i8 %10, %12
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %16
15: ; preds = %9, %18
br label %9
16: ; preds = %9
br i1 %8, label %18, label %17
17: ; preds = %16
tail call void %1()
br label %18
18: ; preds = %17, %16
%19 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %0)
%20 = icmp slt i32 %19, 1
br i1 %20, label %15, label %21
21: ; preds = %18, %4
%22 = tail call signext i8 (...) @getchar()
br label %23
23: ; preds = %2, %21
%24 = phi i32 [ 0, %21 ], [ 1, %2 ]
ret i32 %24
}