#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__ isdigit(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strlen(char const *);
size_t strtol(char *, int /*<<< orphan*/ *, int);
size_t zje_parse_bytes(const char *string) {
  int len = strlen(string);
  char str[len + 1];
  snprintf(str, len + 1, "%s", string);
  int pos = len - 1;
  for (; pos >= 0 && isspace(str[pos]); --pos) {
    str[pos] = '\0';
  }
  if (pos < 0) {
    return 0;
  }
  size_t bytes = strtol(str, NULL, 10);
  if (bytes == 0) {
    return 0;
  }
  if (isdigit(str[pos])) {
    return bytes;
  }
  switch (str[pos]) {
  case 'b':
  case 'B':
    break;
  case 'k':
  case 'K':
    bytes <<= 10;
    break;
  case 'm':
  case 'M':
    bytes <<= 20;
    break;
  default:
    return 0;
  }
  return bytes;
}


x86 assembly (clang, -O0):
<zje_parse_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rcx
lea    0xe5e(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x41(%rbp)
jl     11da <zje_parse_bytes+0x8a>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11ea <zje_parse_bytes+0x9a>
jmp    1204 <zje_parse_bytes+0xb4>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b0 <zje_parse_bytes+0x60>
cmpl   $0x0,-0x2c(%rbp)
jge    1222 <zje_parse_bytes+0xd2>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1342 <zje_parse_bytes+0x1f2>
mov    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1257 <zje_parse_bytes+0x107>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1342 <zje_parse_bytes+0x1f2>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1286 <zje_parse_bytes+0x136>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1342 <zje_parse_bytes+0x1f2>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x48(%rbp)
sub    $0x42,%eax
je     12f8 <zje_parse_bytes+0x1a8>
jmp    12a3 <zje_parse_bytes+0x153>
mov    -0x48(%rbp),%eax
sub    $0x4b,%eax
je     12fd <zje_parse_bytes+0x1ad>
jmp    12b4 <zje_parse_bytes+0x164>
mov    -0x48(%rbp),%eax
sub    $0x4d,%eax
je     130e <zje_parse_bytes+0x1be>
jmp    12c5 <zje_parse_bytes+0x175>
mov    -0x48(%rbp),%eax
sub    $0x62,%eax
je     12f8 <zje_parse_bytes+0x1a8>
jmp    12d6 <zje_parse_bytes+0x186>
mov    -0x48(%rbp),%eax
sub    $0x6b,%eax
je     12fd <zje_parse_bytes+0x1ad>
jmp    12e7 <zje_parse_bytes+0x197>
mov    -0x48(%rbp),%eax
sub    $0x6d,%eax
je     130e <zje_parse_bytes+0x1be>
jmp    131f <zje_parse_bytes+0x1cf>
jmp    1333 <zje_parse_bytes+0x1e3>
mov    -0x38(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x38(%rbp)
jmp    1333 <zje_parse_bytes+0x1e3>
mov    -0x38(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x38(%rbp)
jmp    1333 <zje_parse_bytes+0x1e3>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1342 <zje_parse_bytes+0x1f2>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zje_parse_bytes>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0x1(%r14),%esi
mov    %rsp,%r12
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe7b(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rcx
call   1050 <snprintf@plt>
test   %r14d,%r14d
jle    11c4 <zje_parse_bytes+0x74>
mov    %r14d,%ebx
add    $0x1,%rbx
xor    %r14d,%r14d
nop
lea    -0x2(%rbx),%r13d
movsbl (%r12,%r13,1),%edi
call   1060 <isspace@plt>
test   %rax,%rax
je     11c9 <zje_parse_bytes+0x79>
movb   $0x0,(%r12,%r13,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11a0 <zje_parse_bytes+0x50>
jmp    11f5 <zje_parse_bytes+0xa5>
xor    %r14d,%r14d
jmp    11f5 <zje_parse_bytes+0xa5>
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
test   %rax,%rax
je     11f5 <zje_parse_bytes+0xa5>
mov    %rax,%r15
movsbl (%r12,%r13,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1207 <zje_parse_bytes+0xb7>
mov    %r15,%r14
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsbl (%r12,%r13,1),%eax
xor    %r14d,%r14d
add    $0xffffffbe,%eax
cmp    $0x2b,%eax
ja     11f5 <zje_parse_bytes+0xa5>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     11f2 <zje_parse_bytes+0xa2>
movabs $0x20000000200,%rcx
bt     %rax,%rcx
jb     124d <zje_parse_bytes+0xfd>
movabs $0x80000000800,%rcx
bt     %rax,%rcx
jae    11f5 <zje_parse_bytes+0xa5>
shl    $0x14,%r15
jmp    11f2 <zje_parse_bytes+0xa2>
shl    $0xa,%r15
jmp    11f2 <zje_parse_bytes+0xa2>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i64 @zje_parse_bytes(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i8, i64 %14
store i64 %14, i64* %6
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = load i8*, i8** %3
%20 = call i32 @snprintf(i8* %16, i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %7
br label %23
23: ; preds = %39, %1
%24 = load i32, i32* %7
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %16, i64 %28
%30 = load i8, i8* %29
%31 = call i64 @isspace(i8 signext %30)
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %26, %23
%34 = phi i1 [ false, %23 ], [ %32, %26 ]
br i1 %34, label %35, label %42
35: ; preds = %33
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %16, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %35
%40 = load i32, i32* %7
%41 = add nsw i32 %40, -1
store i32 %41, i32* %7
br label %23
42: ; preds = %33
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42
store i64 0, i64* %2
store i32 1, i32* %8
br label %76
46: ; preds = %42
%47 = call i64 @strtol(i8* %16, i32* null, i32 10)
store i64 %47, i64* %9
%48 = load i64, i64* %9
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i64 0, i64* %2
store i32 1, i32* %8
br label %76
51: ; preds = %46
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %16, i64 %53
%55 = load i8, i8* %54
%56 = call i64 @isdigit(i8 signext %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = load i64, i64* %9
store i64 %59, i64* %2
store i32 1, i32* %8
br label %76
60: ; preds = %51
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %16, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
switch i32 %65, label %73 [
i32 98, label %66
i32 66, label %66
i32 107, label %67
i32 75, label %67
i32 109, label %70
i32 77, label %70
]
66: ; preds = %60, %60
br label %74
67: ; preds = %60, %60
%68 = load i64, i64* %9
%69 = shl i64 %68, 10
store i64 %69, i64* %9
br label %74
70: ; preds = %60, %60
%71 = load i64, i64* %9
%72 = shl i64 %71, 20
store i64 %72, i64* %9
br label %74
73: ; preds = %60
store i64 0, i64* %2
store i32 1, i32* %8
br label %76
74: ; preds = %70, %67, %66
%75 = load i64, i64* %9
store i64 %75, i64* %2
store i32 1, i32* %8
br label %76
76: ; preds = %74, %73, %58, %50, %45
%77 = load i8*, i8** %5
%78 = load i64, i64* %2
ret i64 %78
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i64 @zje_parse_bytes(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %36
8: ; preds = %1
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %18
%11 = phi i64 [ %9, %8 ], [ %12, %18 ]
%12 = add nsw i64 %11, -1
%13 = and i64 %12, 4294967295
%14 = getelementptr inbounds i8, i8* %5, i64 %13
%15 = load i8, i8* %14
%16 = call i64 @isspace(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %10
store i8 0, i8* %14
%19 = icmp ugt i64 %11, 1
br i1 %19, label %10, label %36
20: ; preds = %10
%21 = call i64 @strtol(i8* nocapture %5, i32* null, i32 10)
%22 = icmp eq i64 %21, 0
br i1 %22, label %36, label %23
23: ; preds = %20
%24 = load i8, i8* %14
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i8, i8* %14
%29 = sext i8 %28 to i32
switch i32 %29, label %36 [
i32 98, label %34
i32 66, label %34
i32 107, label %30
i32 75, label %30
i32 109, label %32
i32 77, label %32
]
30: ; preds = %27, %27
%31 = shl i64 %21, 10
br label %34
32: ; preds = %27, %27
%33 = shl i64 %21, 20
br label %34
34: ; preds = %27, %27, %32, %30
%35 = phi i64 [ %33, %32 ], [ %31, %30 ], [ %21, %27 ], [ %21, %27 ]
br label %36
36: ; preds = %18, %1, %34, %20, %23, %27
%37 = phi i64 [ %35, %34 ], [ 0, %20 ], [ %21, %23 ], [ 0, %27 ], [ 0, %1 ], [ 0, %18 ]
ret i64 %37
}