#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*/ memcpy(char *, char *, int);
int strlen(char *);
unsigned long get_bytes(char *bytes) {
  unsigned long res = 0;
  if ((bytes[strlen(bytes) - 1] == 'k') || (bytes[strlen(bytes) - 1] == 'K')) {
    char temp_bytes[strlen(bytes) - 1];
    memcpy(temp_bytes, bytes, strlen(bytes) - 1);
    res = atoi(temp_bytes) * 1024;
  } else
    res = atoi(bytes);
  return res;
}


x86 assembly (clang, -O0):
<get_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6b,%eax
je     1198 <get_bytes+0x68>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4b,%eax
jne    1208 <get_bytes+0xd8>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rdi
call   1050 <atoi@plt>
shl    $0xa,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1217 <get_bytes+0xe7>
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bytes>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
cmpb   $0x6b,-0x1(%rax,%r14,1)
je     115e <get_bytes+0x2e>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x4b,-0x1(%rax,%r14,1)
jne    11a3 <get_bytes+0x73>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r15
add    $0xffffffff,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    -0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1050 <atoi@plt>
shl    $0xa,%eax
mov    %r15,%rsp
jmp    11ab <get_bytes+0x7b>
mov    %r14,%rdi
call   1050 <atoi@plt>
cltq
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @get_bytes(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 107
br i1 %14, label %25, label %15
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = load i8*, i8** %2
%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
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 75
br i1 %24, label %25, label %41
25: ; preds = %15, %1
%26 = load i8*, i8** %2
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = zext i32 %28 to i64
%30 = call i8* @llvm.stacksave()
store i8* %30, i8** %4
%31 = alloca i8, i64 %29
store i64 %29, i64* %5
%32 = load i8*, i8** %2
%33 = load i8*, i8** %2
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = call i32 @memcpy(i8* %31, i8* %32, i32 %35)
%37 = call i32 @atoi(i8* %31)
%38 = mul nsw i32 %37, 1024
%39 = sext i32 %38 to i64
store i64 %39, i64* %3
%40 = load i8*, i8** %4
br label %45
41: ; preds = %15
%42 = load i8*, i8** %2
%43 = call i32 @atoi(i8* %42)
%44 = sext i32 %43 to i64
store i64 %44, i64* %3
br label %45
45: ; preds = %41, %25
%46 = load i64, i64* %3
ret i64 %46
}

LLVM IR (-O2):
define i64 @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 = icmp eq i8 %6, 107
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 75
br i1 %14, label %15, label %26
15: ; preds = %8, %1
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, -1
%18 = zext i32 %17 to i64
%19 = tail call i8* @llvm.stacksave()
%20 = alloca i8, i64 %18
%21 = tail call i32 @strlen(i8* %0)
%22 = add nsw i32 %21, -1
%23 = call i32 @memcpy(i8* %20, i8* %0, i32 %22)
%24 = call i32 @atoi(i8* %20)
%25 = shl nsw i32 %24, 10
br label %28
26: ; preds = %8
%27 = tail call i32 @atoi(i8* %0)
br label %28
28: ; preds = %26, %15
%29 = phi i32 [ %25, %15 ], [ %27, %26 ]
%30 = sext i32 %29 to i64
ret i64 %30
}