// File: /workspace/github_c_makefile_star2_O2/mruby-zest[P]osc-bridge/test/basic-remote.c
// Function: main
int main()
{
    test_plan(17);
    //Define that there is a bridge on localhost:1337
    printf("#Creating Bridge To Remote...\n");
    bridge_t *bridge = br_create("osc.udp://localhost:1337");

    //Get the bridge to obtain the schema
    printf("#Creating Schema For Remote...\n");
    schema_t schema = br_get_schema(bridge, "/schema");
    
    assert_true(1000 <  schema.elements,
            "Schema has around the right number of elements", __LINE__);

    test_lfo(schema, bridge);

    br_recv(bridge, 0);

    assert_int_eq(9, bridge->cache_len,
            "Check Cache Size", __LINE__);
    assert_int_eq(12, bridge->callback_len,
            "Check Callback Size", __LINE__);


    //print_stats(bridge, schema);
    

    int old_pending = br_pending(bridge);
    //printf("STARTING UV RUN...\n");
    struct timeval tv1;
    struct timeval tv2;
    gettimeofday(&tv1, 0);
    int tic = 0;
    while(old_pending) {
        uv_run(bridge->loop, UV_RUN_NOWAIT);
        int new_pending = br_pending(bridge);
        tic++;
        if(old_pending != new_pending)
            old_pending = new_pending;
        else
            usleep(1);
        gettimeofday(&tv2, 0);
        float delta = (tv2.tv_sec-tv1.tv_sec) + 1e-6*(tv2.tv_usec-tv1.tv_usec);
        if(delta > 0.100)
            break;
    }
    gettimeofday(&tv2, 0);
    float delta = (tv2.tv_sec-tv1.tv_sec) + 1e-6*(tv2.tv_usec-tv1.tv_usec);
    printf("#delta time is %f ms\n", delta*1e3);


    assert_int_eq(0, old_pending, "Cache is up-to-date", __LINE__);
    assert_true(delta < 0.100, "Check for timeout", __LINE__);

    assert_flt_eq(0x1.93264cp-2, Pfreq, "Default frequency is set", __LINE__);
    assert_int_eq(0, Pfreqrand, "Default randomness is zero", __LINE__);
    assert_false(Pcontinous, "Default LFO is not continious", __LINE__);

    br_destroy(bridge);
    br_destroy_schema(schema);

    return test_summary();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
pushq $0x11
popq %rdi
callq 0x78fe
leaq 0x1589(%rip), %rdi      # 0x90b0
callq 0x2080
leaq 0x1460(%rip), %rdi      # 0x8f93
callq 0x2767
movq %rax, %rbx
leaq 0x158c(%rip), %rdi      # 0x90ce
callq 0x2080
leaq 0x145e(%rip), %rdx      # 0x8fac
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2af5
xorl %edi, %edi
cmpl $0x3e9, 0x10(%r14)      # imm = 0x3E9
setge %dil
leaq 0x1442(%rip), %rsi      # 0x8fb4
pushq $0x65
popq %rdx
callq 0x73f8
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x79bb
movq %rbx, %rdi
xorl %esi, %esi
callq 0x246c
movl 0x120(%rbx), %esi
leaq 0x1439(%rip), %rdx      # 0x8fe3
pushq $0x9
popq %rdi
pushq $0x6c
popq %rcx
callq 0x7304
movl 0x128(%rbx), %esi
leaq 0x1432(%rip), %rdx      # 0x8ff4
pushq $0xc
popq %rdi
pushq $0x6e
popq %rcx
callq 0x7304
movq %rbx, %rdi
callq 0x3b2a
movl %eax, %r14d
leaq -0x68(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2120
movq (%r15), %r13
movq 0x8(%r15), %r15
testl %r14d, %r14d
je 0x7c5e
movq (%rbx), %rdi
pushq $0x2
popq %rsi
callq 0x2310
movq %rbx, %rdi
callq 0x3b2a
movl %eax, %r12d
cmpl %eax, %r14d
jne 0x7c18
pushq $0x1
popq %rdi
callq 0x2300
movl %r14d, %r12d
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x2120
movq -0x40(%rbp), %rax
subq %r13, %rax
cvtsi2sd %rax, %xmm0
movq -0x38(%rbp), %rax
subq %r15, %rax
cvtsi2sd %rax, %xmm1
mulsd 0xfd5(%rip), %xmm1      # 0x8c18
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x8d1(%rip), %xmm0      # 0x8528
movl %r12d, %r14d
jbe 0x7bed
jmp 0x7c61
xorl %r12d, %r12d
leaq -0x40(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2120
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %r13, %rax
cvtsi2sd %rax, %xmm0
subq %r15, %rcx
cvtsi2sd %rcx, %xmm1
mulsd 0xf8a(%rip), %xmm1      # 0x8c18
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0xf79(%rip), %xmm0      # 0x8c20
mulsd %xmm1, %xmm0
leaq 0x1356(%rip), %rdi      # 0x9008
movb $0x1, %al
callq 0x20f0
leaq 0x135e(%rip), %rdx      # 0x901e
xorl %edi, %edi
movl %r12d, %esi
movl $0x8c, %ecx
callq 0x7304
xorl %edi, %edi
movsd 0x84f(%rip), %xmm0      # 0x8528
ucomisd -0x30(%rbp), %xmm0
seta %dil
leaq 0x1349(%rip), %rsi      # 0x9032
movl $0x8d, %edx
callq 0x73f8
movss 0x44a5(%rip), %xmm1     # 0xc1a0
leaq 0x1342(%rip), %rdi      # 0x9044
movss 0xf1e(%rip), %xmm0      # 0x8c28
movl $0x8f, %esi
callq 0x78cf
movl 0x448a(%rip), %esi      # 0xc1a4
leaq 0x133c(%rip), %rdx      # 0x905d
xorl %edi, %edi
movl $0x90, %ecx
callq 0x7304
movzbl 0x4474(%rip), %edi      # 0xc1a8
leaq 0x133d(%rip), %rsi      # 0x9078
movl $0x91, %edx
callq 0x745a
movq %rbx, %rdi
callq 0x28fa
movq -0x48(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x58(%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x5d58
callq 0x7913
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq