#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 *ask4str(char const *);
int /*<<< orphan*/ show_msg(char *);
int /*<<< orphan*/ sscanf(char *, char *, float *);
scalar_t__ strcspn(char *, char *);
float get_float(const char *prompt) {
  char *line;
  float f;
  if (!(*(line = ask4str(prompt))))
    return -1;
  if (strcspn(line, ",.1234567890")) {
    show_msg("\aNot valid");
    return -1;
  }
  sscanf(line, "%f", &f);
  return f;
}


x86 assembly (clang, -O0):
<get_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ask4str@plt>
mov    %rax,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    1174 <get_float+0x34>
movss  0xe96(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ca <get_float+0x8a>
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1030 <strcspn@plt>
cmp    $0x0,%rax
je     11ac <get_float+0x6c>
lea    0xe7c(%rip),%rdi
call   1040 <show_msg@plt>
movss  0xe5e(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ca <get_float+0x8a>
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_float>:
push   %rbx
sub    $0x10,%rsp
call   1050 <ask4str@plt>
movss  0xeae(%rip),%xmm0
cmpb   $0x0,(%rax)
je     119e <get_float+0x5e>
mov    %rax,%rbx
lea    0xea3(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcspn@plt>
test   %rax,%rax
je     1184 <get_float+0x44>
lea    0xe9c(%rip),%rdi
call   1040 <show_msg@plt>
movss  0xe7e(%rip),%xmm0
jmp    119e <get_float+0x5e>
lea    0xe91(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
movss  0xc(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c",.1234567890\00"
@.str.1 = [11 x i8] c"\07Not valid\00"
@.str.2 = [3 x i8] c"%f\00"
define float @get_float(i8* %0) {
%2 = alloca float
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca float
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @ask4str(i8* %6)
store i8* %7, i8** %4
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store float -1.000000e+00, float* %2
br label %21
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i64 @strcspn(i8* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @show_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store float -1.000000e+00, float* %2
br label %21
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%20 = load float, float* %5
store float %20, float* %2
br label %21
21: ; preds = %17, %15, %10
%22 = load float, float* %2
ret float %22
}

LLVM IR (-O2):
@.str = [13 x i8] c",.1234567890\00"
@.str.1 = [11 x i8] c"\07Not valid\00"
@.str.2 = [3 x i8] c"%f\00"
define float @get_float(i8* %0) {
%2 = alloca float
%3 = bitcast float* %2 to i8*
%4 = tail call i8* @ask4str(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = tail call i64 @strcspn(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @show_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %7
%13 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %2)
%14 = load float, float* %2
br label %15
15: ; preds = %1, %12, %10
%16 = phi float [ -1.000000e+00, %10 ], [ %14, %12 ], [ -1.000000e+00, %1 ]
ret float %16
}