#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 getLocationOfCurrent();
int getRecordsStored();
int dataaddress(int index) {
  long memoryAddress = getLocationOfCurrent();
  long offset = index * 16;
  if (index >= getRecordsStored()) {
    return -1;
  }
  if (memoryAddress - offset >= 0x00100) {
    return (memoryAddress - offset);
  }
  memoryAddress = 0x10000 - (offset - (memoryAddress - 0x0100));
  return memoryAddress;
}


x86 assembly (clang, -O0):
<dataaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getLocationOfCurrent@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getRecordsStored@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jl     1168 <dataaddress+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <dataaddress+0x90>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
cmp    $0x100,%rax
jl     118c <dataaddress+0x6c>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11b0 <dataaddress+0x90>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    $0x100,%rax
sub    %rax,%rcx
mov    $0x10000,%eax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dataaddress>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <getLocationOfCurrent@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <getRecordsStored@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ebx,%ecx
jle    1163 <dataaddress+0x43>
shl    $0x4,%ebx
movslq %ebx,%rcx
mov    %r14,%rax
sub    %rcx,%rax
cmp    $0x100,%rax
jge    1163 <dataaddress+0x43>
sub    %ebx,%r14d
add    $0xff00,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @dataaddress(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %3
%6 = call i64 (...) @getLocationOfCurrent()
store i64 %6, i64* %4
%7 = load i32, i32* %3
%8 = mul nsw i32 %7, 16
%9 = sext i32 %8 to i64
store i64 %9, i64* %5
%10 = load i32, i32* %3
%11 = call i32 (...) @getRecordsStored()
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %32
14: ; preds = %1
%15 = load i64, i64* %4
%16 = load i64, i64* %5
%17 = sub nsw i64 %15, %16
%18 = icmp sge i64 %17, 256
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i64, i64* %4
%21 = load i64, i64* %5
%22 = sub nsw i64 %20, %21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %2
br label %32
24: ; preds = %14
%25 = load i64, i64* %5
%26 = load i64, i64* %4
%27 = sub nsw i64 %26, 256
%28 = sub nsw i64 %25, %27
%29 = sub nsw i64 65536, %28
store i64 %29, i64* %4
%30 = load i64, i64* %4
%31 = trunc i64 %30 to i32
store i32 %31, i32* %2
br label %32
32: ; preds = %24, %19, %13
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @dataaddress(i32 %0) {
%2 = tail call i64 (...) @getLocationOfCurrent()
%3 = shl nsw i32 %0, 4
%4 = tail call i32 (...) @getRecordsStored()
%5 = icmp sgt i32 %4, %0
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = sext i32 %3 to i64
%8 = sub nsw i64 %2, %7
%9 = icmp sgt i64 %8, 255
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = trunc i64 %8 to i32
br label %16
12: ; preds = %6
%13 = trunc i64 %2 to i32
%14 = sub i32 65280, %3
%15 = add i32 %14, %13
br label %16
16: ; preds = %1, %12, %10
%17 = phi i32 [ %11, %10 ], [ %15, %12 ], [ -1, %1 ]
ret i32 %17
}