#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 strlen(char *);
unsigned get_unit(char *unit) {
  if (strlen(unit) > 1)
    return 0;
  switch (*unit) {
  case 'k':
  case 'K':
    return 1000LL;
  case 'm':
  case 'M':
    return 1000LL * 1000LL;
  case 'g':
  case 'G':
    return 1000LL * 1000LL * 1000LL;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<get_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    113a <get_unit+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <get_unit+0xc2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x47,%eax
je     11bf <get_unit+0xaf>
jmp    1152 <get_unit+0x42>
mov    -0x14(%rbp),%eax
sub    $0x4b,%eax
je     11a7 <get_unit+0x97>
jmp    1163 <get_unit+0x53>
mov    -0x14(%rbp),%eax
sub    $0x4d,%eax
je     11b3 <get_unit+0xa3>
jmp    1174 <get_unit+0x64>
mov    -0x14(%rbp),%eax
sub    $0x67,%eax
je     11bf <get_unit+0xaf>
jmp    1185 <get_unit+0x75>
mov    -0x14(%rbp),%eax
sub    $0x6b,%eax
je     11a7 <get_unit+0x97>
jmp    1196 <get_unit+0x86>
mov    -0x14(%rbp),%eax
sub    $0x6d,%eax
je     11b3 <get_unit+0xa3>
jmp    11cb <get_unit+0xbb>
movl   $0x3e8,-0x4(%rbp)
jmp    11d2 <get_unit+0xc2>
movl   $0xf4240,-0x4(%rbp)
jmp    11d2 <get_unit+0xc2>
movl   $0x3b9aca00,-0x4(%rbp)
jmp    11d2 <get_unit+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_unit>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jg     1172 <get_unit+0x62>
movsbl (%rbx),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     1170 <get_unit+0x60>
movabs $0x100000001,%rax
bt     %rcx,%rax
jb     1169 <get_unit+0x59>
mov    $0x3e8,%eax
movabs $0x1000000010,%rdx
bt     %rcx,%rdx
jb     1172 <get_unit+0x62>
movabs $0x4000000040,%rax
bt     %rcx,%rax
jae    1170 <get_unit+0x60>
mov    $0xf4240,%eax
pop    %rbx
ret
mov    $0x3b9aca00,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_unit(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %5, 1
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %16
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %15 [
i32 107, label %12
i32 75, label %12
i32 109, label %13
i32 77, label %13
i32 103, label %14
i32 71, label %14
]
12: ; preds = %8, %8
store i32 1000, i32* %2
br label %16
13: ; preds = %8, %8
store i32 1000000, i32* %2
br label %16
14: ; preds = %8, %8
store i32 1000000000, i32* %2
br label %16
15: ; preds = %8
store i32 0, i32* %2
br label %16
16: ; preds = %15, %14, %13, %12, %7
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
define i32 @get_unit(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = sext i8 %5 to i32
switch i32 %6, label %9 [
i32 107, label %10
i32 75, label %10
i32 109, label %7
i32 77, label %7
i32 103, label %8
i32 71, label %8
]
7: ; preds = %4, %4
br label %10
8: ; preds = %4, %4
br label %10
9: ; preds = %4
br label %10
10: ; preds = %4, %4, %1, %9, %8, %7
%11 = phi i32 [ 0, %9 ], [ 1000000000, %8 ], [ 1000000, %7 ], [ 0, %1 ], [ 1000, %4 ], [ 1000, %4 ]
ret i32 %11
}