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

/* Variables and functions */
long atol(char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
size_t strlen(char *);
long parse_human_number(char *num) {
  long ret = 0;
  char buf[64];
  if (!num)
    return 0;
  size_t l = strlen(num);
  if (l && l < sizeof(buf)) {
    if (num[l - 1] == 'G')
      ret = 1024 * 1024 * 1024;
    else if (num[l - 1] == 'M')
      ret = 1024 * 1024;
    else if (num[l - 1] == 'K')
      ret = 1024;
    if (ret) {
      memcpy(buf, num, l);
      buf[l] = 0;
      return atol(buf) * ret;
    }
    return atol(num);
  }
  return ret;
}


x86 assembly (clang, -O0):
<parse_human_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115c <parse_human_number+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    124c <parse_human_number+0x11c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1244 <parse_human_number+0x114>
cmpq   $0x40,-0x68(%rbp)
jae    1244 <parse_human_number+0x114>
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x47,%eax
jne    11a5 <parse_human_number+0x75>
movq   $0x40000000,-0x18(%rbp)
40
jmp    11f6 <parse_human_number+0xc6>
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4d,%eax
jne    11cb <parse_human_number+0x9b>
movq   $0x100000,-0x18(%rbp)
jmp    11f1 <parse_human_number+0xc1>
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4b,%eax
jne    11ec <parse_human_number+0xbc>
movq   $0x400,-0x18(%rbp)
jmp    11f1 <parse_human_number+0xc1>
jmp    11f6 <parse_human_number+0xc6>
cmpq   $0x0,-0x18(%rbp)
je     1232 <parse_human_number+0x102>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x68(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
call   1050 <atol@plt>
imul   -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124c <parse_human_number+0x11c>
mov    -0x10(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,-0x8(%rbp)
jmp    124c <parse_human_number+0x11c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_human_number>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %rdi,%rdi
je     116c <parse_human_number+0x3c>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
add    $0xffffffffffffffff,%rax
cmp    $0x3e,%rax
ja     116c <parse_human_number+0x3c>
mov    (%rbx,%rax,1),%al
cmp    $0x47,%al
je     1170 <parse_human_number+0x40>
cmp    $0x4b,%al
je     1178 <parse_human_number+0x48>
cmp    $0x4d,%al
jne    11ac <parse_human_number+0x7c>
mov    $0x100000,%r12d
jmp    117e <parse_human_number+0x4e>
xor    %eax,%eax
jmp    11a0 <parse_human_number+0x70>
mov    $0x40000000,%r12d
jmp    117e <parse_human_number+0x4e>
mov    $0x400,%r12d
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%rsp,%r14,1)
mov    %r15,%rdi
call   1050 <atol@plt>
imul   %r12,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <atol@plt>

LLVM IR (-O0):
define i64 @parse_human_number(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [64 x i8]
%6 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i64 0, i64* %2
br label %66
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %64
15: ; preds = %10
%16 = load i64, i64* %6
%17 = icmp ult i64 %16, 64
br i1 %17, label %18, label %64
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = load i64, i64* %6
%21 = sub i64 %20, 1
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 71
br i1 %25, label %26, label %27
26: ; preds = %18
store i64 1073741824, i64* %4
br label %47
27: ; preds = %18
%28 = load i8*, i8** %3
%29 = load i64, i64* %6
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 77
br i1 %34, label %35, label %36
35: ; preds = %27
store i64 1048576, i64* %4
br label %46
36: ; preds = %27
%37 = load i8*, i8** %3
%38 = load i64, i64* %6
%39 = sub i64 %38, 1
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 75
br i1 %43, label %44, label %45
44: ; preds = %36
store i64 1024, i64* %4
br label %45
45: ; preds = %44, %36
br label %46
46: ; preds = %45, %35
br label %47
47: ; preds = %46, %26
%48 = load i64, i64* %4
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %47
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%52 = load i8*, i8** %3
%53 = load i64, i64* %6
%54 = call i32 @memcpy(i8* %51, i8* %52, i64 %53)
%55 = load i64, i64* %6
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%58 = call i64 @atol(i8* %57)
%59 = load i64, i64* %4
%60 = mul nsw i64 %58, %59
store i64 %60, i64* %2
br label %66
61: ; preds = %47
%62 = load i8*, i8** %3
%63 = call i64 @atol(i8* %62)
store i64 %63, i64* %2
br label %66
64: ; preds = %15, %10
%65 = load i64, i64* %4
store i64 %65, i64* %2
br label %66
66: ; preds = %64, %61, %50, %9
%67 = load i64, i64* %2
ret i64 %67
}

LLVM IR (-O2):
define i64 @parse_human_number(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = tail call i64 @strlen(i8* %0)
%7 = add i64 %6, -1
%8 = icmp ult i64 %7, 63
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
switch i8 %11, label %20 [
i8 71, label %14
i8 77, label %12
i8 75, label %13
]
12: ; preds = %9
br label %14
13: ; preds = %9
br label %14
14: ; preds = %12, %13, %9
%15 = phi i64 [ 1073741824, %9 ], [ 1024, %13 ], [ 1048576, %12 ]
%16 = call i32 @memcpy(i8* %3, i8* %0, i64 %6)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %6
store i8 0, i8* %17
%18 = call i64 @atol(i8* %3)
%19 = mul nsw i64 %18, %15
br label %22
20: ; preds = %9
%21 = tail call i64 @atol(i8* %0)
br label %22
22: ; preds = %14, %20, %5, %1
%23 = phi i64 [ 0, %1 ], [ %19, %14 ], [ %21, %20 ], [ 0, %5 ]
ret i64 %23
}