// File: 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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x58(%rsp), %rdi
movl $0x1, %esi
leaq 0x50(%rsp), %rdx
leaq 0xa58b1(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x5a0(%rax)
jne 0x297c3
movq 0x58(%rsp), %rdi
leaq 0xa784f(%rip), %rsi     # 0xd1002
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x64(%rsp)
jmp 0x29b99
jmp 0x297c5
movq 0x58(%rsp), %rdi
movl $0x2, %esi
leaq 0x40(%rsp), %rdx
leaq 0x4c(%rsp), %rcx
callq 0x19be0
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x4c(%rsp)
je 0x2987e
jmp 0x297f0
cmpq $0x0, 0x38(%rsp)
je 0x29816
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x30(%rsp)
je 0x2982d
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
cmpq $0x0, 0x28(%rsp)
je 0x29844
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
jmp 0x29846
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x18(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x64(%rsp)
jmp 0x29b99
movq 0x58(%rsp), %rdi
movl 0x40(%rsp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x18050
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x29927
jmp 0x298a5
cmpq $0x0, 0x38(%rsp)
je 0x298cb
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x30(%rsp)
je 0x298e2
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
cmpq $0x0, 0x28(%rsp)
je 0x298f9
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
jmp 0x298fb
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x19a60
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x64(%rsp)
jmp 0x29b99
movq 0x58(%rsp), %rdi
movl 0x40(%rsp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x18050
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x299d0
jmp 0x2994e
cmpq $0x0, 0x38(%rsp)
je 0x29974
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x30(%rsp)
je 0x2998b
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
cmpq $0x0, 0x28(%rsp)
je 0x299a2
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
jmp 0x299a4
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x19a60
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x64(%rsp)
jmp 0x29b99
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x5a0(%rax), %rax
movq 0x20(%rsp), %rdi
movl 0x40(%rsp), %esi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
callq *%rax
movl %eax, 0x48(%rsp)
cmpl $0x0, 0x48(%rsp)
je 0x29a9c
jmp 0x29a0b
cmpq $0x0, 0x38(%rsp)
je 0x29a31
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x30(%rsp)
je 0x29a48
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
cmpq $0x0, 0x28(%rsp)
je 0x29a5f
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
jmp 0x29a61
jmp 0x29a63
cmpl $0x0, 0x48(%rsp)
je 0x29a8d
movq 0x58(%rsp), %rdi
movl 0x48(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x58(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x64(%rsp)
jmp 0x29b99
jmp 0x29a8f
movl $0x0, 0x64(%rsp)
jmp 0x29b99
movq 0x58(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x58(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x40(%rsp), %eax
jae 0x29b39
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rax
movl 0x44(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
callq 0x18be0
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x191e0
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x44(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
callq 0x18be0
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x29ac0
jmp 0x29b3b
cmpq $0x0, 0x38(%rsp)
je 0x29b61
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x30(%rsp)
je 0x29b78
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
cmpq $0x0, 0x28(%rsp)
je 0x29b8f
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
jmp 0x29b91
movl $0x2, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)