// File: /workspace/github_c_makefile_star2_O1/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 0x1920(%rip), %rdi      # 0x9dd3
movl $0x11, %esi
xorl %eax, %eax
callq 0x20f0
leaq 0x1c2e(%rip), %rdi      # 0xa0f4
callq 0x2080
leaq 0x1b05(%rip), %rdi      # 0x9fd7
callq 0x2804
movq %rax, %rbx
leaq 0x1c31(%rip), %rdi      # 0xa112
callq 0x2080
leaq 0x1b03(%rip), %rdx      # 0x9ff0
leaq -0x70(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b8a
xorl %edi, %edi
cmpl $0x3e9, 0x10(%r14)      # imm = 0x3E9
setge %dil
leaq 0x1ae7(%rip), %rsi      # 0x9ff8
movl $0x65, %edx
callq 0x7d48
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x834b
movq %rbx, %rdi
xorl %esi, %esi
callq 0x24fe
movl 0x120(%rbx), %esi
leaq 0x1adc(%rip), %rdx      # 0xa027
movl $0x9, %edi
movl $0x6c, %ecx
callq 0x7c54
movl 0x128(%rbx), %esi
leaq 0x1ad1(%rip), %rdx      # 0xa038
movl $0xc, %edi
movl $0x6e, %ecx
callq 0x7c54
movq %rbx, %rdi
callq 0x3c81
movl %eax, %r12d
leaq -0x58(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2120
movq (%r14), %r13
movq 0x8(%r14), %r15
testl %r12d, %r12d
je 0x8614
movq (%rbx), %rdi
movl $0x2, %esi
callq 0x2310
movq %rbx, %rdi
callq 0x3c81
movl %eax, %r14d
cmpl %eax, %r12d
jne 0x85c5
movl $0x1, %edi
callq 0x2300
movl %r12d, %r14d
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x2120
movq -0x40(%rbp), %rax
subq %r13, %rax
movq -0x38(%rbp), %rcx
subq %r15, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x166a(%rip), %xmm1     # 0x9c60
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0xf83(%rip), %xmm0      # 0x9590
movl %r14d, %r12d
jbe 0x8596
jmp 0x8617
xorl %r14d, %r14d
leaq -0x40(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2120
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq -0x58(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq -0x50(%rbp), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x1614(%rip), %xmm1     # 0x9c60
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0x15fd(%rip), %xmm0     # 0x9c68
mulsd %xmm1, %xmm0
leaq 0x19d6(%rip), %rdi      # 0xa04c
movb $0x1, %al
callq 0x20f0
leaq 0x19de(%rip), %rdx      # 0xa062
xorl %edi, %edi
movl %r14d, %esi
movl $0x8c, %ecx
callq 0x7c54
xorl %edi, %edi
movsd 0xef3(%rip), %xmm0      # 0x9590
ucomisd -0x30(%rbp), %xmm0
seta %dil
leaq 0x19c9(%rip), %rsi      # 0xa076
movl $0x8d, %edx
callq 0x7d48
movss 0x4ae1(%rip), %xmm0     # 0xd1a0
leaq -0x48(%rbp), %rdi
movl $0x3ec99326, (%rdi)     # imm = 0x3EC99326
leaq -0x44(%rbp), %rsi
movss %xmm0, (%rsi)
leaq 0x19b0(%rip), %r8       # 0xa088
movl $0x4, %edx
movl $0x4, %ecx
movl $0x8f, %r9d
callq 0x8103
movl 0x4ab1(%rip), %esi      # 0xd1a4
leaq 0x19a7(%rip), %rdx      # 0xa0a1
xorl %edi, %edi
movl $0x90, %ecx
callq 0x7c54
movzbl 0x4a9b(%rip), %edi      # 0xd1a8
xorl $0x1, %edi
leaq 0x19a5(%rip), %rsi      # 0xa0bc
movl $0x91, %edx
callq 0x7d48
movq %rbx, %rdi
callq 0x2994
movq -0x60(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x70(%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x6384
callq 0x829f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq