// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
leaq 0x1a16(%rip), %rdi      # 0x9dd3
movl $0x11, %esi
xorl %eax, %eax
callq 0x20f0
leaq 0x1d24(%rip), %rdi      # 0xa0f4
callq 0x2080
leaq 0x1bfb(%rip), %rdi      # 0x9fd7
callq 0x2807
movq %rax, %rbx
leaq 0x1d27(%rip), %rdi      # 0xa112
callq 0x2080
leaq 0x1bf9(%rip), %rdx      # 0x9ff0
leaq -0x60(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b90
xorl %edi, %edi
cmpl $0x3e9, 0x10(%r14)      # imm = 0x3E9
setge %dil
leaq 0x1bdd(%rip), %rsi      # 0x9ff8
movl $0x65, %edx
callq 0x7c8c
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x8255
movq %rbx, %rdi
xorl %esi, %esi
callq 0x24fe
movl 0x120(%rbx), %esi
leaq 0x1bd2(%rip), %rdx      # 0xa027
movl $0x9, %edi
movl $0x6c, %ecx
callq 0x7b98
movl 0x128(%rbx), %esi
leaq 0x1bc7(%rip), %rdx      # 0xa038
movl $0xc, %edi
movl $0x6e, %ecx
callq 0x7b98
movq %rbx, %rdi
callq 0x3c53
movl %eax, %r12d
leaq -0x70(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2120
movq (%r14), %r15
movq 0x8(%r14), %r13
testl %r12d, %r12d
je 0x851e
movq (%rbx), %rdi
movl $0x2, %esi
callq 0x2310
movq %rbx, %rdi
callq 0x3c53
movl %eax, %r14d
cmpl %eax, %r12d
jne 0x84cf
movl $0x1, %edi
callq 0x2300
movl %r12d, %r14d
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x2120
movq -0x40(%rbp), %rax
subq %r15, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq -0x38(%rbp), %rax
subq %r13, %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x1760(%rip), %xmm1     # 0x9c60
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x1079(%rip), %xmm0     # 0x9590
movl %r14d, %r12d
jbe 0x84a0
jmp 0x8521
xorl %r14d, %r14d
leaq -0x40(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x2120
movq (%r12), %rax
movq 0x8(%r12), %rcx
subq %r15, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq %r13, %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x170a(%rip), %xmm1     # 0x9c60
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0x16f3(%rip), %xmm0     # 0x9c68
mulsd %xmm1, %xmm0
leaq 0x1acc(%rip), %rdi      # 0xa04c
movb $0x1, %al
callq 0x20f0
leaq 0x1ad4(%rip), %rdx      # 0xa062
xorl %edi, %edi
movl %r14d, %esi
movl $0x8c, %ecx
callq 0x7b98
xorl %edi, %edi
movsd 0xfe9(%rip), %xmm0      # 0x9590
ucomisd -0x30(%rbp), %xmm0
seta %dil
leaq 0x1abf(%rip), %rsi      # 0xa076
movl $0x8d, %edx
callq 0x7c8c
movss 0x4bd7(%rip), %xmm0     # 0xd1a0
leaq -0x48(%rbp), %rdi
movl $0x3ec99326, (%rdi)     # imm = 0x3EC99326
leaq -0x44(%rbp), %rsi
movss %xmm0, (%rsi)
leaq 0x1aa6(%rip), %r8       # 0xa088
movl $0x4, %edx
movl $0x4, %ecx
movl $0x8f, %r9d
callq 0x8009
movl 0x4ba7(%rip), %esi      # 0xd1a4
leaq 0x1a9d(%rip), %rdx      # 0xa0a1
xorl %edi, %edi
movl $0x90, %ecx
callq 0x7b98
movzbl 0x4b91(%rip), %edi      # 0xd1a8
xorl $0x1, %edi
leaq 0x1a9b(%rip), %rsi      # 0xa0bc
movl $0x91, %edx
callq 0x7c8c
movq %rbx, %rdi
callq 0x299a
movq -0x50(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x60(%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x62cc
callq 0x81a9
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq