#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 */
long long *org_trifort_gc_get_to_space_address(char *);
long org_trifort_getlong(char *, int);
char *org_trifort_gc_deref(char *gc_info, int handle) {
  long long lhandle;
  long long *to_space;
  long space_size;
  long long array;
  long long offset;
  long long address;
  char *data_arr;
  lhandle = handle;
  lhandle = lhandle << 4;
  to_space = org_trifort_gc_get_to_space_address(gc_info);
  space_size = org_trifort_getlong(gc_info, 16);
  array = lhandle / space_size;
  offset = lhandle % space_size;
  address = to_space[array];
  data_arr = (char *)address;
  return &data_arr[offset];
}


x86 assembly (clang, -O0):
<org_trifort_gc_deref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <org_trifort_gc_get_to_space_address@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x10,%esi
call   1040 <org_trifort_getlong@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rdx,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<org_trifort_gc_deref>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movslq %esi,%rbx
shl    $0x4,%rbx
call   1030 <org_trifort_gc_get_to_space_address@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x10,%esi
call   1040 <org_trifort_getlong@plt>
mov    %rax,%rcx
or     %rbx,%rax
shr    $0x20,%rax
je     115a <org_trifort_gc_deref+0x3a>
mov    %rbx,%rax
cqto
idiv   %rcx
jmp    1160 <org_trifort_gc_deref+0x40>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
add    (%r14,%rax,8),%rdx
mov    %rdx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @org_trifort_gc_deref(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = shl i64 %14, 4
store i64 %15, i64* %5
%16 = load i8*, i8** %3
%17 = call i64* @org_trifort_gc_get_to_space_address(i8* %16)
store i64* %17, i64** %6
%18 = load i8*, i8** %3
%19 = call i64 @org_trifort_getlong(i8* %18, i32 16)
store i64 %19, i64* %7
%20 = load i64, i64* %5
%21 = load i64, i64* %7
%22 = sdiv i64 %20, %21
store i64 %22, i64* %8
%23 = load i64, i64* %5
%24 = load i64, i64* %7
%25 = srem i64 %23, %24
store i64 %25, i64* %9
%26 = load i64*, i64** %6
%27 = load i64, i64* %8
%28 = getelementptr inbounds i64, i64* %26, i64 %27
%29 = load i64, i64* %28
store i64 %29, i64* %10
%30 = load i64, i64* %10
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %11
%32 = load i8*, i8** %11
%33 = load i64, i64* %9
%34 = getelementptr inbounds i8, i8* %32, i64 %33
ret i8* %34
}

LLVM IR (-O2):
define i8* @org_trifort_gc_deref(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = shl nsw i64 %3, 4
%5 = tail call i64* @org_trifort_gc_get_to_space_address(i8* %0)
%6 = tail call i64 @org_trifort_getlong(i8* %0, i32 16)
%7 = sdiv i64 %4, %6
%8 = srem i64 %4, %6
%9 = getelementptr inbounds i64, i64* %5, i64 %7
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 %8
ret i8* %12
}