#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 double uint64_t;

/* Variables and functions */
scalar_t__ isspace(char);
double strtod(char const *, char **);
int tolower(char);
bool volume_str_to_size(const char *str, uint64_t *size) {
  double ap;
  char *ptr;
  if ((ap = strtod(str, &ptr)) < 0)
    return false;
  for (; isspace(*ptr); ptr++)
    continue;
  switch (tolower(*ptr)) {
  default:
    return false;
  case 'p':
    ap *= 1024;
  case 't':
    ap *= 1024;
  case 'g':
    ap *= 1024;
  case 'm':
    ap *= 1024;
  case 'k':
    ap *= 1024;
  case 'i':
  case 'b':
    break;
  }
  *size = ap;
  return true;
}


x86 assembly (clang, -O0):
<volume_str_to_size>:
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 <strtod@plt>
movaps %xmm0,%xmm1
movsd  %xmm1,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    116e <volume_str_to_size+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1250 <volume_str_to_size+0x120>
jmp    1173 <volume_str_to_size+0x43>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     119f <volume_str_to_size+0x6f>
jmp    118e <volume_str_to_size+0x5e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1173 <volume_str_to_size+0x43>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x12,%eax
ja     11d1 <volume_str_to_size+0xa1>
mov    -0x30(%rbp),%rax
lea    0xe40(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    1250 <volume_str_to_size+0x120>
movsd  0xe1b(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe09(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdf7(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xde5(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdd3(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    123c <volume_str_to_size+0x10c>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<volume_str_to_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11c9 <volume_str_to_size+0x99>
movsd  %xmm0,(%rsp)
mov    0x8(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <volume_str_to_size+0x30>
movsbl -0x1(%rbx),%edi
call   1050 <tolower@plt>
add    $0xffffff9e,%eax
cmp    $0x12,%eax
ja     11c9 <volume_str_to_size+0x99>
lea    0xe7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
movsd  (%rsp),%xmm0
jmp    *%rax
mulsd  0xe61(%rip),%xmm0
mulsd  0xe59(%rip),%xmm0
mulsd  0xe51(%rip),%xmm0
mulsd  0xe49(%rip),%xmm0
mulsd  0xe41(%rip),%xmm0
movsd  %xmm0,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @volume_str_to_size(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca double
%7 = alloca i8*
store i8* %0, i8** %4
store double* %1, double** %5
%8 = load i8*, i8** %4
%9 = call double @strtod(i8* %8, i8** %7)
store double %9, double* %6
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %46
12: ; preds = %2
br label %13
13: ; preds = %19, %12
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = call i64 @isspace(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
br label %19
19: ; preds = %18
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %7
br label %13
22: ; preds = %13
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = call i32 @tolower(i8 signext %24)
switch i32 %25, label %26 [
i32 112, label %27
i32 116, label %30
i32 103, label %33
i32 109, label %36
i32 107, label %39
i32 105, label %42
i32 98, label %42
]
26: ; preds = %22
store i32 0, i32* %3
br label %46
27: ; preds = %22
%28 = load double, double* %6
%29 = fmul double %28, 1.024000e+03
store double %29, double* %6
br label %30
30: ; preds = %22, %27
%31 = load double, double* %6
%32 = fmul double %31, 1.024000e+03
store double %32, double* %6
br label %33
33: ; preds = %22, %30
%34 = load double, double* %6
%35 = fmul double %34, 1.024000e+03
store double %35, double* %6
br label %36
36: ; preds = %22, %33
%37 = load double, double* %6
%38 = fmul double %37, 1.024000e+03
store double %38, double* %6
br label %39
39: ; preds = %22, %36
%40 = load double, double* %6
%41 = fmul double %40, 1.024000e+03
store double %41, double* %6
br label %42
42: ; preds = %22, %22, %39
br label %43
43: ; preds = %42
%44 = load double, double* %6
%45 = load double*, double** %5
store double %44, double* %45
store i32 1, i32* %3
br label %46
46: ; preds = %43, %26, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @volume_str_to_size(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call double @strtod(i8* %0, i8** %3)
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %34, label %7
7: ; preds = %2
%8 = load i8*, i8** %3
br label %9
9: ; preds = %9, %7
%10 = phi i8* [ %8, %7 ], [ %14, %9 ]
%11 = load i8, i8* %10
%12 = tail call i64 @isspace(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = load i8, i8* %10
%17 = tail call i32 @tolower(i8 signext %16)
switch i32 %17, label %34 [
i32 112, label %18
i32 116, label %20
i32 103, label %23
i32 109, label %26
i32 107, label %29
i32 105, label %32
i32 98, label %32
]
18: ; preds = %15
%19 = fmul double %5, 1.024000e+03
br label %20
20: ; preds = %15, %18
%21 = phi double [ %5, %15 ], [ %19, %18 ]
%22 = fmul double %21, 1.024000e+03
br label %23
23: ; preds = %15, %20
%24 = phi double [ %5, %15 ], [ %22, %20 ]
%25 = fmul double %24, 1.024000e+03
br label %26
26: ; preds = %15, %23
%27 = phi double [ %5, %15 ], [ %25, %23 ]
%28 = fmul double %27, 1.024000e+03
br label %29
29: ; preds = %15, %26
%30 = phi double [ %5, %15 ], [ %28, %26 ]
%31 = fmul double %30, 1.024000e+03
br label %32
32: ; preds = %29, %15, %15
%33 = phi double [ %5, %15 ], [ %5, %15 ], [ %31, %29 ]
store double %33, double* %1
br label %34
34: ; preds = %15, %2, %32
%35 = phi i32 [ 1, %32 ], [ 0, %2 ], [ 0, %15 ]
ret i32 %35
}