#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 int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ round(double);
double sizestrtod(char const *, char const **);
int hdd_size_parse(const char *str, uint64_t *ret) {
  double val;
  const char *endptr;
  val = sizestrtod(str, &endptr);
  if (endptr[0] == '\0' || (endptr[0] == 'B' && endptr[1] == '\0')) {
    if (val > 18446744073709551615.0) {
      return -2;
    }
    *ret = round(val);
    return 1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<hdd_size_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <sizestrtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1173 <hdd_size_parse+0x53>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x42,%eax
jne    11b4 <hdd_size_parse+0x94>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    11b4 <hdd_size_parse+0x94>
movsd  -0x20(%rbp),%xmm0
movsd  0xe80(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1196 <hdd_size_parse+0x76>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11bb <hdd_size_parse+0x9b>
movsd  -0x20(%rbp),%xmm0
call   1040 <round@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11bb <hdd_size_parse+0x9b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdd_size_parse>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <sizestrtod@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%dl
test   %dl,%dl
je     114d <hdd_size_parse+0x2d>
mov    $0xffffffff,%eax
cmp    $0x42,%dl
jne    1168 <hdd_size_parse+0x48>
cmpb   $0x0,0x1(%rcx)
jne    1168 <hdd_size_parse+0x48>
mov    $0xfffffffe,%eax
ucomisd 0xea6(%rip),%xmm0
ja     1168 <hdd_size_parse+0x48>
call   1040 <round@plt>
mov    %eax,(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hdd_size_parse(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca double
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call double @sizestrtod(i8* %8, i8** %7)
store double %9, double* %6
%10 = load i8*, i8** %7
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 66
br i1 %20, label %21, label %35
21: ; preds = %15
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %21, %2
%28 = load double, double* %6
%29 = fcmp ogt double %28, 0x43F0000000000000
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 -2, i32* %3
br label %36
31: ; preds = %27
%32 = load double, double* %6
%33 = call i32 @round(double %32)
%34 = load i32*, i32** %5
store i32 %33, i32* %34
store i32 1, i32* %3
br label %36
35: ; preds = %21, %15
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %31, %30
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @hdd_size_parse(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call double @sizestrtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
switch i8 %7, label %16 [
i8 0, label %12
i8 66, label %8
]
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2, %8
%13 = fcmp ogt double %5, 0x43F0000000000000
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = call i32 @round(double %5)
store i32 %15, i32* %1
br label %16
16: ; preds = %8, %2, %12, %14
%17 = phi i32 [ 1, %14 ], [ -2, %12 ], [ -1, %2 ], [ -1, %8 ]
ret i32 %17
}