#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 */
scalar_t__ atof(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char const *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
float prompt_for_float(const char *prompt) {
  char input[1024];
  char *t;
  int valid;
  while (1) {
    printf(prompt);
    fflush(stdout);
    fgets(input, 1024, stdin);
    valid = 1;
    for (t = input; t < input + 1024; t++) {
      if (*t == 0)
        break;
      if (*t < 20) {
        *t = '\0';
        break;
      }
      if (*t != '.' && (*t < '0' || *t > '9')) {
        valid = 0;
        break;
      }
    }
    if (strlen(input) == 0) {
      valid = 0;
    }
    if (valid) {
      return (float)atof(input);
    }
    printf("Please enter a number\n");
  }
  return 0.0;
}


x86 assembly (clang, -O0):
<prompt_for_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <printf@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
movl   $0x1,-0x41c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
lea    -0x410(%rbp),%rcx
add    $0x400,%rcx
cmp    %rcx,%rax
jae    1264 <prompt_for_float+0x114>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11de <prompt_for_float+0x8e>
jmp    1264 <prompt_for_float+0x114>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x14,%eax
jge    1200 <prompt_for_float+0xb0>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
jmp    1264 <prompt_for_float+0x114>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1248 <prompt_for_float+0xf8>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1239 <prompt_for_float+0xe9>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1248 <prompt_for_float+0xf8>
movl   $0x0,-0x41c(%rbp)
jmp    1264 <prompt_for_float+0x114>
jmp    124d <prompt_for_float+0xfd>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    11a8 <prompt_for_float+0x58>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1284 <prompt_for_float+0x134>
movl   $0x0,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
je     12ab <prompt_for_float+0x15b>
lea    -0x410(%rbp),%rdi
call   1030 <atof@plt>
cvtsi2ss %rax,%xmm0
add    $0x420,%rsp
pop    %rbp
ret
lea    0xd4e(%rip),%rdi
call   1050 <printf@plt>
jmp    115f <prompt_for_float+0xf>

x86 assembly (clang, -O2):
<prompt_for_float>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
lea    0x400(%rsp),%rbx
mov    %rsp,%r12
mov    0x2e62(%rip),%r13
mov    0x2e6b(%rip),%rbp
lea    0xe7c(%rip),%r15
jmp    11a1 <prompt_for_float+0x51>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
jne    11f4 <prompt_for_float+0xa4>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %r12,%rax
jmp    11d9 <prompt_for_float+0x89>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rbx,%rax
jae    1193 <prompt_for_float+0x43>
movzbl (%rax),%ecx
test   %cl,%cl
je     1193 <prompt_for_float+0x43>
cmp    $0x13,%cl
jle    1190 <prompt_for_float+0x40>
cmp    $0x2e,%cl
je     11d0 <prompt_for_float+0x80>
add    $0xc6,%cl
cmp    $0xf6,%cl
jae    11d0 <prompt_for_float+0x80>
jmp    1199 <prompt_for_float+0x49>
mov    %rsp,%rdi
call   1040 <atof@plt>
cvtsi2ss %rax,%xmm0
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@.str = [23 x i8] c"Please enter a number\0A\00"
define float @prompt_for_float(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
br label %6
6: ; preds = %1, %65
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 1024, i32 %12)
store i32 1, i32* %5
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8* %14, i8** %4
br label %15
15: ; preds = %50, %6
%16 = load i8*, i8** %4
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 1024
%19 = icmp ult i8* %16, %18
br i1 %19, label %20, label %53
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %53
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp slt i32 %29, 20
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i8*, i8** %4
store i8 0, i8* %32
br label %53
33: ; preds = %26
%34 = load i8*, i8** %4
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 46
br i1 %37, label %38, label %49
38: ; preds = %33
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp slt i32 %41, 48
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = load i8*, i8** %4
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp sgt i32 %46, 57
br i1 %47, label %48, label %49
48: ; preds = %43, %38
store i32 0, i32* %5
br label %53
49: ; preds = %43, %33
br label %50
50: ; preds = %49
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %4
br label %15
53: ; preds = %48, %31, %25, %15
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%55 = call i64 @strlen(i8* %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %53
store i32 0, i32* %5
br label %58
58: ; preds = %57, %53
%59 = load i32, i32* %5
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%63 = call i64 @atof(i8* %62)
%64 = sitofp i64 %63 to float
ret float %64
65: ; preds = %58
%66 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %6
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@str = [22 x i8] c"Please enter a number\00"
define float @prompt_for_float(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1024
br label %5
5: ; preds = %32, %1
%6 = call i32 @printf(i8* dereferenceable(1) %0)
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %3, i32 1024, i32 %9)
br label %11
11: ; preds = %5, %23
%12 = phi i8* [ %3, %5 ], [ %24, %23 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %11
%16 = icmp slt i8 %13, 20
br i1 %16, label %17, label %18
17: ; preds = %15
store i8 0, i8* %12
br label %26
18: ; preds = %15
%19 = icmp ne i8 %13, 46
%20 = add nsw i8 %13, -58
%21 = icmp ult i8 %20, -10
%22 = and i1 %19, %21
br i1 %22, label %32, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %12, i64 1
%25 = icmp ult i8* %24, %4
br i1 %25, label %11, label %26
26: ; preds = %11, %23, %17
%27 = load i8, i8* %3
%28 = icmp eq i8 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i64 @atof(i8* %3)
%31 = sitofp i64 %30 to float
ret float %31
32: ; preds = %18, %26
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %5
}