#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*/ int64_t;

/* Variables and functions */
double strtod(char const *, char **);
int toupper(char);
int64_t parseBytes(const char *value, unsigned long unit) {
  char *p = NULL;
  double bytes;
  bytes = strtod(value, &p);
  if (p != NULL) {
    switch (toupper(*p)) {
    case 'E':
      bytes *= 1024;
    case 'P':
      bytes *= 1024;
    case 'T':
      bytes *= 1024;
    case 'G':
      bytes *= 1024;
    case 'M':
      bytes *= 1024;
    case 'K':
      bytes *= 1024;
      break;
    }
  }
  return ((int64_t)(unit > 1 ? (bytes / unit) : bytes));
}


x86 assembly (clang, -O0):
<parseBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f8 <parseBytes+0xd8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
add    $0xffffffbb,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0xf,%eax
ja     11f3 <parseBytes+0xd3>
mov    -0x28(%rbp),%rax
lea    0xeb2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0xe71(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe5f(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe4d(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe3b(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe29(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe17(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11f8 <parseBytes+0xd8>
cmpq   $0x1,-0x10(%rbp)
jbe    123d <parseBytes+0x11d>
movsd  -0x20(%rbp),%xmm0
movaps 0xe01(%rip),%xmm2
movq   -0x10(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe00(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1247 <parseBytes+0x127>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseBytes>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1040 <strtod@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     119f <parseBytes+0x7f>
movsd  %xmm0,(%rsp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
add    $0xffffffbb,%eax
cmp    $0xf,%eax
ja     11d4 <parseBytes+0xb4>
lea    0xecf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
movsd  (%rsp),%xmm0
jmp    *%rax
mulsd  0xe89(%rip),%xmm0
mulsd  0xe81(%rip),%xmm0
mulsd  0xe79(%rip),%xmm0
mulsd  0xe71(%rip),%xmm0
mulsd  0xe69(%rip),%xmm0
mulsd  0xe61(%rip),%xmm0
cmp    $0x2,%rbx
jb     11ca <parseBytes+0xaa>
movq   %rbx,%xmm2
punpckldq 0xe5e(%rip),%xmm2
subpd  0xe66(%rip),%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbx
ret
movsd  (%rsp),%xmm0
cmp    $0x2,%rbx
jae    11a5 <parseBytes+0x85>
jmp    11ca <parseBytes+0xaa>

LLVM IR (-O0):
define i32 @parseBytes(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca double
store i8* %0, i8** %3
store i64 %1, i64* %4
store i8* null, i8** %5
%7 = load i8*, i8** %3
%8 = call double @strtod(i8* %7, i8** %5)
store double %8, double* %6
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %34
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = call i32 @toupper(i8 signext %13)
switch i32 %14, label %33 [
i32 69, label %15
i32 80, label %18
i32 84, label %21
i32 71, label %24
i32 77, label %27
i32 75, label %30
]
15: ; preds = %11
%16 = load double, double* %6
%17 = fmul double %16, 1.024000e+03
store double %17, double* %6
br label %18
18: ; preds = %11, %15
%19 = load double, double* %6
%20 = fmul double %19, 1.024000e+03
store double %20, double* %6
br label %21
21: ; preds = %11, %18
%22 = load double, double* %6
%23 = fmul double %22, 1.024000e+03
store double %23, double* %6
br label %24
24: ; preds = %11, %21
%25 = load double, double* %6
%26 = fmul double %25, 1.024000e+03
store double %26, double* %6
br label %27
27: ; preds = %11, %24
%28 = load double, double* %6
%29 = fmul double %28, 1.024000e+03
store double %29, double* %6
br label %30
30: ; preds = %11, %27
%31 = load double, double* %6
%32 = fmul double %31, 1.024000e+03
store double %32, double* %6
br label %33
33: ; preds = %11, %30
br label %34
34: ; preds = %33, %2
%35 = load i64, i64* %4
%36 = icmp ugt i64 %35, 1
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load double, double* %6
%39 = load i64, i64* %4
%40 = uitofp i64 %39 to double
%41 = fdiv double %38, %40
br label %44
42: ; preds = %34
%43 = load double, double* %6
br label %44
44: ; preds = %42, %37
%45 = phi double [ %41, %37 ], [ %43, %42 ]
%46 = fptosi double %45 to i32
ret i32 %46
}

LLVM IR (-O2):
define i32 @parseBytes(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %28, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = tail call i32 @toupper(i8 signext %9)
switch i32 %10, label %28 [
i32 69, label %11
i32 80, label %13
i32 84, label %16
i32 71, label %19
i32 77, label %22
i32 75, label %25
]
11: ; preds = %8
%12 = fmul double %5, 1.024000e+03
br label %13
13: ; preds = %8, %11
%14 = phi double [ %5, %8 ], [ %12, %11 ]
%15 = fmul double %14, 1.024000e+03
br label %16
16: ; preds = %8, %13
%17 = phi double [ %5, %8 ], [ %15, %13 ]
%18 = fmul double %17, 1.024000e+03
br label %19
19: ; preds = %8, %16
%20 = phi double [ %5, %8 ], [ %18, %16 ]
%21 = fmul double %20, 1.024000e+03
br label %22
22: ; preds = %8, %19
%23 = phi double [ %5, %8 ], [ %21, %19 ]
%24 = fmul double %23, 1.024000e+03
br label %25
25: ; preds = %8, %22
%26 = phi double [ %5, %8 ], [ %24, %22 ]
%27 = fmul double %26, 1.024000e+03
br label %28
28: ; preds = %25, %8, %2
%29 = phi double [ %5, %8 ], [ %27, %25 ], [ %5, %2 ]
%30 = icmp ugt i64 %1, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = uitofp i64 %1 to double
%33 = fdiv double %29, %32
br label %34
34: ; preds = %28, %31
%35 = phi double [ %33, %31 ], [ %29, %28 ]
%36 = fptosi double %35 to i32
ret i32 %36
}