#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 */
typedef int int64_t;

/* Variables and functions */
scalar_t__ errno;
int strtoll(char *, char **, int);
int64_t parse_file_size(char *s) {
  char *end = NULL;
  errno = 0;
  int64_t val = strtoll(s, &end, 10);
  if (errno)
    return -1;
  switch (*end) {
  case 0:
    return val;
  case 'k':
  case 'K':
    return val * 1024;
  case 'm':
  case 'M':
    return val * 1024 * 1024;
  case 'g':
  case 'G':
    return val * 1024 * 1024 * 1024;
  case 't':
  case 'T':
    return val * 1024 * 1024 * 1024 * 1024;
  default:
    return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2eb5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e92(%rip),%rax
cmpq   $0x0,(%rax)
je     1164 <parse_file_size+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <parse_file_size+0x14f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     1203 <parse_file_size+0xf3>
jmp    117b <parse_file_size+0x6b>
mov    -0x20(%rbp),%eax
sub    $0x47,%eax
je     122d <parse_file_size+0x11d>
jmp    118c <parse_file_size+0x7c>
mov    -0x20(%rbp),%eax
sub    $0x4b,%eax
je     120e <parse_file_size+0xfe>
jmp    119d <parse_file_size+0x8d>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     121c <parse_file_size+0x10c>
jmp    11ae <parse_file_size+0x9e>
mov    -0x20(%rbp),%eax
sub    $0x54,%eax
je     1241 <parse_file_size+0x131>
jmp    11bf <parse_file_size+0xaf>
mov    -0x20(%rbp),%eax
sub    $0x67,%eax
je     122d <parse_file_size+0x11d>
jmp    11d0 <parse_file_size+0xc0>
mov    -0x20(%rbp),%eax
sub    $0x6b,%eax
je     120e <parse_file_size+0xfe>
jmp    11e1 <parse_file_size+0xd1>
mov    -0x20(%rbp),%eax
sub    $0x6d,%eax
je     121c <parse_file_size+0x10c>
jmp    11f2 <parse_file_size+0xe2>
mov    -0x20(%rbp),%eax
sub    $0x74,%eax
je     1241 <parse_file_size+0x131>
jmp    1258 <parse_file_size+0x148>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125f <parse_file_size+0x14f>
mov    -0x1c(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    125f <parse_file_size+0x14f>
mov    -0x1c(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    125f <parse_file_size+0x14f>
mov    -0x1c(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    125f <parse_file_size+0x14f>
mov    -0x1c(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    125f <parse_file_size+0x14f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_file_size>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2ebb(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    $0xffffffff,%ecx
cmpq   $0x0,(%rbx)
je     114e <parse_file_size+0x3e>
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%rcx
movsbl (%rcx),%edx
lea    -0x47(%rdx),%ecx
cmp    $0x2d,%ecx
ja     1187 <parse_file_size+0x77>
lea    0xe9b(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
shl    $0x1e,%eax
mov    %eax,%ecx
jmp    1146 <parse_file_size+0x36>
shl    $0xa,%eax
mov    %eax,%ecx
jmp    1146 <parse_file_size+0x36>
shl    $0x14,%eax
mov    %eax,%ecx
jmp    1146 <parse_file_size+0x36>
xor    %ecx,%ecx
jmp    1146 <parse_file_size+0x36>
mov    %eax,%ecx
test   %edx,%edx
je     1146 <parse_file_size+0x36>
mov    $0xffffffff,%ecx
jmp    1146 <parse_file_size+0x36>

LLVM IR (-O0):
@errno = global i64 0
define i32 @parse_file_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %4
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = call i32 @strtoll(i8* %6, i8** %4, i32 10)
store i32 %7, i32* %5
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %36
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %35 [
i32 0, label %15
i32 107, label %17
i32 75, label %17
i32 109, label %20
i32 77, label %20
i32 103, label %24
i32 71, label %24
i32 116, label %29
i32 84, label %29
]
15: ; preds = %11
%16 = load i32, i32* %5
store i32 %16, i32* %2
br label %36
17: ; preds = %11, %11
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, 1024
store i32 %19, i32* %2
br label %36
20: ; preds = %11, %11
%21 = load i32, i32* %5
%22 = mul nsw i32 %21, 1024
%23 = mul nsw i32 %22, 1024
store i32 %23, i32* %2
br label %36
24: ; preds = %11, %11
%25 = load i32, i32* %5
%26 = mul nsw i32 %25, 1024
%27 = mul nsw i32 %26, 1024
%28 = mul nsw i32 %27, 1024
store i32 %28, i32* %2
br label %36
29: ; preds = %11, %11
%30 = load i32, i32* %5
%31 = mul nsw i32 %30, 1024
%32 = mul nsw i32 %31, 1024
%33 = mul nsw i32 %32, 1024
%34 = mul nsw i32 %33, 1024
store i32 %34, i32* %2
br label %36
35: ; preds = %11
store i32 -1, i32* %2
br label %36
36: ; preds = %35, %29, %24, %20, %17, %15, %10
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @parse_file_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
store i64 0, i64* @errno
%4 = call i32 @strtoll(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %18 [
i32 0, label %19
i32 107, label %11
i32 75, label %11
i32 109, label %13
i32 77, label %13
i32 103, label %15
i32 71, label %15
i32 116, label %17
i32 84, label %17
]
11: ; preds = %7, %7
%12 = shl nsw i32 %4, 10
br label %19
13: ; preds = %7, %7
%14 = shl nsw i32 %4, 20
br label %19
15: ; preds = %7, %7
%16 = shl nsw i32 %4, 30
br label %19
17: ; preds = %7, %7
br label %19
18: ; preds = %7
br label %19
19: ; preds = %7, %1, %18, %17, %15, %13, %11
%20 = phi i32 [ -1, %18 ], [ 0, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ -1, %1 ], [ %4, %7 ]
ret i32 %20
}