#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*/ exit(int);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, float *);
float convert(char *str) {
  float grade;
  int num;
  num = sscanf(str, "%f", &grade);
  if (!num || grade < 0 || grade > 10) {
    printf("Error: grade is not acceptable,bad input.\n");
    exit(1);
  }
  return grade;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xebd(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1180 <convert+0x50>
xorps  %xmm0,%xmm0
ucomiss -0xc(%rbp),%xmm0
ja     1180 <convert+0x50>
movss  -0xc(%rbp),%xmm0
movss  0xe89(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1196 <convert+0x66>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rax
lea    0xecc(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1040 <sscanf@plt>
test   %eax,%eax
je     115f <convert+0x2f>
movss  0x4(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     115f <convert+0x2f>
ucomiss 0xea5(%rip),%xmm0
ja     115f <convert+0x2f>
pop    %rax
ret
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
@.str.1 = [43 x i8] c"Error: grade is not acceptable,bad input.\0A\00"
define float @convert(i8* %0) {
%2 = alloca i8*
%3 = alloca float
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load float, float* %3
%11 = fcmp olt float %10, 0.000000e+00
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load float, float* %3
%14 = fcmp ogt float %13, 1.000000e+01
br i1 %14, label %15, label %18
15: ; preds = %12, %9, %1
%16 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = load float, float* %3
ret float %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
@str = [42 x i8] c"Error: grade is not acceptable,bad input.\00"
define float @convert(i8* nocapture %0) {
%2 = alloca float
%3 = bitcast float* %2 to i8*
%4 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %2)
%5 = icmp eq i32 %4, 0
%6 = load float, float* %2
%7 = fcmp olt float %6, 0.000000e+00
%8 = select i1 %5, i1 true, i1 %7
%9 = fcmp ogt float %6, 1.000000e+01
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
ret float %6
}