#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 sscanf(char const *, char *, long *, char *, char *);
int /*<<< orphan*/ ztolower(char);
long zstr_to_size(const char *s, long def) {
  char unit, junk;
  long intval;
  switch (sscanf(s, "%ld%c%c", &intval, &unit, &junk)) {
  case 1:
    unit = 'b';
  case 2:
    if (intval < 0)
      return 0;
    switch (ztolower(unit)) {
    case 'g':
      return (intval * (1024 * 1024 * 1024));
    case 'm':
      return (intval * (1024 * 1024));
    case 'k':
      return (intval * 1024);
    case 'b':
    default:
      return (intval);
    }
  }
  return def;
}


x86 assembly (clang, -O0):
<zstr_to_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xef5(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x19(%rbp),%rcx
lea    -0x1a(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0x1,%eax
je     1170 <zstr_to_size+0x50>
jmp    115f <zstr_to_size+0x3f>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     1174 <zstr_to_size+0x54>
jmp    1200 <zstr_to_size+0xe0>
movb   $0x62,-0x19(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    118c <zstr_to_size+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    1208 <zstr_to_size+0xe8>
movsbl -0x19(%rbp),%edi
call   1040 <ztolower@plt>
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xb,%eax
ja     11f3 <zstr_to_size+0xd3>
mov    -0x38(%rbp),%rax
lea    0xe4e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <zstr_to_size+0xe8>
mov    -0x28(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <zstr_to_size+0xe8>
mov    -0x28(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <zstr_to_size+0xe8>
jmp    11f3 <zstr_to_size+0xd3>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <zstr_to_size+0xe8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zstr_to_size>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xed1(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x6(%rsp),%rcx
lea    0x7(%rsp),%r8
call   1030 <sscanf@plt>
cmp    $0x2,%eax
je     1152 <zstr_to_size+0x32>
cmp    $0x1,%eax
jne    119d <zstr_to_size+0x7d>
movb   $0x62,0x6(%rsp)
cmpq   $0x0,0x8(%rsp)
js     117e <zstr_to_size+0x5e>
movsbl 0x6(%rsp),%edi
call   1040 <ztolower@plt>
cmp    $0x6d,%eax
je     1182 <zstr_to_size+0x62>
cmp    $0x6b,%eax
je     118d <zstr_to_size+0x6d>
cmp    $0x67,%eax
jne    1198 <zstr_to_size+0x78>
mov    0x8(%rsp),%rbx
shl    $0x1e,%rbx
jmp    119d <zstr_to_size+0x7d>
xor    %ebx,%ebx
jmp    119d <zstr_to_size+0x7d>
mov    0x8(%rsp),%rbx
shl    $0x14,%rbx
jmp    119d <zstr_to_size+0x7d>
mov    0x8(%rsp),%rbx
shl    $0xa,%rbx
jmp    119d <zstr_to_size+0x7d>
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%ld%c%c\00"
define i64 @zstr_to_size(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8
%7 = alloca i8
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i8*, i8** %4
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64* %8, i8* %6, i8* %7)
switch i32 %10, label %31 [
i32 1, label %11
i32 2, label %12
]
11: ; preds = %2
store i8 98, i8* %6
br label %12
12: ; preds = %2, %11
%13 = load i64, i64* %8
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i64 0, i64* %3
br label %33
16: ; preds = %12
%17 = load i8, i8* %6
%18 = call i32 @ztolower(i8 signext %17)
switch i32 %18, label %29 [
i32 103, label %19
i32 109, label %22
i32 107, label %25
i32 98, label %28
]
19: ; preds = %16
%20 = load i64, i64* %8
%21 = mul nsw i64 %20, 1073741824
store i64 %21, i64* %3
br label %33
22: ; preds = %16
%23 = load i64, i64* %8
%24 = mul nsw i64 %23, 1048576
store i64 %24, i64* %3
br label %33
25: ; preds = %16
%26 = load i64, i64* %8
%27 = mul nsw i64 %26, 1024
store i64 %27, i64* %3
br label %33
28: ; preds = %16
br label %29
29: ; preds = %16, %28
%30 = load i64, i64* %8
store i64 %30, i64* %3
br label %33
31: ; preds = %2
%32 = load i64, i64* %5
store i64 %32, i64* %3
br label %33
33: ; preds = %31, %29, %25, %22, %19, %15
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
@.str = [8 x i8] c"%ld%c%c\00"
define i64 @zstr_to_size(i8* nocapture %0, i64 %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64* %5, i8* %3, i8* %4)
switch i32 %7, label %26 [
i32 1, label %8
i32 2, label %9
]
8: ; preds = %2
store i8 98, i8* %3
br label %9
9: ; preds = %2, %8
%10 = load i64, i64* %5
%11 = icmp slt i64 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = load i8, i8* %3
%14 = call i32 @ztolower(i8 signext %13)
switch i32 %14, label %24 [
i32 103, label %15
i32 109, label %18
i32 107, label %21
]
15: ; preds = %12
%16 = load i64, i64* %5
%17 = shl nsw i64 %16, 30
br label %26
18: ; preds = %12
%19 = load i64, i64* %5
%20 = shl nsw i64 %19, 20
br label %26
21: ; preds = %12
%22 = load i64, i64* %5
%23 = shl nsw i64 %22, 10
br label %26
24: ; preds = %12
%25 = load i64, i64* %5
br label %26
26: ; preds = %2, %9, %24, %21, %18, %15
%27 = phi i64 [ %25, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ 0, %9 ], [ %1, %2 ]
ret i64 %27
}