int parse_bytes(s)
char *s;
{
  int n = atoi(s);
  if ((lastchar(s) == 'k') || (lastchar(s) == 'K'))
    n *= 1024;
  if ((lastchar(s) == 'm') || (lastchar(s) == 'M'))
    n *= (1024 * 1024);
  return (n);
}


x86 assembly (clang, -O0):
<parse_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1040 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <lastchar@plt>
cmp    $0x6b,%eax
je     1162 <parse_bytes+0x42>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <lastchar@plt>
cmp    $0x4b,%eax
jne    116b <parse_bytes+0x4b>
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <lastchar@plt>
cmp    $0x6d,%eax
je     1193 <parse_bytes+0x73>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <lastchar@plt>
cmp    $0x4d,%eax
jne    119c <parse_bytes+0x7c>
mov    -0xc(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_bytes>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <lastchar@plt>
cmp    $0x6b,%eax
je     114d <parse_bytes+0x2d>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <lastchar@plt>
cmp    $0x4b,%eax
jne    1150 <parse_bytes+0x30>
shl    $0xa,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <lastchar@plt>
cmp    $0x6d,%eax
je     116e <parse_bytes+0x4e>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <lastchar@plt>
cmp    $0x4d,%eax
jne    1171 <parse_bytes+0x51>
shl    $0x14,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_bytes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %4)
store i32 %5, i32* %3
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %6)
%8 = icmp eq i32 %7, 107
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %10)
%12 = icmp eq i32 %11, 75
br i1 %12, label %13, label %16
13: ; preds = %9, %1
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 1024
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %9
%17 = load i8*, i8** %2
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %17)
%19 = icmp eq i32 %18, 109
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %21)
%23 = icmp eq i32 %22, 77
br i1 %23, label %24, label %27
24: ; preds = %20, %16
%25 = load i32, i32* %3
%26 = mul nsw i32 %25, 1048576
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %20
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @parse_bytes(i8* %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0)
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %0)
%4 = icmp eq i32 %3, 107
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %0)
%7 = icmp eq i32 %6, 75
br i1 %7, label %8, label %10
8: ; preds = %5, %1
%9 = shl nsw i32 %2, 10
br label %10
10: ; preds = %8, %5
%11 = phi i32 [ %9, %8 ], [ %2, %5 ]
%12 = tail call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %0)
%13 = icmp eq i32 %12, 109
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i32 (i8*, ...) bitcast (i32 (...)* @lastchar to i32 (i8*, ...)*)(i8* %0)
%16 = icmp eq i32 %15, 77
br i1 %16, label %17, label %19
17: ; preds = %14, %10
%18 = shl nsw i32 %11, 20
br label %19
19: ; preds = %17, %14
%20 = phi i32 [ %18, %17 ], [ %11, %14 ]
ret i32 %20
}