#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 */
unsigned long strtoul(char *, char **, int);
unsigned long parse_blocksize(char *s, unsigned long *b) {
  int err = 0;
  char *end;
  *b = strtoul(s, &end, 10);
  switch (end[0]) {
  case '\0':
  case 'b':
  case 'B':
    break;
  case 'k':
  case 'K':
    *b *= 1024;
    break;
  case 'm':
  case 'M':
    *b *= (1024 * 1024);
    break;
  case 'g':
  case 'G':
    *b *= (1024 * 1024 * 1024);
    break;
  default:
    err++;
    break;
  }
  if (end[0] && end[1])
    err++;
  return err;
}


x86 assembly (clang, -O0):
<parse_blocksize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     11e2 <parse_blocksize+0xd2>
jmp    115a <parse_blocksize+0x4a>
mov    -0x24(%rbp),%eax
sub    $0x42,%eax
je     11e2 <parse_blocksize+0xd2>
jmp    116b <parse_blocksize+0x5b>
mov    -0x24(%rbp),%eax
sub    $0x47,%eax
je     120d <parse_blocksize+0xfd>
jmp    117c <parse_blocksize+0x6c>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     11e7 <parse_blocksize+0xd7>
jmp    118d <parse_blocksize+0x7d>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     11fa <parse_blocksize+0xea>
jmp    119e <parse_blocksize+0x8e>
mov    -0x24(%rbp),%eax
sub    $0x62,%eax
je     11e2 <parse_blocksize+0xd2>
jmp    11af <parse_blocksize+0x9f>
mov    -0x24(%rbp),%eax
sub    $0x67,%eax
je     120d <parse_blocksize+0xfd>
jmp    11c0 <parse_blocksize+0xb0>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     11e7 <parse_blocksize+0xd7>
jmp    11d1 <parse_blocksize+0xc1>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
je     11fa <parse_blocksize+0xea>
jmp    1220 <parse_blocksize+0x110>
jmp    1229 <parse_blocksize+0x119>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
shl    $0xa,%rcx
mov    %rcx,(%rax)
jmp    1229 <parse_blocksize+0x119>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
shl    $0x14,%rcx
mov    %rcx,(%rax)
jmp    1229 <parse_blocksize+0x119>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
shl    $0x1e,%rcx
mov    %rcx,(%rax)
jmp    1229 <parse_blocksize+0x119>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1253 <parse_blocksize+0x143>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1253 <parse_blocksize+0x143>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_blocksize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %rax,(%r14)
mov    (%rsp),%rsi
mov    (%rsi),%bl
movsbl %bl,%ecx
xor    %r8d,%r8d
lea    -0x42(%rcx),%edi
cmp    $0x2b,%edi
ja     117b <parse_blocksize+0x6b>
mov    $0xa,%ecx
lea    0xeb9(%rip),%rdx
movslq (%rdx,%rdi,4),%rdi
add    %rdx,%rdi
jmp    *%rdi
mov    $0x1e,%ecx
jmp    115c <parse_blocksize+0x4c>
mov    $0x14,%ecx
shl    %cl,%rax
mov    %rax,(%r14)
mov    (%rsi),%bl
test   %bl,%bl
je     1170 <parse_blocksize+0x60>
cmpb   $0x1,0x1(%rsi)
sbb    $0xffffffff,%r8d
mov    %r8d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
test   %ecx,%ecx
je     1164 <parse_blocksize+0x54>
mov    $0x1,%r8d
jmp    1164 <parse_blocksize+0x54>

LLVM IR (-O0):
define i64 @parse_blocksize(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i64* %1, i64** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i64 @strtoul(i8* %7, i8** %6, i32 10)
%9 = load i64*, i64** %4
store i64 %8, i64* %9
%10 = load i8*, i8** %6
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %27 [
i32 0, label %14
i32 98, label %14
i32 66, label %14
i32 107, label %15
i32 75, label %15
i32 109, label %19
i32 77, label %19
i32 103, label %23
i32 71, label %23
]
14: ; preds = %2, %2, %2
br label %30
15: ; preds = %2, %2
%16 = load i64*, i64** %4
%17 = load i64, i64* %16
%18 = mul i64 %17, 1024
store i64 %18, i64* %16
br label %30
19: ; preds = %2, %2
%20 = load i64*, i64** %4
%21 = load i64, i64* %20
%22 = mul i64 %21, 1048576
store i64 %22, i64* %20
br label %30
23: ; preds = %2, %2
%24 = load i64*, i64** %4
%25 = load i64, i64* %24
%26 = mul i64 %25, 1073741824
store i64 %26, i64* %24
br label %30
27: ; preds = %2
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %23, %19, %15, %14
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %30
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %45
45: ; preds = %42, %36, %30
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
ret i64 %47
}

LLVM IR (-O2):
define i64 @parse_blocksize(i8* %0, i64* nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
store i64 %5, i64* %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %11 [
i32 0, label %16
i32 98, label %16
i32 66, label %16
i32 107, label %12
i32 75, label %12
i32 109, label %9
i32 77, label %9
i32 103, label %10
i32 71, label %10
]
9: ; preds = %2, %2
br label %12
10: ; preds = %2, %2
br label %12
11: ; preds = %2
br label %16
12: ; preds = %2, %2, %9, %10
%13 = phi i64 [ 20, %9 ], [ 30, %10 ], [ 10, %2 ], [ 10, %2 ]
%14 = shl i64 %5, %13
store i64 %14, i64* %1
%15 = load i8, i8* %6
br label %16
16: ; preds = %12, %2, %2, %2, %11
%17 = phi i8 [ %15, %12 ], [ %7, %2 ], [ %7, %2 ], [ %7, %2 ], [ %7, %11 ]
%18 = phi i32 [ 0, %12 ], [ 0, %2 ], [ 0, %2 ], [ 0, %2 ], [ 1, %11 ]
%19 = icmp eq i8 %17, 0
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %6, i64 1
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
%24 = zext i1 %23 to i32
%25 = add nuw nsw i32 %18, %24
br label %26
26: ; preds = %20, %16
%27 = phi i32 [ %18, %16 ], [ %25, %20 ]
%28 = zext i32 %27 to i64
ret i64 %28
}