#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 */
scalar_t__ strstr(char const *, char *);
long long strtoll(char const *, int /*<<< orphan*/ *, int);
long long string_to_bytes(const char *str) {
  long long val = strtoll(str, NULL, 10);
  if (!val)
    return -1;
  if (strstr(str, "kb"))
    return val * 1024;
  if (strstr(str, "mb"))
    return val * 1024 * 1024;
  if (strstr(str, "gb"))
    return val * 1024 * 1024 * 1024;
  return val;
}


x86 assembly (clang, -O0):
<string_to_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115a <string_to_bytes+0x3a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ef <string_to_bytes+0xcf>
mov    -0x10(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     1185 <string_to_bytes+0x65>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <string_to_bytes+0xcf>
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11b4 <string_to_bytes+0x94>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <string_to_bytes+0xcf>
mov    -0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11e7 <string_to_bytes+0xc7>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <string_to_bytes+0xcf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_bytes>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtoll@plt>
test   %rax,%rax
je     1155 <string_to_bytes+0x35>
mov    %rax,%rbx
lea    0xebe(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     115e <string_to_bytes+0x3e>
shl    $0xa,%rbx
jmp    1195 <string_to_bytes+0x75>
mov    $0xffffffffffffffff,%rbx
jmp    1195 <string_to_bytes+0x75>
lea    0xe9e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     1178 <string_to_bytes+0x58>
shl    $0x14,%rbx
jmp    1195 <string_to_bytes+0x75>
lea    0xe87(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
mov    %rbx,%rcx
shl    $0x1e,%rcx
test   %rax,%rax
cmovne %rcx,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"kb\00"
@.str.1 = [3 x i8] c"mb\00"
@.str.2 = [3 x i8] c"gb\00"
define i64 @string_to_bytes(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strtoll(i8* %5, i32* null, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp ne i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i64 -1, i64* %2
br label %36
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strstr(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i64, i64* %4
%16 = mul nsw i64 %15, 1024
store i64 %16, i64* %2
br label %36
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = call i64 @strstr(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i64, i64* %4
%23 = mul nsw i64 %22, 1024
%24 = mul nsw i64 %23, 1024
store i64 %24, i64* %2
br label %36
25: ; preds = %17
%26 = load i8*, i8** %3
%27 = call i64 @strstr(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i64, i64* %4
%31 = mul nsw i64 %30, 1024
%32 = mul nsw i64 %31, 1024
%33 = mul nsw i64 %32, 1024
store i64 %33, i64* %2
br label %36
34: ; preds = %25
%35 = load i64, i64* %4
store i64 %35, i64* %2
br label %36
36: ; preds = %34, %29, %21, %14, %9
%37 = load i64, i64* %2
ret i64 %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"kb\00"
@.str.1 = [3 x i8] c"mb\00"
@.str.2 = [3 x i8] c"gb\00"
define i64 @string_to_bytes(i8* %0) {
%2 = tail call i64 @strtoll(i8* nocapture %0, i32* null, i32 10)
%3 = icmp eq i64 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = shl nsw i64 %2, 10
br label %19
9: ; preds = %4
%10 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = shl nsw i64 %2, 20
br label %19
14: ; preds = %9
%15 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = shl nsw i64 %2, 30
%18 = select i1 %16, i64 %2, i64 %17
br label %19
19: ; preds = %14, %1, %12, %7
%20 = phi i64 [ %8, %7 ], [ %13, %12 ], [ -1, %1 ], [ %18, %14 ]
ret i64 %20
}