#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 **);
int64_t mm_parse_num(const char *str) {
  double x;
  char *p;
  x = strtod(str, &p);
  if (*p == 'G' || *p == 'g')
    x *= 1e9;
  else if (*p == 'M' || *p == 'm')
    x *= 1e6;
  else if (*p == 'K' || *p == 'k')
    x *= 1e3;
  return (int64_t)(x + .499);
}


x86 assembly (clang, -O0):
<mm_parse_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x47,%eax
je     114e <mm_parse_num+0x3e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x67,%eax
jne    1165 <mm_parse_num+0x55>
movsd  0xeba(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11d8 <mm_parse_num+0xc8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
je     1185 <mm_parse_num+0x75>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
jne    119c <mm_parse_num+0x8c>
movsd  0xe7b(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11d3 <mm_parse_num+0xc3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4b,%eax
je     11bc <mm_parse_num+0xac>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6b,%eax
jne    11ce <mm_parse_num+0xbe>
movsd  0xe3c(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11d3 <mm_parse_num+0xc3>
jmp    11d8 <mm_parse_num+0xc8>
movsd  0xe38(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_parse_num>:
push   %rax
mov    %rsp,%rsi
call   1030 <strtod@plt>
mov    (%rsp),%rax
mov    (%rax),%al
add    $0xb9,%al
cmp    $0x26,%al
ja     1174 <mm_parse_num+0x64>
movzbl %al,%eax
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     1162 <mm_parse_num+0x52>
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     116c <mm_parse_num+0x5c>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    1174 <mm_parse_num+0x64>
mulsd  0xea8(%rip),%xmm0
jmp    1174 <mm_parse_num+0x64>
mulsd  0xea6(%rip),%xmm0
jmp    1174 <mm_parse_num+0x64>
mulsd  0xe8c(%rip),%xmm0
addsd  0xe9c(%rip),%xmm0
cvttsd2si %xmm0,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @mm_parse_num(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call double @strtod(i8* %5, i8** %4)
store double %6, double* %3
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 71
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 103
br i1 %15, label %16, label %19
16: ; preds = %11, %1
%17 = load double, double* %3
%18 = fmul double %17, 1.000000e+09
store double %18, double* %3
br label %47
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 77
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 109
br i1 %28, label %29, label %32
29: ; preds = %24, %19
%30 = load double, double* %3
%31 = fmul double %30, 1.000000e+06
store double %31, double* %3
br label %46
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 75
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 107
br i1 %41, label %42, label %45
42: ; preds = %37, %32
%43 = load double, double* %3
%44 = fmul double %43, 1.000000e+03
store double %44, double* %3
br label %45
45: ; preds = %42, %37
br label %46
46: ; preds = %45, %29
br label %47
47: ; preds = %46, %16
%48 = load double, double* %3
%49 = fadd double %48, 4.990000e-01
%50 = fptosi double %49 to i32
ret i32 %50
}

LLVM IR (-O2):
define i32 @mm_parse_num(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call double @strtod(i8* %0, i8** %2)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
switch i8 %6, label %13 [
i8 71, label %7
i8 103, label %7
i8 77, label %9
i8 109, label %9
i8 75, label %11
i8 107, label %11
]
7: ; preds = %1, %1
%8 = fmul double %4, 1.000000e+09
br label %13
9: ; preds = %1, %1
%10 = fmul double %4, 1.000000e+06
br label %13
11: ; preds = %1, %1
%12 = fmul double %4, 1.000000e+03
br label %13
13: ; preds = %1, %9, %11, %7
%14 = phi double [ %8, %7 ], [ %10, %9 ], [ %12, %11 ], [ %4, %1 ]
%15 = fadd double %14, 4.990000e-01
%16 = fptosi double %15 to i32
ret i32 %16
}