#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*/ getLine(char *, int);
int /*<<< orphan*/ isspace(char);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, double *);
double getDouble() {
  char input[15];
  double result;
  int validDouble = 0;
  getLine(input, 15);
  while (validDouble == 0) {
    if (!isspace(input[0]))
      validDouble = sscanf(input, "%lf", &result);
    if (validDouble == 0) {
      printf("Error - Please enter a valid number: ");
      getLine(input, 15);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<getDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x1c(%rbp)
lea    -0xf(%rbp),%rdi
mov    $0xf,%esi
call   1060 <getLine@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11b9 <getDouble+0x79>
movsbl -0xf(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    1190 <getDouble+0x50>
lea    -0xf(%rbp),%rdi
lea    0xe7c(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11b4 <getDouble+0x74>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
lea    -0xf(%rbp),%rdi
mov    $0xf,%esi
call   1060 <getLine@plt>
jmp    115d <getDouble+0x1d>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDouble>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x9(%rsp),%rbx
lea    0xea9(%rip),%r14
mov    %rsp,%r15
lea    0xea3(%rip),%r12
jmp    1178 <getDouble+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
call   1060 <getLine@plt>
movsbl 0x9(%rsp),%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    1170 <getDouble+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <sscanf@plt>
test   %eax,%eax
je     1170 <getDouble+0x30>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
@.str.1 = [38 x i8] c"Error - Please enter a valid number: \00"
define double @getDouble() {
%1 = alloca [15 x i8]
%2 = alloca double
%3 = alloca i32
store i32 0, i32* %3
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%5 = call i32 @getLine(i8* %4, i32 15)
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%11 = load i8, i8* %10
%12 = call i32 @isspace(i8 signext %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %2)
store i32 %16, i32* %3
br label %17
17: ; preds = %14, %9
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%23 = call i32 @getLine(i8* %22, i32 15)
br label %24
24: ; preds = %20, %17
br label %6
25: ; preds = %6
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
@.str.1 = [38 x i8] c"Error - Please enter a valid number: \00"
define double @getDouble() {
%1 = alloca [15 x i8]
%2 = alloca double
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%4 = bitcast double* %2 to i8*
br label %5
5: ; preds = %13, %0
%6 = call i32 @getLine(i8* %3, i32 15)
%7 = load i8, i8* %3
%8 = call i32 @isspace(i8 signext %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10, %5
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %5
15: ; preds = %10
%16 = load double, double* %2
ret double %16
}