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

/* Variables and functions */
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
unsigned long str_to_num(const char *str) {
  char *s = (char *)str;
  unsigned long num = strtoul(s, &s, 0);
  if (s) {
    if (s[0] == 'K')
      num <<= 10;
    if (s[0] == 'M')
      num <<= 20;
  }
  return num;
}


x86 assembly (clang, -O0):
<str_to_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117f <str_to_num+0x6f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4b,%eax
jne    115e <str_to_num+0x4e>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
jne    117a <str_to_num+0x6a>
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
jmp    117f <str_to_num+0x6f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_num>:
push   %rax
mov    %rdi,(%rsp)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     1146 <str_to_num+0x36>
mov    (%rcx),%cl
mov    %rax,%rdx
shl    $0xa,%rdx
cmp    $0x4b,%cl
cmovne %rax,%rdx
mov    %rdx,%rax
shl    $0x14,%rax
cmp    $0x4d,%cl
cmovne %rdx,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @str_to_num(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strtoul(i8* %6, i8** %3, i32 0)
store i64 %7, i64* %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 75
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i64, i64* %4
%18 = shl i64 %17, 10
store i64 %18, i64* %4
br label %19
19: ; preds = %16, %10
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 77
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i64, i64* %4
%27 = shl i64 %26, 20
store i64 %27, i64* %4
br label %28
28: ; preds = %25, %19
br label %29
29: ; preds = %28, %1
%30 = load i64, i64* %4
ret i64 %30
}

LLVM IR (-O2):
define i64 @str_to_num(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* %0, i8** %2
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 75
%10 = shl i64 %4, 10
%11 = select i1 %9, i64 %10, i64 %4
%12 = icmp eq i8 %8, 77
%13 = shl i64 %11, 20
%14 = select i1 %12, i64 %13, i64 %11
br label %15
15: ; preds = %7, %1
%16 = phi i64 [ %4, %1 ], [ %14, %7 ]
ret i64 %16
}