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

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int strtoll(char *, char **, int);
int parsesize(char *spec, off_t *size, char *errbuf) {
  char *ep;
  errno = 0;
  *size = strtoll(spec, &ep, 10);
  if (errno || strlen(ep) > 1 || size <= 0)
    goto error;
  switch (*ep) {
  case '\0':
    break;
  case 'k':
  case 'K':
    *size <<= 10;
    break;
  case 'm':
  case 'M':
    *size <<= 20;
    break;
  case 'g':
  case 'G':
    *size <<= 30;
    break;
  default:
    goto error;
  }
  return 0;
error:
  strcpy(errbuf, "bogus size");
  return -1;
}


x86 assembly (clang, -O0):
<parsesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoll@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e6d(%rip),%rax
cmpq   $0x0,(%rax)
jne    119a <parsesize+0x6a>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jg     119a <parsesize+0x6a>
cmpq   $0x0,-0x18(%rbp)
ja     119f <parsesize+0x6f>
jmp    1262 <parsesize+0x132>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     121c <parsesize+0xec>
jmp    11b6 <parsesize+0x86>
mov    -0x2c(%rbp),%eax
sub    $0x47,%eax
je     1241 <parsesize+0x111>
jmp    11c7 <parsesize+0x97>
mov    -0x2c(%rbp),%eax
sub    $0x4b,%eax
je     1221 <parsesize+0xf1>
jmp    11d8 <parsesize+0xa8>
mov    -0x2c(%rbp),%eax
sub    $0x4d,%eax
je     1231 <parsesize+0x101>
jmp    11e9 <parsesize+0xb9>
mov    -0x2c(%rbp),%eax
sub    $0x67,%eax
je     1241 <parsesize+0x111>
jmp    11fa <parsesize+0xca>
mov    -0x2c(%rbp),%eax
sub    $0x6b,%eax
je     1221 <parsesize+0xf1>
jmp    120b <parsesize+0xdb>
mov    -0x2c(%rbp),%eax
sub    $0x6d,%eax
je     1231 <parsesize+0x101>
jmp    1251 <parsesize+0x121>
jmp    1256 <parsesize+0x126>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0xa,%ecx
mov    %ecx,(%rax)
jmp    1256 <parsesize+0x126>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x14,%ecx
mov    %ecx,(%rax)
jmp    1256 <parsesize+0x126>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1e,%ecx
mov    %ecx,(%rax)
jmp    1256 <parsesize+0x126>
jmp    1262 <parsesize+0x132>
movl   $0x0,-0x4(%rbp)
jmp    1279 <parsesize+0x149>
mov    -0x20(%rbp),%rdi
lea    0xd93(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsesize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    0x2e9b(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtoll@plt>
mov    %eax,(%r12)
cmpq   $0x0,(%rbx)
jne    1174 <parsesize+0x44>
mov    (%rsp),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jle    1194 <parsesize+0x64>
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
movsbl (%r15),%eax
lea    -0x47(%rax),%ecx
cmp    $0x26,%ecx
ja     11e7 <parsesize+0xb7>
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     11d7 <parsesize+0xa7>
movabs $0x1000000010,%rdx
bt     %rcx,%rdx
jb     11de <parsesize+0xae>
movabs $0x4000000040,%rdx
bt     %rcx,%rdx
jae    11e7 <parsesize+0xb7>
shll   $0x14,(%r12)
jmp    11e3 <parsesize+0xb3>
shll   $0x1e,(%r12)
jmp    11e3 <parsesize+0xb3>
shll   $0xa,(%r12)
xor    %eax,%eax
jmp    1188 <parsesize+0x58>
test   %eax,%eax
jne    1174 <parsesize+0x44>
jmp    1188 <parsesize+0x58>

LLVM IR (-O0):
@errno = global i64 0
@.str = [11 x i8] c"bogus size\00"
define i32 @parsesize(i8* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i64 0, i64* @errno
%9 = load i8*, i8** %5
%10 = call i32 @strtoll(i8* %9, i8** %8, i32 10)
%11 = load i32*, i32** %6
store i32 %10, i32* %11
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = call i32 @strlen(i8* %15)
%17 = icmp sgt i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32*, i32** %6
%20 = icmp ule i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18, %14, %3
br label %41
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
switch i32 %25, label %39 [
i32 0, label %26
i32 107, label %27
i32 75, label %27
i32 109, label %31
i32 77, label %31
i32 103, label %35
i32 71, label %35
]
26: ; preds = %22
br label %40
27: ; preds = %22, %22
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = shl i32 %29, 10
store i32 %30, i32* %28
br label %40
31: ; preds = %22, %22
%32 = load i32*, i32** %6
%33 = load i32, i32* %32
%34 = shl i32 %33, 20
store i32 %34, i32* %32
br label %40
35: ; preds = %22, %22
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = shl i32 %37, 30
store i32 %38, i32* %36
br label %40
39: ; preds = %22
br label %41
40: ; preds = %35, %31, %27, %26
store i32 0, i32* %4
br label %44
41: ; preds = %39, %21
%42 = load i8*, i8** %7
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %44
44: ; preds = %41, %40
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [11 x i8] c"bogus size\00"
define i32 @parsesize(i8* %0, i32* nocapture %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i64 0, i64* @errno
%6 = call i32 @strtoll(i8* %0, i8** %4, i32 10)
store i32 %6, i32* %1
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = tail call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, 1
br i1 %12, label %25, label %13
13: ; preds = %9
%14 = load i8, i8* %10
%15 = sext i8 %14 to i32
switch i32 %15, label %25 [
i32 0, label %27
i32 107, label %16
i32 75, label %16
i32 109, label %19
i32 77, label %19
i32 103, label %22
i32 71, label %22
]
16: ; preds = %13, %13
%17 = load i32, i32* %1
%18 = shl i32 %17, 10
store i32 %18, i32* %1
br label %27
19: ; preds = %13, %13
%20 = load i32, i32* %1
%21 = shl i32 %20, 20
store i32 %21, i32* %1
br label %27
22: ; preds = %13, %13
%23 = load i32, i32* %1
%24 = shl i32 %23, 30
store i32 %24, i32* %1
br label %27
25: ; preds = %13, %3, %9
%26 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %13, %16, %19, %22, %25
%28 = phi i32 [ -1, %25 ], [ 0, %22 ], [ 0, %19 ], [ 0, %16 ], [ %15, %13 ]
ret i32 %28
}