// File: /workspace/github_cpp_makefile_star2_O2/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 0x58ba3(%rip), %rcx     # 0x7d03b
pushq $0x1
popq %rsi
leaq 0x18(%rsp), %r14
movq %r14, %rdx
callq 0x1a500
movq %rax, %r13
movq (%r14), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x5a0(%rax)
je 0x2451a
pushq $0x2
popq %rbp
leaq 0xc(%rsp), %rdx
leaq 0x24(%rsp), %r15
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rcx
callq 0x19ac0
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x24529
testq %r14, %r14
je 0x244fa
movl 0xc(%rsp), %ecx
pushq $0x18
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x197e0
pushq $-0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x18680
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x18420
jmp 0x2462b
leaq 0x5ab29(%rip), %rsi     # 0x7f04a
movq %rbx, %rdi
jmp 0x24624
movl 0xc(%rsp), %esi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x18050
testq %rax, %rax
je 0x245d3
movq %rax, %r15
movl 0xc(%rsp), %esi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x18050
testq %rax, %rax
je 0x245f0
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 0x2463e
movl %eax, %r13d
testq %r14, %r14
je 0x245a6
movl 0xc(%rsp), %ecx
pushq $0x18
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x197e0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x182e0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x182e0
movq %rbx, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199c0
jmp 0x2462b
testq %r14, %r14
je 0x24616
movl 0xc(%rsp), %ecx
pushq $0x18
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x197e0
jmp 0x24616
testq %r14, %r14
je 0x2460b
movl 0xc(%rsp), %ecx
pushq $0x18
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x197e0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x182e0
pushq $-0x6
popq %rdi
callq 0x19950
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x19bc0
movl %eax, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movl 0xc(%rsp), %ecx
cmpq %rcx, %r14
jae 0x246a4
movq (%r15,%r14,8), %rsi
movq %rbx, %rdi
callq 0x18b50
leaq 0x1(%r14), %r13
movq %rbx, %rdi
pushq $-0x3
popq %rsi
movq %r13, %rdx
callq 0x19120
movq (%r12,%r14,8), %rsi
movq %rbx, %rdi
callq 0x18b50
movq %rbx, %rdi
pushq $-0x2
popq %rsi
movq %r13, %rdx
callq 0x19120
movq %r13, %r14
jmp 0x2465e
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x246bd
pushq $0x18
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
callq 0x197e0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x182e0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x182e0
jmp 0x2462d