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

/* Variables and functions */
int /*<<< orphan*/ LOG_WARNING;
long LONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
long strtol(char const *const, char **, int /*<<< orphan*/);
int /*<<< orphan*/ zc_err(int /*<<< orphan*/, char *, char const *const, ...);
char *zc_strdup(char *);
int zc_size_parse(const char *const s, uint64_t *const out) {
  long size, unit;
  char *p;
  errno = 0;
  size = strtol(s, &p, 0);
  if (errno != 0 || p == s)
    goto parse_error;
  if (size < 0) {
    p = zc_strdup("Negative block size");
    goto invalid_size;
  }
  switch (*p) {
  case '\0':
    unit = 1;
    break;
  case 'k':
  case 'K':
    unit = 1024;
    break;
  case 'm':
  case 'M':
    unit = 1048576;
    break;
  case 'g':
  case 'G':
    unit = 1073741824;
    break;
  default:
    goto parse_error;
  }
  if (unit != 1 && *(++p) != '\0')
    goto parse_error;
  if (size >= LONG_MAX / unit) {
    p = "Block size too large";
    p = zc_strdup(p);
    goto invalid_size;
  }
  size *= unit;
  *out = (uint64_t)size;
  return 0;
invalid_size:
  zc_err(LOG_WARNING, "Invalid block size: %s: %s\n", s, p);
  free(p);
  return -1;
parse_error:
  zc_err(LOG_WARNING, "Invalid block size: %s\n", s);
  return -1;
}


x86 assembly (clang, -O0):
<zc_size_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e79(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e58(%rip),%rax
cmpq   $0x0,(%rax)
jne    1190 <zc_size_parse+0x50>
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1195 <zc_size_parse+0x55>
jmp    1334 <zc_size_parse+0x1f4>
cmpq   $0x0,-0x20(%rbp)
jge    11b5 <zc_size_parse+0x75>
lea    0xe59(%rip),%rdi
call   1040 <zc_strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1300 <zc_size_parse+0x1c0>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1232 <zc_size_parse+0xf2>
jmp    11cc <zc_size_parse+0x8c>
mov    -0x34(%rbp),%eax
sub    $0x47,%eax
je     1259 <zc_size_parse+0x119>
jmp    11dd <zc_size_parse+0x9d>
mov    -0x34(%rbp),%eax
sub    $0x4b,%eax
je     123f <zc_size_parse+0xff>
jmp    11ee <zc_size_parse+0xae>
mov    -0x34(%rbp),%eax
sub    $0x4d,%eax
je     124c <zc_size_parse+0x10c>
jmp    11ff <zc_size_parse+0xbf>
mov    -0x34(%rbp),%eax
sub    $0x67,%eax
je     1259 <zc_size_parse+0x119>
jmp    1210 <zc_size_parse+0xd0>
mov    -0x34(%rbp),%eax
sub    $0x6b,%eax
je     123f <zc_size_parse+0xff>
jmp    1221 <zc_size_parse+0xe1>
mov    -0x34(%rbp),%eax
sub    $0x6d,%eax
je     124c <zc_size_parse+0x10c>
jmp    1266 <zc_size_parse+0x126>
movq   $0x1,-0x28(%rbp)
jmp    126b <zc_size_parse+0x12b>
movq   $0x400,-0x28(%rbp)
jmp    126b <zc_size_parse+0x12b>
movq   $0x100000,-0x28(%rbp)
jmp    126b <zc_size_parse+0x12b>
movq   $0x40000000,-0x28(%rbp)
40
jmp    126b <zc_size_parse+0x12b>
jmp    1334 <zc_size_parse+0x1f4>
cmpq   $0x1,-0x28(%rbp)
je     1297 <zc_size_parse+0x157>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1297 <zc_size_parse+0x157>
jmp    1334 <zc_size_parse+0x1f4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jl     12dc <zc_size_parse+0x19c>
lea    0xd4e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <zc_strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1300 <zc_size_parse+0x1c0>
mov    -0x28(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1356 <zc_size_parse+0x216>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd11(%rip),%rsi
mov    $0x0,%al
call   1060 <zc_err@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1356 <zc_size_parse+0x216>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   1060 <zc_err@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zc_size_parse>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e7a(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
cmpq   $0x0,(%rbx)
je     1198 <zc_size_parse+0x58>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xec6(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <zc_err@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rax,%rcx
mov    0x8(%rsp),%rax
cmp    %r15,%rax
je     116f <zc_size_parse+0x2f>
test   %rcx,%rcx
js     11fb <zc_size_parse+0xbb>
movsbl (%rax),%edx
lea    -0x47(%rdx),%edi
cmp    $0x26,%edi
ja     1215 <zc_size_parse+0xd5>
movabs $0x100000001,%rsi
bt     %rdi,%rsi
jb     1204 <zc_size_parse+0xc4>
mov    $0x400,%esi
movabs $0x1000000010,%rbx
bt     %rdi,%rbx
jb     11ef <zc_size_parse+0xaf>
movabs $0x4000000040,%rsi
bt     %rdi,%rsi
jae    1215 <zc_size_parse+0xd5>
mov    $0x100000,%esi
cmpb   $0x0,0x1(%rax)
jne    116f <zc_size_parse+0x2f>
jmp    1222 <zc_size_parse+0xe2>
lea    0xdfe(%rip),%rdi
jmp    125d <zc_size_parse+0x11d>
mov    $0x40000000,%esi
cmpb   $0x0,0x1(%rax)
jne    116f <zc_size_parse+0x2f>
jmp    1222 <zc_size_parse+0xe2>
mov    $0x1,%esi
test   %edx,%edx
jne    116f <zc_size_parse+0x2f>
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rdx
shr    $0x20,%rdx
je     124d <zc_size_parse+0x10d>
cqto
idiv   %rsi
cmp    %rax,%rcx
jge    1256 <zc_size_parse+0x116>
imul   %rcx,%rsi
mov    %rsi,(%r14)
xor    %eax,%eax
jmp    118e <zc_size_parse+0x4e>
xor    %edx,%edx
div    %esi
cmp    %rax,%rcx
jl     123f <zc_size_parse+0xff>
lea    0xdb7(%rip),%rdi
call   1040 <zc_strdup@plt>
mov    %rax,%r14
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <zc_err@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1189 <zc_size_parse+0x49>

LLVM IR (-O0):
@errno = global i64 0
@.str = [20 x i8] c"Negative block size\00"
@LONG_MAX = global i64 0
@.str.1 = [21 x i8] c"Block size too large\00"
@LOG_WARNING = global i32 0
@.str.2 = [28 x i8] c"Invalid block size: %s: %s\0A\00"
@.str.3 = [24 x i8] c"Invalid block size: %s\0A\00"
define i32 @zc_size_parse(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64 0, i64* @errno
%9 = load i8*, i8** %4
%10 = call i64 @strtol(i8* %9, i8** %8, i32 0)
store i64 %10, i64* %6
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %8
%15 = load i8*, i8** %4
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13, %2
br label %64
18: ; preds = %13
%19 = load i64, i64* %6
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i8* @zc_strdup(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %8
br label %57
23: ; preds = %18
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %31 [
i32 0, label %27
i32 107, label %28
i32 75, label %28
i32 109, label %29
i32 77, label %29
i32 103, label %30
i32 71, label %30
]
27: ; preds = %23
store i64 1, i64* %7
br label %32
28: ; preds = %23, %23
store i64 1024, i64* %7
br label %32
29: ; preds = %23, %23
store i64 1048576, i64* %7
br label %32
30: ; preds = %23, %23
store i64 1073741824, i64* %7
br label %32
31: ; preds = %23
br label %64
32: ; preds = %30, %29, %28, %27
%33 = load i64, i64* %7
%34 = icmp ne i64 %33, 1
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
br label %64
42: ; preds = %35, %32
%43 = load i64, i64* %6
%44 = load i64, i64* @LONG_MAX
%45 = load i64, i64* %7
%46 = sdiv i64 %44, %45
%47 = icmp sge i64 %43, %46
br i1 %47, label %48, label %51
48: ; preds = %42
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %8
%49 = load i8*, i8** %8
%50 = call i8* @zc_strdup(i8* %49)
store i8* %50, i8** %8
br label %57
51: ; preds = %42
%52 = load i64, i64* %7
%53 = load i64, i64* %6
%54 = mul nsw i64 %53, %52
store i64 %54, i64* %6
%55 = load i64, i64* %6
%56 = load i64*, i64** %5
store i64 %55, i64* %56
store i32 0, i32* %3
br label %68
57: ; preds = %48, %21
%58 = load i32, i32* @LOG_WARNING
%59 = load i8*, i8** %4
%60 = load i8*, i8** %8
%61 = call i32 (i32, i8*, i8*, ...) @zc_err(i32 %58, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %59, i8* %60)
%62 = load i8*, i8** %8
%63 = call i32 @free(i8* %62)
store i32 -1, i32* %3
br label %68
64: ; preds = %41, %31, %17
%65 = load i32, i32* @LOG_WARNING
%66 = load i8*, i8** %4
%67 = call i32 (i32, i8*, i8*, ...) @zc_err(i32 %65, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %66)
store i32 -1, i32* %3
br label %68
68: ; preds = %64, %57, %51
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [20 x i8] c"Negative block size\00"
@LONG_MAX = global i64 0
@.str.1 = [21 x i8] c"Block size too large\00"
@LOG_WARNING = global i32 0
@.str.2 = [28 x i8] c"Invalid block size: %s: %s\0A\00"
@.str.3 = [24 x i8] c"Invalid block size: %s\0A\00"
define i32 @zc_size_parse(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, %0
br i1 %10, label %36, label %11
11: ; preds = %8
%12 = icmp slt i64 %5, 0
br i1 %12, label %30, label %13
13: ; preds = %11
%14 = load i8, i8* %9
%15 = sext i8 %14 to i32
switch i32 %15, label %36 [
i32 0, label %23
i32 107, label %18
i32 75, label %18
i32 109, label %16
i32 77, label %16
i32 103, label %17
i32 71, label %17
]
16: ; preds = %13, %13
br label %18
17: ; preds = %13, %13
br label %18
18: ; preds = %13, %13, %17, %16
%19 = phi i64 [ 1048576, %16 ], [ 1073741824, %17 ], [ 1024, %13 ], [ 1024, %13 ]
%20 = getelementptr inbounds i8, i8* %9, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %13, %18
%24 = phi i64 [ %19, %18 ], [ 1, %13 ]
%25 = load i64, i64* @LONG_MAX
%26 = sdiv i64 %25, %24
%27 = icmp slt i64 %5, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = mul nsw i64 %24, %5
store i64 %29, i64* %1
br label %39
30: ; preds = %23, %11
%31 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %23 ]
%32 = tail call i8* @zc_strdup(i8* %31)
%33 = load i32, i32* @LOG_WARNING
%34 = tail call i32 (i32, i8*, i8*, ...) @zc_err(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %32)
%35 = tail call i32 @free(i8* %32)
br label %39
36: ; preds = %18, %13, %2, %8
%37 = load i32, i32* @LOG_WARNING
%38 = tail call i32 (i32, i8*, i8*, ...) @zc_err(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %39
39: ; preds = %36, %30, %28
%40 = phi i32 [ -1, %36 ], [ -1, %30 ], [ 0, %28 ]
ret i32 %40
}