#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 */
typedef unsigned int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void *strtoul(char const *, char **, int);
float get_testfloat(const char *str) {
  char *endptr;
  unsigned exp;
  union {
    uint32_t uns32;
    float float32;
  } val;
  exp = strtoul(str, &endptr, 16);
  if (*endptr != '.') {
    fprintf(stderr, "%s: bad format\n", endptr);
    exit(-1);
  }
  val.uns32 = strtoul(endptr + 1, 0, 16);
  val.uns32 |= exp << 23;
  return (exp & 0x800) ? -val.float32 : val.float32;
}


x86 assembly (clang, -O0):
<get_testfloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1184 <get_testfloat+0x54>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x17,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x800,%eax
cmp    $0x0,%eax
je     11d6 <get_testfloat+0xa6>
movss  -0x18(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11e0 <get_testfloat+0xb0>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_testfloat>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    0x8(%rsp),%rdx
cmpb   $0x2e,(%rdx)
jne    1185 <get_testfloat+0x55>
mov    %rax,%rbx
add    $0x1,%rdx
mov    %rdx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %ebx,%ecx
shl    $0x17,%ecx
or     %eax,%ecx
movd   %ecx,%xmm0
test   $0x800,%ebx
je     117f <get_testfloat+0x4f>
pxor   0xe81(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%union.anon = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"%s: bad format\0A\00"
define float @get_testfloat(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %union.anon
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strtoul(i8* %6, i8** %3, i32 16)
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %4
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 46
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i8* @strtoul(i8* %20, i8** null, i32 16)
%22 = ptrtoint i8* %21 to i32
%23 = bitcast %union.anon* %5 to i32*
store i32 %22, i32* %23
%24 = load i32, i32* %4
%25 = shl i32 %24, 23
%26 = bitcast %union.anon* %5 to i32*
%27 = load i32, i32* %26
%28 = or i32 %27, %25
store i32 %28, i32* %26
%29 = load i32, i32* %4
%30 = and i32 %29, 2048
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %18
%33 = bitcast %union.anon* %5 to float*
%34 = load float, float* %33
%35 = fneg float %34
br label %39
36: ; preds = %18
%37 = bitcast %union.anon* %5 to float*
%38 = load float, float* %37
br label %39
39: ; preds = %36, %32
%40 = phi float [ %35, %32 ], [ %38, %36 ]
ret float %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"%s: bad format\0A\00"
define float @get_testfloat(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i8* @strtoul(i8* %0, i8** %2, i32 16)
%5 = ptrtoint i8* %4 to i64
%6 = trunc i64 %5 to i32
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 46
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %7)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = tail call i8* @strtoul(i8* nocapture %15, i8** null, i32 16)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
%19 = shl i32 %6, 23
%20 = or i32 %19, %18
%21 = and i32 %6, 2048
%22 = icmp eq i32 %21, 0
%23 = bitcast i32 %20 to float
%24 = fneg float %23
%25 = select i1 %22, float %23, float %24
ret float %25
}