#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*/ keybFlush();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, double *, char *);
double getDouble() {
  double val;
  char nl = 'x';
  while (nl != '\n') {
    scanf("%lf%c", &val, &nl);
    if (nl != '\n') {
      keybFlush();
      printf("Invalid number, please try again: ");
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<getDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x78,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1182 <getDouble+0x52>
lea    0xeb0(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x9(%rbp),%rdx
call   1050 <scanf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     117d <getDouble+0x4d>
mov    $0x0,%al
call   1040 <keybFlush@plt>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    113c <getDouble+0xc>
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDouble>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x78,0xf(%rsp)
lea    0xeb9(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xf(%rsp),%r12
lea    0xeae(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <scanf@plt>
cmpb   $0xa,0xf(%rsp)
je     118b <getDouble+0x5b>
xor    %eax,%eax
call   1040 <keybFlush@plt>
mov    %rbx,%rdi
call   1030 <printf@plt>
cmpb   $0xa,0xf(%rsp)
jne    1160 <getDouble+0x30>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%lf%c\00"
@.str.1 = [35 x i8] c"Invalid number, please try again: \00"
define double @getDouble() {
%1 = alloca double
%2 = alloca i8
store i8 120, i8* %2
br label %3
3: ; preds = %15, %0
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp ne i32 %5, 10
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double* %1, i8* %2)
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i32 (...) @keybFlush()
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %7
br label %3
16: ; preds = %3
%17 = load double, double* %1
ret double %17
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lf%c\00"
@.str.1 = [35 x i8] c"Invalid number, please try again: \00"
define double @getDouble() {
%1 = alloca double
%2 = alloca i8
%3 = bitcast double* %1 to i8*
store i8 120, i8* %2
br label %4
4: ; preds = %0, %8
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double* %1, i8* %2)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 10
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = call i32 (...) @keybFlush()
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %4
13: ; preds = %4, %8
%14 = load double, double* %1
ret double %14
}