int do_size(arg)
char *arg;
{
  int ret = 0;
  char unit = '\0';
  sscanf(arg, "%d%c", &ret, &unit);
  switch (unit) {
  case 'm':
  case 'M':
    ret = ret * 1024 * 1024;
    break;
  case 'k':
  case 'K':
    ret = ret * 1024;
    break;
  case 'b':
  case 'B':
    ret *= 512;
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<do_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xece(%rip),%rsi
xor    %eax,%eax
lea    -0xc(%rbp),%rdx
lea    -0xd(%rbp),%rcx
call   1030 <sscanf@plt>
movsbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x42,%eax
je     11ca <do_size+0xba>
jmp    1156 <do_size+0x46>
mov    -0x14(%rbp),%eax
sub    $0x4b,%eax
je     11bc <do_size+0xac>
jmp    1167 <do_size+0x57>
mov    -0x14(%rbp),%eax
sub    $0x4d,%eax
je     11ab <do_size+0x9b>
jmp    1178 <do_size+0x68>
mov    -0x14(%rbp),%eax
sub    $0x62,%eax
je     11ca <do_size+0xba>
jmp    1189 <do_size+0x79>
mov    -0x14(%rbp),%eax
sub    $0x6b,%eax
je     11bc <do_size+0xac>
jmp    119a <do_size+0x8a>
mov    -0x14(%rbp),%eax
sub    $0x6d,%eax
jne    11d3 <do_size+0xc3>
jmp    11ab <do_size+0x9b>
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11d3 <do_size+0xc3>
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11d3 <do_size+0xc3>
mov    -0xc(%rbp),%eax
shl    $0x9,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_size>:
push   %rax
movl   $0x0,0x4(%rsp)
movb   $0x0,0x3(%rsp)
lea    0xedb(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x3(%rsp),%rcx
xor    %eax,%eax
call   1030 <sscanf@plt>
movsbl 0x3(%rsp),%eax
add    $0xffffffbe,%eax
cmp    $0x2b,%eax
ja     118e <do_size+0x7e>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     1185 <do_size+0x75>
movabs $0x20000000200,%rcx
bt     %rax,%rcx
jb     117c <do_size+0x6c>
movabs $0x80000000800,%rcx
bt     %rax,%rcx
jae    118e <do_size+0x7e>
mov    0x4(%rsp),%eax
shl    $0x14,%eax
pop    %rcx
ret
mov    0x4(%rsp),%eax
shl    $0xa,%eax
pop    %rcx
ret
mov    0x4(%rsp),%eax
shl    $0x9,%eax
pop    %rcx
ret
mov    0x4(%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%c\00"
define i32 @do_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i8 0, i8* %4
%5 = load i8*, i8** %2
%6 = call i32 (i8*, i8*, ...) @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %4)
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
switch i32 %8, label %19 [
i32 109, label %9
i32 77, label %9
i32 107, label %13
i32 75, label %13
i32 98, label %16
i32 66, label %16
]
9: ; preds = %1, %1
%10 = load i32, i32* %3
%11 = mul nsw i32 %10, 1024
%12 = mul nsw i32 %11, 1024
store i32 %12, i32* %3
br label %19
13: ; preds = %1, %1
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 1024
store i32 %15, i32* %3
br label %19
16: ; preds = %1, %1
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 512
store i32 %18, i32* %3
br label %19
19: ; preds = %1, %16, %13, %9
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%c\00"
define i32 @do_size(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
store i8 0, i8* %3
%5 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %3)
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
switch i32 %7, label %8 [
i32 109, label %10
i32 77, label %10
i32 107, label %13
i32 75, label %13
i32 98, label %16
i32 66, label %16
]
8: ; preds = %1
%9 = load i32, i32* %2
br label %19
10: ; preds = %1, %1
%11 = load i32, i32* %2
%12 = shl nsw i32 %11, 20
br label %19
13: ; preds = %1, %1
%14 = load i32, i32* %2
%15 = shl nsw i32 %14, 10
br label %19
16: ; preds = %1, %1
%17 = load i32, i32* %2
%18 = shl nsw i32 %17, 9
br label %19
19: ; preds = %8, %16, %13, %10
%20 = phi i32 [ %9, %8 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ]
ret i32 %20
}