// File: /workspace/github_cpp_makefile_star2_O3/stetre[P]moonvulkan/src/device.c
// Function: GetCalibratedTimestamps
static int GetCalibratedTimestamps(lua_State *L)
    {
    ud_t *ud;
    int err;
    VkResult ec;
    uint32_t i, count;
    VkCalibratedTimestampInfoEXT *infos = NULL;
    uint64_t* timestamps = NULL;
    uint64_t* maxdeviations = NULL;
    VkDevice device = checkdevice(L, 1, &ud);
    CheckDevicePfn(L, ud, GetCalibratedTimestampsEXT);

#define CLEANUP do {                                                        \
    if(infos) zfreearrayVkCalibratedTimestampInfoEXT(L, infos, count, 1);   \
    if(timestamps) Free(L, timestamps);                                     \
    if(maxdeviations) Free(L, maxdeviations);                               \
} while(0)
    infos = zcheckarrayVkCalibratedTimestampInfoEXT(L, 2, &count, &err);
    if(err) { CLEANUP; return argerror(L, 2); }
    timestamps = (uint64_t*)MallocNoErr(L, sizeof(uint64_t)*count);
    if(!timestamps) { CLEANUP; return errmemory(L); }
    maxdeviations = (uint64_t*)MallocNoErr(L, sizeof(uint64_t)*count);
    if(!maxdeviations) { CLEANUP; return errmemory(L); }

    ec = ud->ddt->GetCalibratedTimestampsEXT(device, count, infos, timestamps, maxdeviations);
    if(ec) { CLEANUP; CheckError(L, ec); return 0; }

    lua_newtable(L);
    lua_newtable(L);
    for(i=0; i<count; i++)
        {
        lua_pushinteger(L, timestamps[i]);
        lua_rawseti(L, -3, i+1);
        lua_pushinteger(L, maxdeviations[i]);
        lua_rawseti(L, -2, i+1);
        }
    CLEANUP;
#undef CLEANUP
    return 2;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x672eb(%rip), %rcx     # 0x8c03b
leaq 0x18(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a4e0
movq %rax, %r13
movq (%r14), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x5a0(%rax)
je 0x24ddc
leaq 0xc(%rsp), %rdx
leaq 0x24(%rsp), %r15
movq %rbx, %rdi
movl $0x2, %esi
movq %r15, %rcx
callq 0x19aa0
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x24deb
testq %r14, %r14
je 0x24db8
movl 0xc(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x18680
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0x18410
jmp 0x24ef9
leaq 0x69267(%rip), %rsi     # 0x8e04a
movq %rbx, %rdi
jmp 0x24ef2
movl 0xc(%rsp), %esi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x18050
testq %rax, %rax
je 0x24e97
movq %rax, %r15
movl 0xc(%rsp), %esi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x18050
testq %rax, %rax
je 0x24eb8
movq %rax, %r12
movq 0x18(%rsp), %rax
movq 0x50(%rax), %rax
movl 0xc(%rsp), %esi
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
callq *0x5a0(%rax)
testl %eax, %eax
je 0x24f08
movl %eax, %ebp
testq %r14, %r14
je 0x24e6b
movl 0xc(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x182d0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x182d0
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199a0
jmp 0x24ef9
testq %r14, %r14
je 0x24ee2
movl 0xc(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
callq 0x197d0
jmp 0x24ee2
testq %r14, %r14
je 0x24ed7
movl 0xc(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x182d0
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x19930
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x19ba0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
cmpl $0x0, 0xc(%rsp)
je 0x24f8b
movq %r14, 0x10(%rsp)
xorl %ebp, %ebp
movq %r15, %r14
movq %r12, %r15
movq (%r14,%rbp,8), %rsi
movq %rbx, %rdi
callq 0x18b50
leaq 0x1(%rbp), %r12
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
movq %r12, %rdx
callq 0x19130
movq (%r15,%rbp,8), %rsi
movq %rbx, %rdi
callq 0x18b50
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r12, %rdx
callq 0x19130
movl 0xc(%rsp), %r13d
movq %r12, %rbp
cmpq %r13, %r12
jb 0x24f37
movq %r15, %r12
movq %r14, %r15
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x24fa9
movl $0x18, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl %r13d, %ecx
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x182d0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x182d0
movl $0x2, %eax
jmp 0x24ef9