#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 */
int /*<<< orphan*/ strcasecmp(char const *, char *);
unsigned long parse_unit(const char *start) {
  if (*start == '\0')
    return 1;
  if (!strcasecmp(start, "k"))
    return 1024;
  if (!strcasecmp(start, "m"))
    return 1024 * 1024;
  if (!strcasecmp(start, "g"))
    return 1024 * 1024 * 1024;
  return 0;
}


x86 assembly (clang, -O0):
<parse_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1139 <parse_unit+0x29>
movq   $0x1,-0x8(%rbp)
jmp    11b3 <parse_unit+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xebc(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    115f <parse_unit+0x4f>
movq   $0x400,-0x8(%rbp)
jmp    11b3 <parse_unit+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1185 <parse_unit+0x75>
movq   $0x100000,-0x8(%rbp)
jmp    11b3 <parse_unit+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11ab <parse_unit+0x9b>
movq   $0x40000000,-0x8(%rbp)
40
jmp    11b3 <parse_unit+0xa3>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_unit>:
push   %rbx
cmpb   $0x0,(%rdi)
je     115a <parse_unit+0x4a>
mov    %rdi,%rbx
lea    0xee0(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1161 <parse_unit+0x51>
lea    0xed2(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1168 <parse_unit+0x58>
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
shl    $0x1e,%rax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x400,%eax
pop    %rbx
ret
mov    $0x100000,%eax
pop    %rbx
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"
define i64 @parse_unit(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 1, i64* %2
br label %25
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i64 1024, i64* %2
br label %25
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @strcasecmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
store i64 1048576, i64* %2
br label %25
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @strcasecmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19
store i64 1073741824, i64* %2
br label %25
24: ; preds = %19
store i64 0, i64* %2
br label %25
25: ; preds = %24, %23, %18, %13, %8
%26 = load i64, i64* %2
ret i64 %26
}

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"
define i64 @parse_unit(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i64 1073741824, i64 0
br label %14
14: ; preds = %10, %7, %4, %1
%15 = phi i64 [ 1, %1 ], [ 1024, %4 ], [ 1048576, %7 ], [ %13, %10 ]
ret i64 %15
}