#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 *, char *, int *, char *, char *);
int /*<<< orphan*/ tolower(char);
int zstr_to_size(char *s) {
  char unit, junk;
  int intval;
  switch (sscanf(s, "%d%c%c", &intval, &unit, &junk)) {
  case 1:
    unit = 'b';
  case 2:
    if (intval < 0)
      return 0;
    switch (tolower(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 0;
}


x86 assembly (clang, -O0):
<zstr_to_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xef9(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x11(%rbp),%rcx
lea    -0x12(%rbp),%r8
call   1040 <sscanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x1,%eax
je     116c <zstr_to_size+0x4c>
jmp    115b <zstr_to_size+0x3b>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1170 <zstr_to_size+0x50>
jmp    11ef <zstr_to_size+0xcf>
movb   $0x62,-0x11(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1186 <zstr_to_size+0x66>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <zstr_to_size+0xd6>
movsbl -0x11(%rbp),%edi
call   1030 <tolower@plt>
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0xb,%eax
ja     11e4 <zstr_to_size+0xc4>
mov    -0x28(%rbp),%rax
lea    0xe54(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%eax
shl    $0x1e,%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <zstr_to_size+0xd6>
mov    -0x18(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <zstr_to_size+0xd6>
mov    -0x18(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <zstr_to_size+0xd6>
jmp    11e4 <zstr_to_size+0xc4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <zstr_to_size+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zstr_to_size>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xf(%rsp),%rcx
lea    0x17(%rsp),%r8
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
je     1152 <zstr_to_size+0x32>
cmp    $0x1,%ecx
jne    119a <zstr_to_size+0x7a>
movb   $0x62,0xf(%rsp)
cmpl   $0x0,0x10(%rsp)
js     119a <zstr_to_size+0x7a>
movsbl 0xf(%rsp),%edi
call   1030 <tolower@plt>
cmp    $0x6d,%eax
je     117e <zstr_to_size+0x5e>
cmp    $0x6b,%eax
je     118a <zstr_to_size+0x6a>
cmp    $0x67,%eax
jne    1196 <zstr_to_size+0x76>
mov    0x10(%rsp),%eax
shl    $0x1e,%eax
add    $0x18,%rsp
ret
mov    0x10(%rsp),%eax
shl    $0x14,%eax
add    $0x18,%rsp
ret
mov    0x10(%rsp),%eax
shl    $0xa,%eax
add    $0x18,%rsp
ret
mov    0x10(%rsp),%eax
add    $0x18,%rsp
ret

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

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