#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 */
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
int ULLONG_MAX;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strtoull(char *, char **, int /*<<< orphan*/);
uint64_t __str_to_num(char *str) {
  char *s = str;
  uint64_t num = strtoull(s, &s, 0);
  if (*s == '\0')
    return num;
  if (strcmp(s, "KiB") == 0)
    num *= 1024;
  else if (strcmp(s, "MiB") == 0)
    num *= 1024 * 1024;
  else if (strcmp(s, "GiB") == 0)
    num *= 1024 * 1024 * 1024;
  else {
    do {
      fprintf(stderr,
              "%s:%u: Error: "
              "--size or -s out of range, use KiB/MiB or GiB only\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/open-power/snap/refs/heads/master/"
              "software/include/snap_tools.h",
              141);
    } while (0);
    num = ULLONG_MAX;
    errno = ERANGE;
    exit(EXIT_FAILURE);
  }
  return num;
}


x86 assembly (clang, -O0):
<__str_to_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1181 <__str_to_num+0x41>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <__str_to_num+0x11b>
mov    -0x18(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a9 <__str_to_num+0x69>
mov    -0x1c(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x1c(%rbp)
jmp    1255 <__str_to_num+0x115>
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <__str_to_num+0x91>
mov    -0x1c(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x1c(%rbp)
jmp    1250 <__str_to_num+0x110>
mov    -0x18(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f9 <__str_to_num+0xb9>
mov    -0x1c(%rbp),%eax
shl    $0x1e,%eax
mov    %eax,-0x1c(%rbp)
jmp    124b <__str_to_num+0x10b>
jmp    11fe <__str_to_num+0xbe>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
lea    0xe39(%rip),%rdx
mov    $0x8d,%ecx
call   1050 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8d(%rip),%rax
mov    %ecx,(%rax)
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1250 <__str_to_num+0x110>
jmp    1255 <__str_to_num+0x115>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__str_to_num>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,(%rsp)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %eax,%ebp
mov    (%rsp),%rbx
cmpb   $0x0,(%rbx)
je     11a5 <__str_to_num+0x65>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     119d <__str_to_num+0x5d>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a2 <__str_to_num+0x62>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11ae <__str_to_num+0x6e>
shl    $0x1e,%ebp
jmp    11a5 <__str_to_num+0x65>
shl    $0xa,%ebp
jmp    11a5 <__str_to_num+0x65>
shl    $0x14,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
lea    0xe89(%rip),%rdx
mov    $0x8d,%ecx
call   1050 <fprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    0x2df1(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"KiB\00"
@.str.1 = [4 x i8] c"MiB\00"
@.str.2 = [4 x i8] c"GiB\00"
@stderr = global i32 0
@.str.3 = [66 x i8] c"%s:%u: Error: --size or -s out of range, use KiB/MiB or GiB only\0A\00"
@.str.4 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/open-power/snap/refs/heads/master/software/include/snap_tools.h\00"
@ULLONG_MAX = global i32 0
@ERANGE = global i32 0
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @__str_to_num(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strtoull(i8* %7, i8** %4, i32 0)
store i32 %8, i32* %5
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %5
store i32 %14, i32* %2
br label %49
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 1024
store i32 %21, i32* %5
br label %47
22: ; preds = %15
%23 = load i8*, i8** %4
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %5
%28 = mul nsw i32 %27, 1048576
store i32 %28, i32* %5
br label %46
29: ; preds = %22
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %5
%35 = mul nsw i32 %34, 1073741824
store i32 %35, i32* %5
br label %45
36: ; preds = %29
br label %37
37: ; preds = %36
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.4, i64 0, i64 0), i32 141)
br label %40
40: ; preds = %37
%41 = load i32, i32* @ULLONG_MAX
store i32 %41, i32* %5
%42 = load i32, i32* @ERANGE
store i32 %42, i32* @errno
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %33
br label %46
46: ; preds = %45, %26
br label %47
47: ; preds = %46, %19
%48 = load i32, i32* %5
store i32 %48, i32* %2
br label %49
49: ; preds = %47, %13
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@.str = [4 x i8] c"KiB\00"
@.str.1 = [4 x i8] c"MiB\00"
@.str.2 = [4 x i8] c"GiB\00"
@stderr = global i32 0
@.str.3 = [66 x i8] c"%s:%u: Error: --size or -s out of range, use KiB/MiB or GiB only\0A\00"
@.str.4 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/open-power/snap/refs/heads/master/software/include/snap_tools.h\00"
@ULLONG_MAX = global i32 0
@ERANGE = global i32 0
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @__str_to_num(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* %0, i8** %2
%4 = call i32 @strtoull(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %1
%9 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = shl nsw i32 %4, 10
br label %29
13: ; preds = %8
%14 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = shl nsw i32 %4, 20
br label %29
18: ; preds = %13
%19 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = shl nsw i32 %4, 30
br label %29
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.4, i64 0, i64 0), i32 141)
%26 = load i32, i32* @ERANGE
store i32 %26, i32* @errno
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %11, %21, %16, %1
%30 = phi i32 [ %4, %1 ], [ %12, %11 ], [ %17, %16 ], [ %22, %21 ]
ret i32 %30
}