#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 unsigned long long uint64_t;

/* Variables and functions */
scalar_t__ errno;
scalar_t__ isspace(int);
unsigned long long strtoull(char const *, char **, int /*<<< orphan*/);
uint64_t rte_str_to_size(const char *str) {
  char *endptr;
  unsigned long long size;
  while (isspace((int)*str))
    str++;
  if (*str == '-')
    return 0;
  errno = 0;
  size = strtoull(str, &endptr, 0);
  if (errno)
    return 0;
  if (*endptr == ' ')
    endptr++;
  switch (*endptr) {
  case 'G':
  case 'g':
    size *= 1024;
  case 'M':
  case 'm':
    size *= 1024;
  case 'K':
  case 'k':
    size *= 1024;
  default:
    break;
  }
  return size;
}


x86 assembly (clang, -O0):
<rte_str_to_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1153 <rte_str_to_size+0x33>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <rte_str_to_size+0xc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1170 <rte_str_to_size+0x50>
movq   $0x0,-0x8(%rbp)
jmp    1269 <rte_str_to_size+0x149>
mov    0x2e69(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e48(%rip),%rax
cmpq   $0x0,(%rax)
je     11af <rte_str_to_size+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    1269 <rte_str_to_size+0x149>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11cb <rte_str_to_size+0xab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x47,%eax
je     1238 <rte_str_to_size+0x118>
jmp    11e3 <rte_str_to_size+0xc3>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     1250 <rte_str_to_size+0x130>
jmp    11f4 <rte_str_to_size+0xd4>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     1244 <rte_str_to_size+0x124>
jmp    1205 <rte_str_to_size+0xe5>
mov    -0x24(%rbp),%eax
sub    $0x67,%eax
je     1238 <rte_str_to_size+0x118>
jmp    1216 <rte_str_to_size+0xf6>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     1250 <rte_str_to_size+0x130>
jmp    1227 <rte_str_to_size+0x107>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
je     1244 <rte_str_to_size+0x124>
jmp    125c <rte_str_to_size+0x13c>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
jmp    1261 <rte_str_to_size+0x141>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rte_str_to_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isspace@plt>
test   %rax,%rax
jne    1130 <rte_str_to_size+0x10>
cmpb   $0x2d,(%rbx)
je     1168 <rte_str_to_size+0x48>
mov    0x2e92(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoull@plt>
cmpq   $0x0,(%r14)
je     1172 <rte_str_to_size+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rsp),%rdx
mov    (%rdx),%cl
cmp    $0x20,%cl
jne    1180 <rte_str_to_size+0x60>
mov    0x1(%rdx),%cl
movsbl %cl,%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     116a <rte_str_to_size+0x4a>
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     11bd <rte_str_to_size+0x9d>
movabs $0x1000000010,%rdx
bt     %rcx,%rdx
jb     11c5 <rte_str_to_size+0xa5>
movabs $0x4000000040,%rdx
bt     %rcx,%rdx
jb     11c1 <rte_str_to_size+0xa1>
jmp    116a <rte_str_to_size+0x4a>
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
jmp    116a <rte_str_to_size+0x4a>

LLVM IR (-O0):
@errno = global i64 0
define i64 @rte_str_to_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
br label %6
6: ; preds = %12, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = call i64 @isspace(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
br label %6
15: ; preds = %6
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 45
br i1 %19, label %20, label %21
20: ; preds = %15
store i64 0, i64* %2
br label %51
21: ; preds = %15
store i64 0, i64* @errno
%22 = load i8*, i8** %3
%23 = call i64 @strtoull(i8* %22, i8** %4, i32 0)
store i64 %23, i64* %5
%24 = load i64, i64* @errno
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i64 0, i64* %2
br label %51
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 32
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
br label %35
35: ; preds = %32, %27
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
switch i32 %38, label %48 [
i32 71, label %39
i32 103, label %39
i32 77, label %42
i32 109, label %42
i32 75, label %45
i32 107, label %45
]
39: ; preds = %35, %35
%40 = load i64, i64* %5
%41 = mul i64 %40, 1024
store i64 %41, i64* %5
br label %42
42: ; preds = %35, %35, %39
%43 = load i64, i64* %5
%44 = mul i64 %43, 1024
store i64 %44, i64* %5
br label %45
45: ; preds = %35, %35, %42
%46 = load i64, i64* %5
%47 = mul i64 %46, 1024
store i64 %47, i64* %5
br label %48
48: ; preds = %35, %45
br label %49
49: ; preds = %48
%50 = load i64, i64* %5
store i64 %50, i64* %2
br label %51
51: ; preds = %49, %26, %20
%52 = load i64, i64* %2
ret i64 %52
}

LLVM IR (-O2):
@errno = global i64 0
define i64 @rte_str_to_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %10, %4 ]
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = tail call i64 @isspace(i32 %7)
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %9, label %11, label %4
11: ; preds = %4
%12 = load i8, i8* %5
%13 = icmp eq i8 %12, 45
br i1 %13, label %36, label %14
14: ; preds = %11
store i64 0, i64* @errno
%15 = call i64 @strtoull(i8* %5, i8** %2, i32 0)
%16 = load i64, i64* @errno
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 32
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %19, i64 1
%24 = load i8, i8* %23
br label %25
25: ; preds = %22, %18
%26 = phi i8 [ %24, %22 ], [ %20, %18 ]
%27 = sext i8 %26 to i32
switch i32 %27, label %36 [
i32 71, label %28
i32 103, label %28
i32 77, label %30
i32 109, label %30
i32 75, label %33
i32 107, label %33
]
28: ; preds = %25, %25
%29 = shl i64 %15, 10
br label %30
30: ; preds = %25, %25, %28
%31 = phi i64 [ %15, %25 ], [ %15, %25 ], [ %29, %28 ]
%32 = shl i64 %31, 10
br label %33
33: ; preds = %25, %25, %30
%34 = phi i64 [ %15, %25 ], [ %15, %25 ], [ %32, %30 ]
%35 = shl i64 %34, 10
br label %36
36: ; preds = %25, %33, %14, %11
%37 = phi i64 [ 0, %11 ], [ 0, %14 ], [ %15, %25 ], [ %35, %33 ]
ret i64 %37
}