#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 */
scalar_t__ strcmp(char *, char *);
double strtod(char const *, char **);
int parse_byte_count(const char *str, double *result) {
  char *end;
  double base = strtod(str, &end);
  long long mul = 1;
  if (*end == '\0') {
    mul = 1L;
  } else if (strcmp(end, "k") == 0) {
    mul = 1024L;
  } else if (strcmp(end, "M") == 0) {
    mul = 1024L * 1024L;
  } else if (strcmp(end, "G") == 0) {
    mul = 1024L * 1024L * 1024L;
  } else if (strcmp(end, "T") == 0) {
    mul = 1024LL * 1024LL * 1024LL * 1024LL;
  } else {
    return 0;
  }
  *result = base * mul;
  return 1;
}


x86 assembly (clang, -O0):
<parse_byte_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1167 <parse_byte_count+0x47>
movq   $0x1,-0x30(%rbp)
jmp    1229 <parse_byte_count+0x109>
mov    -0x20(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    118e <parse_byte_count+0x6e>
movq   $0x400,-0x30(%rbp)
jmp    1224 <parse_byte_count+0x104>
mov    -0x20(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b5 <parse_byte_count+0x95>
movq   $0x100000,-0x30(%rbp)
jmp    121f <parse_byte_count+0xff>
mov    -0x20(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11dc <parse_byte_count+0xbc>
movq   $0x40000000,-0x30(%rbp)
40
jmp    121a <parse_byte_count+0xfa>
mov    -0x20(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1209 <parse_byte_count+0xe9>
movabs $0x10000000000,%rax
mov    %rax,-0x30(%rbp)
jmp    1215 <parse_byte_count+0xf5>
movl   $0x0,-0x4(%rbp)
jmp    1247 <parse_byte_count+0x127>
jmp    121a <parse_byte_count+0xfa>
jmp    121f <parse_byte_count+0xff>
jmp    1224 <parse_byte_count+0x104>
jmp    1229 <parse_byte_count+0x109>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_byte_count>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
lea    0x10(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x10(%rsp),%rbx
cmpb   $0x0,(%rbx)
je     11a3 <parse_byte_count+0x83>
movsd  %xmm0,0x8(%rsp)
lea    0xedd(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ad <parse_byte_count+0x8d>
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b7 <parse_byte_count+0x97>
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c1 <parse_byte_count+0xa1>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11dd <parse_byte_count+0xbd>
movsd  0xe7f(%rip),%xmm1
jmp    11c9 <parse_byte_count+0xa9>
movsd  0xe55(%rip),%xmm1
jmp    11cf <parse_byte_count+0xaf>
movsd  0xe53(%rip),%xmm1
jmp    11c9 <parse_byte_count+0xa9>
movsd  0xe51(%rip),%xmm1
jmp    11c9 <parse_byte_count+0xa9>
movsd  0xe4f(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"k\00"
@.str.1 = [2 x i8] c"M\00"
@.str.2 = [2 x i8] c"G\00"
@.str.3 = [2 x i8] c"T\00"
define i32 @parse_byte_count(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i8*
%7 = alloca double
%8 = alloca i64
store i8* %0, i8** %4
store double* %1, double** %5
%9 = load i8*, i8** %4
%10 = call double @strtod(i8* %9, i8** %6)
store double %10, double* %7
store i64 1, i64* %8
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i64 1, i64* %8
br label %41
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i64 1024, i64* %8
br label %40
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i64 1048576, i64* %8
br label %39
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i64 1073741824, i64* %8
br label %38
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i64 1099511627776, i64* %8
br label %37
36: ; preds = %31
store i32 0, i32* %3
br label %47
37: ; preds = %35
br label %38
38: ; preds = %37, %30
br label %39
39: ; preds = %38, %25
br label %40
40: ; preds = %39, %20
br label %41
41: ; preds = %40, %15
%42 = load double, double* %7
%43 = load i64, i64* %8
%44 = sitofp i64 %43 to double
%45 = fmul double %42, %44
%46 = load double*, double** %5
store double %45, double* %46
store i32 1, i32* %3
br label %47
47: ; preds = %41, %36
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"k\00"
@.str.1 = [2 x i8] c"M\00"
@.str.2 = [2 x i8] c"G\00"
@.str.3 = [2 x i8] c"T\00"
define i32 @parse_byte_count(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %15, %12, %9, %2
%22 = phi double [ 1.000000e+00, %2 ], [ 1.024000e+03, %9 ], [ 0x4130000000000000, %12 ], [ 0x41D0000000000000, %15 ], [ 0x4270000000000000, %18 ]
%23 = fmul double %5, %22
store double %23, double* %1
br label %24
24: ; preds = %18, %21
%25 = phi i32 [ 1, %21 ], [ 0, %18 ]
ret i32 %25
}