// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl $0x11, %edi
callq 0xb690
leaq 0x186a(%rip), %rdi      # 0xd22d
movb $0x0, %al
callq 0x20e0
leaq 0x187b(%rip), %rdi      # 0xd24c
callq 0x2860
movq %rax, -0x10(%rbp)
leaq 0x1884(%rip), %rdi      # 0xd265
movb $0x0, %al
callq 0x20e0
movq -0x10(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq 0x188e(%rip), %rdx      # 0xd285
callq 0x2e10
movl $0x3e8, %eax            # imm = 0x3E8
cmpl -0x18(%rbp), %eax
setl %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x187a(%rip), %rsi      # 0xd28d
movl $0x65, %edx
callq 0xaf70
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xb7d0
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2490
movq -0x10(%rbp), %rax
movl 0x120(%rax), %esi
movl $0x9, %edi
leaq 0x1856(%rip), %rdx      # 0xd2bc
movl $0x6c, %ecx
callq 0xae20
movq -0x10(%rbp), %rax
movl 0x128(%rax), %esi
movl $0xc, %edi
leaq 0x1847(%rip), %rdx      # 0xd2cd
movl $0x6e, %ecx
callq 0xae20
movq -0x10(%rbp), %rdi
callq 0x45d0
movl %eax, -0x2c(%rbp)
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2110
movl $0x0, -0x54(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0xbb58
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x2, %esi
callq 0x22f0
movq -0x10(%rbp), %rdi
callq 0x45d0
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x58(%rbp), %eax
je 0xbaf0
movl -0x58(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0xbafa
movl $0x1, %edi
callq 0x22e0
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2110
movq -0x50(%rbp), %rax
subq -0x40(%rbp), %rax
cvtsi2sd %rax, %xmm1
movq -0x48(%rbp), %rax
subq -0x38(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1367(%rip), %xmm2     # 0xce90
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xa75(%rip), %xmm1      # 0xc5c0
ucomisd %xmm1, %xmm0
jbe 0xbb53
jmp 0xbb58
jmp 0xbab0
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2110
movq -0x50(%rbp), %rax
subq -0x40(%rbp), %rax
cvtsi2sd %rax, %xmm1
movq -0x48(%rbp), %rax
subq -0x38(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1309(%rip), %xmm2     # 0xce90
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x12ef(%rip), %xmm1     # 0xce98
mulsd %xmm1, %xmm0
leaq 0x172d(%rip), %rdi      # 0xd2e1
movb $0x1, %al
callq 0x20e0
movl -0x2c(%rbp), %esi
xorl %edi, %edi
leaq 0x1730(%rip), %rdx      # 0xd2f7
movl $0x8c, %ecx
callq 0xae20
movss -0x60(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x9de(%rip), %xmm0      # 0xc5c0
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x1716(%rip), %rsi      # 0xd30b
movl $0x8d, %edx
callq 0xaf70
movss 0x4589(%rip), %xmm1     # 0x10190
movss 0x1291(%rip), %xmm0     # 0xcea0
leaq 0x1707(%rip), %rdi      # 0xd31d
movl $0x8f, %esi
callq 0xb650
movl 0x456e(%rip), %esi      # 0x10194
xorl %edi, %edi
leaq 0x1707(%rip), %rdx      # 0xd336
movl $0x90, %ecx
callq 0xae20
movb 0x4559(%rip), %al       # 0x10198
andb $0x1, %al
movzbl %al, %edi
leaq 0x1706(%rip), %rsi      # 0xd351
movl $0x91, %edx
callq 0xb010
movq -0x10(%rbp), %rdi
callq 0x2ab0
leaq -0x28(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x80c0
callq 0xb6c0
addq $0x80, %rsp
popq %rbp
retq