#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 atol(char const *);
scalar_t__ isdigit(char const);
char *strchr(char const *, char const);
unsigned long parse_human_number(const char *num) {
  unsigned long ret = 0;
  static const unsigned long mul[] = {1024, 1024 * 1024, 1024 * 1024 * 1024};
  const char *kmg = "KMG";
  const char *kmgind, *p;
  ret = atol(num);
  p = num;
  while (isdigit(*(++p)))
    ;
  if (*p && (kmgind = strchr(kmg, *p)))
    ret *= mul[kmgind - kmg];
  return ret;
}


x86 assembly (clang, -O0):
<parse_human_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     118b <parse_human_number+0x5b>
jmp    1164 <parse_human_number+0x34>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d8 <parse_human_number+0xa8>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11d8 <parse_human_number+0xa8>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rax,%rcx
lea    0xe35(%rip),%rax
mov    (%rax,%rcx,8),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_human_number>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <atol@plt>
mov    %rax,%r14
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <parse_human_number+0x20>
mov    -0x1(%rbx),%al
test   %al,%al
je     118e <parse_human_number+0x5e>
movsbl %al,%esi
lea    0xea6(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     118e <parse_human_number+0x5e>
sub    %rbx,%rax
lea    0xe77(%rip),%rcx
imul   (%rcx,%rax,8),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@parse_human_number.mul = internal constant [3 x i64] [i64 1024, i64 1048576, i64 1073741824]
@.str = [4 x i8] c"KMG\00"
define i64 @parse_human_number(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %4
%7 = load i8*, i8** %2
%8 = call i64 @atol(i8* %7)
store i64 %8, i64* %3
%9 = load i8*, i8** %2
store i8* %9, i8** %6
br label %10
10: ; preds = %16, %1
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %6
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
br label %10
17: ; preds = %10
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = call i8* @strchr(i8* %23, i8 signext %25)
store i8* %26, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %38
28: ; preds = %22
%29 = load i8*, i8** %5
%30 = load i8*, i8** %4
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = getelementptr inbounds [3 x i64], [3 x i64]* @parse_human_number.mul, i64 0, i64 %33
%35 = load i64, i64* %34
%36 = load i64, i64* %3
%37 = mul i64 %36, %35
store i64 %37, i64* %3
br label %38
38: ; preds = %28, %22, %17
%39 = load i64, i64* %3
ret i64 %39
}

LLVM IR (-O2):
@parse_human_number.mul = internal unnamed_addr constant [3 x i64] [i64 1024, i64 1048576, i64 1073741824]
@.str = [4 x i8] c"KMG\00"
define i64 @parse_human_number(i8* nocapture %0) {
%2 = tail call i64 @atol(i8* %0)
br label %3
3: ; preds = %3, %1
%4 = phi i8* [ %0, %1 ], [ %5, %3 ]
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = load i8, i8* %5
%7 = tail call i64 @isdigit(i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = load i8, i8* %5
%11 = icmp eq i8 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = tail call i8* @strchr(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %10)
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = ptrtoint i8* %13 to i64
%17 = sub i64 %16, ptrtoint ([4 x i8]* @.str to i64)
%18 = getelementptr inbounds [3 x i64], [3 x i64]* @parse_human_number.mul, i64 0, i64 %17
%19 = load i64, i64* %18
%20 = mul i64 %19, %2
br label %21
21: ; preds = %15, %12, %9
%22 = phi i64 [ %20, %15 ], [ %2, %12 ], [ %2, %9 ]
ret i64 %22
}