#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;
typedef int uint32_t;

/* Variables and functions */
uint64_t ConvertFromBytes(uint32_t to_memory_unit, uint64_t original_value) {
  uint64_t converted_value = 0;
  if (to_memory_unit == 0)
    converted_value = original_value / ((uint64_t)1);
  else if (to_memory_unit == 1)
    converted_value = original_value / ((uint64_t)1024);
  else if (to_memory_unit == 2)
    converted_value = original_value / (((uint64_t)1024) * ((uint64_t)1024));
  else if (to_memory_unit == 3)
    converted_value = original_value /
                      (((uint64_t)1024) * ((uint64_t)1024) * ((uint64_t)1024));
  return converted_value;
}


x86 assembly (clang, -O0):
<ConvertFromBytes>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    112e <ConvertFromBytes+0x2e>
mov    -0x8(%rbp),%eax
mov    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    118f <ConvertFromBytes+0x8f>
cmpl   $0x1,-0x4(%rbp)
jne    114b <ConvertFromBytes+0x4b>
mov    -0x8(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    118a <ConvertFromBytes+0x8a>
cmpl   $0x2,-0x4(%rbp)
jne    1168 <ConvertFromBytes+0x68>
mov    -0x8(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1185 <ConvertFromBytes+0x85>
cmpl   $0x3,-0x4(%rbp)
jne    1180 <ConvertFromBytes+0x80>
mov    -0x8(%rbp),%eax
mov    $0x40000000,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1185 <ConvertFromBytes+0x85>
jmp    118a <ConvertFromBytes+0x8a>
jmp    118f <ConvertFromBytes+0x8f>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConvertFromBytes>:
cmp    $0x3,%edi
ja     112a <ConvertFromBytes+0x2a>
mov    %esi,%eax
mov    %edi,%ecx
lea    0xef0(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0xa,%ecx
mov    %ecx,%eax
ret
xor    %eax,%eax
ret
lea    0xfffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x14,%ecx
mov    %ecx,%eax
ret
lea    0x3fffffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x1e,%ecx
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @ConvertFromBytes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = sdiv i32 %9, 1
store i32 %10, i32* %5
br label %32
11: ; preds = %2
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = sdiv i32 %15, 1024
store i32 %16, i32* %5
br label %31
17: ; preds = %11
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %4
%22 = sdiv i32 %21, 1048576
store i32 %22, i32* %5
br label %30
23: ; preds = %17
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %4
%28 = sdiv i32 %27, 1073741824
store i32 %28, i32* %5
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %20
br label %31
31: ; preds = %30, %14
br label %32
32: ; preds = %31, %8
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @ConvertFromBytes(i32 %0, i32 %1) {
switch i32 %0, label %9 [
i32 0, label %10
i32 1, label %3
i32 2, label %5
i32 3, label %7
]
3: ; preds = %2
%4 = sdiv i32 %1, 1024
br label %10
5: ; preds = %2
%6 = sdiv i32 %1, 1048576
br label %10
7: ; preds = %2
%8 = sdiv i32 %1, 1073741824
br label %10
9: ; preds = %2
br label %10
10: ; preds = %2, %9, %3, %7, %5
%11 = phi i32 [ %4, %3 ], [ %6, %5 ], [ %8, %7 ], [ %1, %2 ], [ 0, %9 ]
ret i32 %11
}