#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*/ Fail(char *, ...);
int sscanf(char *, char const *, char *);
void DoFloatTest(char *inputstr, const char *formatstr, float checkval) {
  char buf[256] = {0};
  float val;
  int ret;
  int i;
  for (i = 0; i < 256; i++)
    buf[i] = (char)-1;
  ret = sscanf(inputstr, formatstr, buf);
  val = *(float *)buf;
  if (ret != 1) {
    Fail("ERROR: Expected sscanf to return 1, got %d.\n"
         "Using \"%s\" in \"%s\".\n",
         ret, inputstr, formatstr);
  }
  if (val != checkval) {
    Fail("ERROR: scanned float incorrectly from \"%s\" using \"%s\".\n"
         "Expected \"%f\", got \"%f\".\n",
         inputstr, formatstr, checkval, val);
  }
  if (buf[4] != (char)-1) {
    Fail("ERROR: overflow occurred in scanning float from \"%s\" "
         "using \"%s\".\n",
         inputstr, formatstr);
  }
}


x86 assembly (clang, -O0):
<DoFloatTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
movl   $0x0,-0x12c(%rbp)
cmpl   $0x100,-0x12c(%rbp)
jge    1198 <DoFloatTest+0x68>
movslq -0x12c(%rbp),%rax
movb   $0xff,-0x120(%rbp,%rax,1)
ff
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
jmp    1165 <DoFloatTest+0x35>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x120(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x128(%rbp)
movss  -0x120(%rbp),%xmm0
ff
movss  %xmm0,-0x124(%rbp)
ff
cmpl   $0x1,-0x128(%rbp)
je     11eb <DoFloatTest+0xbb>
mov    -0x128(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
movss  -0x124(%rbp),%xmm0
ff
ucomiss -0x14(%rbp),%xmm0
jne    1208 <DoFloatTest+0xd8>
jp     1208 <DoFloatTest+0xd8>
jmp    1233 <DoFloatTest+0x103>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x124(%rbp),%xmm1
ff
cvtss2sd %xmm1,%xmm1
lea    0xe15(%rip),%rdi
mov    $0x2,%al
call   1050 <Fail@plt>
movsbl -0x11c(%rbp),%eax
cmp    $0xffffffff,%eax
je     1259 <DoFloatTest+0x129>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoFloatTest>:
push   %r14
push   %rbx
sub    $0x118,%rsp
movd   %xmm0,0xc(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
pcmpeqd %xmm0,%xmm0
movdqa %xmm0,0x100(%rsp)
movdqa %xmm0,0xf0(%rsp)
movdqa %xmm0,0xe0(%rsp)
movdqa %xmm0,0xd0(%rsp)
movdqa %xmm0,0xc0(%rsp)
movdqa %xmm0,0xb0(%rsp)
movdqa %xmm0,0xa0(%rsp)
movdqa %xmm0,0x90(%rsp)
movdqa %xmm0,0x80(%rsp)
movdqa %xmm0,0x70(%rsp)
movdqa %xmm0,0x60(%rsp)
movdqa %xmm0,0x50(%rsp)
movdqa %xmm0,0x40(%rsp)
movdqa %xmm0,0x30(%rsp)
movdqa %xmm0,0x20(%rsp)
movdqa %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdx
call   1030 <sscanf@plt>
movss  0x10(%rsp),%xmm1
cmp    $0x1,%eax
je     11ec <DoFloatTest+0xcc>
lea    0xe2f(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
movss  %xmm1,0x8(%rsp)
call   1040 <Fail@plt>
movss  0x8(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
ucomiss %xmm0,%xmm1
jne    11f9 <DoFloatTest+0xd9>
jnp    1215 <DoFloatTest+0xf5>
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
lea    0xe39(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    $0x2,%al
call   1040 <Fail@plt>
cmpb   $0xff,0x14(%rsp)
je     1230 <DoFloatTest+0x110>
lea    0xe6f(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <Fail@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [65 x i8] c"ERROR: Expected sscanf to return 1, got %d.\0AUsing \22%s\22 in \22%s\22.\0A\00"
@.str.1 = [81 x i8] c"ERROR: scanned float incorrectly from \22%s\22 using \22%s\22.\0AExpected \22%f\22, got \22%f\22.\0A\00"
@.str.2 = [66 x i8] c"ERROR: overflow occurred in scanning float from \22%s\22 using \22%s\22.\0A\00"
define void @DoFloatTest(i8* %0, i8* %1, float %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca float
%7 = alloca [256 x i8]
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store float %2, float* %6
%11 = bitcast [256 x i8]* %7 to i8*
store i32 0, i32* %10
br label %12
12: ; preds = %19, %3
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 256
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %17
store i8 -1, i8* %18
br label %19
19: ; preds = %15
%20 = load i32, i32* %10
%21 = add nsw i32 %20, 1
store i32 %21, i32* %10
br label %12
22: ; preds = %12
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 @sscanf(i8* %23, i8* %24, i8* %25)
store i32 %26, i32* %9
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = bitcast i8* %27 to float*
%29 = load float, float* %28
store float %29, float* %8
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %22
%33 = load i32, i32* %9
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %33, i8* %34, i8* %35)
br label %37
37: ; preds = %32, %22
%38 = load float, float* %8
%39 = load float, float* %6
%40 = fcmp une float %38, %39
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = load float, float* %6
%45 = fpext float %44 to double
%46 = load float, float* %8
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43, double %45, double %47)
br label %49
49: ; preds = %41, %37
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 4
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i8*, i8** %4
%56 = load i8*, i8** %5
%57 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %55, i8* %56)
br label %58
58: ; preds = %54, %49
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"ERROR: Expected sscanf to return 1, got %d.\0AUsing \22%s\22 in \22%s\22.\0A\00"
@.str.1 = [81 x i8] c"ERROR: scanned float incorrectly from \22%s\22 using \22%s\22.\0AExpected \22%f\22, got \22%f\22.\0A\00"
@.str.2 = [66 x i8] c"ERROR: overflow occurred in scanning float from \22%s\22 using \22%s\22.\0A\00"
define void @DoFloatTest(i8* %0, i8* %1, float %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @sscanf(i8* %0, i8* %1, i8* %6)
%8 = bitcast [256 x i8]* %4 to float*
%9 = load float, float* %8
%10 = icmp eq i32 %7, 1
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %0, i8* %1)
br label %13
13: ; preds = %11, %3
%14 = fcmp une float %9, %2
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = fpext float %2 to double
%17 = fpext float %9 to double
%18 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, double %16, double %17)
br label %19
19: ; preds = %15, %13
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 4
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, -1
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %25
25: ; preds = %23, %19
ret void
}