#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 */
int atoi(char *);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
int strlen(char *);
int get_bytes(char *cur_arg) {
  int size = 0;
  char c = cur_arg[strlen(cur_arg) - 1];
  char *temp = strdup(cur_arg);
  temp[strlen(temp) - 1] = '\0';
  size = atoi(temp);
  free(temp);
  switch (c) {
  case 'm':
  case 'M':
    size *= 1024;
  case 'k':
  case 'K':
    size *= 1024;
  case 'b':
  case 'B':
    break;
  default:
    return -1;
  }
  return size;
}


x86 assembly (clang, -O0):
<get_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    %rdi,-0x38(%rbp)
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    %rdi,-0x30(%rbp)
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x42,%eax
je     122d <get_bytes+0xed>
jmp    11c6 <get_bytes+0x86>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     1224 <get_bytes+0xe4>
jmp    11d7 <get_bytes+0x97>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     121b <get_bytes+0xdb>
jmp    11e8 <get_bytes+0xa8>
mov    -0x24(%rbp),%eax
sub    $0x62,%eax
je     122d <get_bytes+0xed>
jmp    11f9 <get_bytes+0xb9>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     1224 <get_bytes+0xe4>
jmp    120a <get_bytes+0xca>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
jne    1232 <get_bytes+0xf2>
jmp    121b <get_bytes+0xdb>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x14(%rbp)
jmp    123e <get_bytes+0xfe>
movl   $0xffffffff,-0x4(%rbp)
jmp    1244 <get_bytes+0x104>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bytes>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%ebp
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0xffffffbe,%ebp
cmp    $0x2b,%ebp
ja     11c8 <get_bytes+0x88>
movabs $0x100000001,%rcx
bt     %rbp,%rcx
jb     11c5 <get_bytes+0x85>
movabs $0x20000000200,%rcx
bt     %rbp,%rcx
jb     11c1 <get_bytes+0x81>
movabs $0x80000000800,%rcx
bt     %rbp,%rcx
jae    11c8 <get_bytes+0x88>
shl    $0xa,%r14d
shl    $0xa,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_bytes(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = load i8*, i8** %3
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %16, i64 %20
store i8 0, i8* %21
%22 = load i8*, i8** %6
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %4
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
switch i32 %27, label %35 [
i32 109, label %28
i32 77, label %28
i32 107, label %31
i32 75, label %31
i32 98, label %34
i32 66, label %34
]
28: ; preds = %1, %1
%29 = load i32, i32* %4
%30 = mul nsw i32 %29, 1024
store i32 %30, i32* %4
br label %31
31: ; preds = %1, %1, %28
%32 = load i32, i32* %4
%33 = mul nsw i32 %32, 1024
store i32 %33, i32* %4
br label %34
34: ; preds = %1, %1, %31
br label %36
35: ; preds = %1
store i32 -1, i32* %2
br label %38
36: ; preds = %34
%37 = load i32, i32* %4
store i32 %37, i32* %2
br label %38
38: ; preds = %36, %35
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @get_bytes(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = tail call i8* @strdup(i8* %0)
%8 = tail call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @atoi(i8* %7)
%13 = tail call i32 @free(i8* %7)
%14 = sext i8 %6 to i32
switch i32 %14, label %22 [
i32 109, label %15
i32 77, label %15
i32 107, label %17
i32 75, label %17
i32 98, label %20
i32 66, label %20
]
15: ; preds = %1, %1
%16 = shl nsw i32 %12, 10
br label %17
17: ; preds = %1, %1, %15
%18 = phi i32 [ %12, %1 ], [ %12, %1 ], [ %16, %15 ]
%19 = shl nsw i32 %18, 10
br label %20
20: ; preds = %17, %1, %1
%21 = phi i32 [ %12, %1 ], [ %12, %1 ], [ %19, %17 ]
br label %22
22: ; preds = %1, %20
%23 = phi i32 [ %21, %20 ], [ -1, %1 ]
ret i32 %23
}