#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 */
size_t atoi(char *);
size_t strlen(char *);
size_t parse_size(char *optarg) {
  size_t test_mem_size_multi = 1;
  char multi = optarg[strlen(optarg) - 1];
  if (multi == 'b' || multi == 'B') {
    optarg[strlen(optarg) - 1] = optarg[strlen(optarg)];
    multi = optarg[strlen(optarg) - 1];
  }
  if (multi == 'k' || multi == 'K') {
    test_mem_size_multi = 1024;
    optarg[strlen(optarg) - 1] = optarg[strlen(optarg)];
  } else if (multi == 'm' || multi == 'M') {
    test_mem_size_multi = 1024 * 1024LL;
    optarg[strlen(optarg) - 1] = optarg[strlen(optarg)];
  } else if (multi == 'g' || multi == 'G') {
    test_mem_size_multi = 1024 * 1024 * 1024LL;
    optarg[strlen(optarg) - 1] = optarg[strlen(optarg)];
  }
  return test_mem_size_multi * atoi(optarg);
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    $0x1,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x62,%eax
je     1173 <parse_size+0x53>
movsbl -0x11(%rbp),%eax
cmp    $0x42,%eax
jne    11d5 <parse_size+0xb5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x31(%rbp),%dl
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    $0x1,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x6b,%eax
je     11ef <parse_size+0xcf>
movsbl -0x11(%rbp),%eax
cmp    $0x4b,%eax
jne    123c <parse_size+0x11c>
movq   $0x400,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x49(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x49(%rbp),%dl
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1315 <parse_size+0x1f5>
movsbl -0x11(%rbp),%eax
cmp    $0x6d,%eax
je     1256 <parse_size+0x136>
movsbl -0x11(%rbp),%eax
cmp    $0x4d,%eax
jne    12a3 <parse_size+0x183>
movq   $0x100000,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x61(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x61(%rbp),%dl
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1310 <parse_size+0x1f0>
movsbl -0x11(%rbp),%eax
cmp    $0x67,%eax
je     12bd <parse_size+0x19d>
movsbl -0x11(%rbp),%eax
cmp    $0x47,%eax
jne    130b <parse_size+0x1eb>
movq   $0x40000000,-0x10(%rbp)
40
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x79(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x79(%rbp),%dl
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1310 <parse_size+0x1f0>
jmp    1315 <parse_size+0x1f5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
imul   %rcx,%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    -0x1(%rax,%rbx,1),%cl
mov    %ecx,%edx
and    $0xdf,%dl
cmp    $0x42,%dl
jne    114d <parse_size+0x2d>
mov    (%rbx,%rax,1),%cl
mov    %cl,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    -0x1(%rax,%rbx,1),%cl
and    $0xdf,%cl
cmp    $0x47,%cl
je     116d <parse_size+0x4d>
cmp    $0x4b,%cl
je     1175 <parse_size+0x55>
mov    $0x1,%r14d
cmp    $0x4d,%cl
jne    118a <parse_size+0x6a>
mov    $0x100000,%r14d
jmp    117b <parse_size+0x5b>
mov    $0x40000000,%r14d
jmp    117b <parse_size+0x5b>
mov    $0x400,%r14d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    (%rbx,%rax,1),%cl
mov    %cl,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1040 <atoi@plt>
imul   %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8
store i8* %0, i8** %2
store i64 1, i64* %3
%5 = load i8*, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = sub i64 %7, 1
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = load i8, i8* %9
store i8 %10, i8* %4
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 98
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 66
br i1 %17, label %18, label %35
18: ; preds = %14, %1
%19 = load i8*, i8** %2
%20 = load i8*, i8** %2
%21 = call i64 @strlen(i8* %20)
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %2
%25 = load i8*, i8** %2
%26 = call i64 @strlen(i8* %25)
%27 = sub i64 %26, 1
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %23, i8* %28
%29 = load i8*, i8** %2
%30 = load i8*, i8** %2
%31 = call i64 @strlen(i8* %30)
%32 = sub i64 %31, 1
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %4
br label %35
35: ; preds = %18, %14
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 107
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i8, i8* %4
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 75
br i1 %42, label %43, label %54
43: ; preds = %39, %35
store i64 1024, i64* %3
%44 = load i8*, i8** %2
%45 = load i8*, i8** %2
%46 = call i64 @strlen(i8* %45)
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %2
%50 = load i8*, i8** %2
%51 = call i64 @strlen(i8* %50)
%52 = sub i64 %51, 1
%53 = getelementptr inbounds i8, i8* %49, i64 %52
store i8 %48, i8* %53
br label %94
54: ; preds = %39
%55 = load i8, i8* %4
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 109
br i1 %57, label %62, label %58
58: ; preds = %54
%59 = load i8, i8* %4
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 77
br i1 %61, label %62, label %73
62: ; preds = %58, %54
store i64 1048576, i64* %3
%63 = load i8*, i8** %2
%64 = load i8*, i8** %2
%65 = call i64 @strlen(i8* %64)
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = load i8*, i8** %2
%69 = load i8*, i8** %2
%70 = call i64 @strlen(i8* %69)
%71 = sub i64 %70, 1
%72 = getelementptr inbounds i8, i8* %68, i64 %71
store i8 %67, i8* %72
br label %93
73: ; preds = %58
%74 = load i8, i8* %4
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 103
br i1 %76, label %81, label %77
77: ; preds = %73
%78 = load i8, i8* %4
%79 = sext i8 %78 to i32
%80 = icmp eq i32 %79, 71
br i1 %80, label %81, label %92
81: ; preds = %77, %73
store i64 1073741824, i64* %3
%82 = load i8*, i8** %2
%83 = load i8*, i8** %2
%84 = call i64 @strlen(i8* %83)
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8, i8* %85
%87 = load i8*, i8** %2
%88 = load i8*, i8** %2
%89 = call i64 @strlen(i8* %88)
%90 = sub i64 %89, 1
%91 = getelementptr inbounds i8, i8* %87, i64 %90
store i8 %86, i8* %91
br label %92
92: ; preds = %81, %77
br label %93
93: ; preds = %92, %62
br label %94
94: ; preds = %93, %43
%95 = load i64, i64* %3
%96 = load i8*, i8** %2
%97 = call i64 @atoi(i8* %96)
%98 = mul i64 %95, %97
ret i64 %98
}

LLVM IR (-O2):
define i64 @parse_size(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, -1
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = and i8 %5, -33
%7 = icmp eq i8 %6, 66
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %0, i64 %2
%10 = load i8, i8* %9
store i8 %10, i8* %4
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = add i64 %11, -1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
br label %15
15: ; preds = %1, %8
%16 = phi i8 [ %14, %8 ], [ %5, %1 ]
%17 = and i8 %16, -33
switch i8 %17, label %27 [
i8 75, label %20
i8 77, label %18
i8 71, label %19
]
18: ; preds = %15
br label %20
19: ; preds = %15
br label %20
20: ; preds = %15, %19, %18
%21 = phi i64 [ 1073741824, %19 ], [ 1048576, %18 ], [ 1024, %15 ]
%22 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = add i64 %22, -1
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %24, i8* %26
br label %27
27: ; preds = %20, %15
%28 = phi i64 [ 1, %15 ], [ %21, %20 ]
%29 = tail call i64 @atoi(i8* %0)
%30 = mul i64 %29, %28
ret i64 %30
}