#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 uint64_t;

/* Variables and functions */
long long LONG_MAX;
long long strtoll(char const *, char **, int);
int parse_chunklen(uint64_t *out, const char *str) {
  char *endp;
  long long int n;
  n = strtoll(str, &endp, 10);
  if (n <= 0 || n == LONG_MAX)
    return -1;
  switch (*endp) {
  case '\0':
    *out = n;
    break;
  case 'k':
  case 'K':
    *out = (uint64_t)n * 1024;
    break;
  case 'm':
  case 'M':
    *out = (uint64_t)n * 1024 * 1024;
    break;
  case 'g':
  case 'G':
    *out = (uint64_t)n * 1024 * 1024 * 1024;
    break;
  default:
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_chunklen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    1155 <parse_chunklen+0x45>
mov    -0x28(%rbp),%rax
mov    0x2e94(%rip),%rcx
cmp    (%rcx),%rax
jne    1161 <parse_chunklen+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <parse_chunklen+0x137>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     11de <parse_chunklen+0xce>
jmp    1178 <parse_chunklen+0x68>
mov    -0x2c(%rbp),%eax
sub    $0x47,%eax
je     121a <parse_chunklen+0x10a>
jmp    1189 <parse_chunklen+0x79>
mov    -0x2c(%rbp),%eax
sub    $0x4b,%eax
je     11ef <parse_chunklen+0xdf>
jmp    119a <parse_chunklen+0x8a>
mov    -0x2c(%rbp),%eax
sub    $0x4d,%eax
je     1203 <parse_chunklen+0xf3>
jmp    11ab <parse_chunklen+0x9b>
mov    -0x2c(%rbp),%eax
sub    $0x67,%eax
je     121a <parse_chunklen+0x10a>
jmp    11bc <parse_chunklen+0xac>
mov    -0x2c(%rbp),%eax
sub    $0x6b,%eax
je     11ef <parse_chunklen+0xdf>
jmp    11cd <parse_chunklen+0xbd>
mov    -0x2c(%rbp),%eax
sub    $0x6d,%eax
je     1203 <parse_chunklen+0xf3>
jmp    1234 <parse_chunklen+0x124>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1240 <parse_chunklen+0x130>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
shl    $0xa,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1240 <parse_chunklen+0x130>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
shl    $0xa,%ecx
shl    $0xa,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1240 <parse_chunklen+0x130>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
shl    $0xa,%ecx
shl    $0xa,%ecx
shl    $0xa,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1240 <parse_chunklen+0x130>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <parse_chunklen+0x137>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_chunklen>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    $0xffffffff,%ecx
test   %rax,%rax
jle    119a <parse_chunklen+0x8a>
mov    0x2ea2(%rip),%rdx
cmp    (%rdx),%rax
je     119a <parse_chunklen+0x8a>
mov    0x8(%rsp),%rdx
movsbl (%rdx),%edx
lea    -0x47(%rdx),%esi
cmp    $0x26,%esi
ja     1192 <parse_chunklen+0x82>
movabs $0x100000001,%rdi
bt     %rsi,%rdi
jb     1188 <parse_chunklen+0x78>
movabs $0x1000000010,%rdi
bt     %rsi,%rdi
jb     118d <parse_chunklen+0x7d>
movabs $0x4000000040,%rdi
bt     %rsi,%rdi
jae    1192 <parse_chunklen+0x82>
shl    $0x14,%eax
jmp    1196 <parse_chunklen+0x86>
shl    $0x1e,%eax
jmp    1196 <parse_chunklen+0x86>
shl    $0xa,%eax
jmp    1196 <parse_chunklen+0x86>
test   %edx,%edx
jne    119a <parse_chunklen+0x8a>
mov    %eax,(%rbx)
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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