#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 EINVAL;
scalar_t__ UINT64_MAX;
scalar_t__ strtoull(char *, char **, int /*<<< orphan*/);
int get_number(char *arg, uint64_t *res) {
  char *ptr = NULL;
  uint64_t num;
  num = strtoull(arg, &ptr, 0);
  if ((ptr == arg) || (num == UINT64_MAX))
    return (-EINVAL);
  switch (*ptr) {
  case '\0':
    break;
  case 'g':
  case 'G':
    num *= 1024;
  case 'm':
  case 'M':
    num *= 1024;
  case 'k':
  case 'K':
    num *= 1024;
  case 'b':
  case 'B':
    break;
  default:
    return (-EINVAL);
  }
  *res = num;
  return (0);
}


x86 assembly (clang, -O0):
<get_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     115d <get_number+0x4d>
mov    -0x28(%rbp),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
jne    1170 <get_number+0x60>
xor    %eax,%eax
mov    0x2e7a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1262 <get_number+0x152>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     120f <get_number+0xff>
jmp    1187 <get_number+0x77>
mov    -0x2c(%rbp),%eax
sub    $0x42,%eax
je     1238 <get_number+0x128>
jmp    1198 <get_number+0x88>
mov    -0x2c(%rbp),%eax
sub    $0x47,%eax
je     1214 <get_number+0x104>
jmp    11a9 <get_number+0x99>
mov    -0x2c(%rbp),%eax
sub    $0x4b,%eax
je     122c <get_number+0x11c>
jmp    11ba <get_number+0xaa>
mov    -0x2c(%rbp),%eax
sub    $0x4d,%eax
je     1220 <get_number+0x110>
jmp    11cb <get_number+0xbb>
mov    -0x2c(%rbp),%eax
sub    $0x62,%eax
je     1238 <get_number+0x128>
jmp    11dc <get_number+0xcc>
mov    -0x2c(%rbp),%eax
sub    $0x67,%eax
je     1214 <get_number+0x104>
jmp    11ed <get_number+0xdd>
mov    -0x2c(%rbp),%eax
sub    $0x6b,%eax
je     122c <get_number+0x11c>
jmp    11fe <get_number+0xee>
mov    -0x2c(%rbp),%eax
sub    $0x6d,%eax
je     1220 <get_number+0x110>
jmp    123d <get_number+0x12d>
jmp    1250 <get_number+0x140>
mov    -0x28(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x28(%rbp)
jmp    1250 <get_number+0x140>
xor    %eax,%eax
mov    0x2d9a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1262 <get_number+0x152>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_number>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     1179 <get_number+0x69>
mov    0x2e8a(%rip),%rdx
cmp    (%rdx),%rax
je     1179 <get_number+0x69>
movsbl (%rcx),%edx
lea    -0x42(%rdx),%ecx
cmp    $0x2b,%ecx
ja     118d <get_number+0x7d>
lea    0xea3(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,(%r14)
xor    %ebp,%ebp
jmp    1182 <get_number+0x72>
mov    0x2e60(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %edx,%edx
je     1172 <get_number+0x62>
mov    0x2e48(%rip),%rax
xor    %ebp,%ebp
jmp    1180 <get_number+0x70>

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

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