// File: /workspace/github_c_makefile_star2_O2/whtc123[P]libuvc/uvc.c
// Function: channel_select
channel_t channel_select(int need_default,char *fmt,...){
	va_list argp;
	int cnt = strlen(fmt);
	queue_t select_node[HEAP_SELECT_CNT];
	channel_t channels[HEAP_SELECT_CNT];
	channel *chan=NULL;
	uvc_ctx *ctx=uvc_self();
	channel_t c;
	int i = 0;
	if (cnt < 0)return -1;
	
	va_start(argp, fmt);
	for (i = 0; i<cnt; i++)
	{
		c = va_arg(argp, channel_t);
		channels[i] = c;
		select_node[i].ext = ctx;
		if (fmt[i] == 'r' && channel_readable(c)){
			return c;
		}
		else if (fmt[i] == 'w' && channel_writeable(c)){
			return c;
		}
		else if (fmt[i] != 'w' && fmt[i] != 'r'){
			abort();
		}
	}
	va_end(argp);
	if (need_default){
		return -1;
	}
   
	for(i=0;i<cnt;i++)
	{
		c = channels[i];

	    if(fmt[i]=='r' ){
			chan = channel_pool_get(get_chan_pool(), c);
			queue_insert_head(&chan->readq, &select_node[i]);
	    }
	    else if(fmt[i]=='w'){
			chan = channel_pool_get(get_chan_pool(), c);
			queue_insert_head(&chan->writq, &select_node[i]);
		}else if(fmt[i] != 'w' && fmt[i] != 'r'){
			abort();
	    }
	}
	uvc_yield();
	c = 0;
	for (i = 0; i < cnt; i++)
	{
			
		if (fmt[i] == 'r' && channel_readable(channels[i])){
			assert(c == 0);
			c = channels[i];
		}
		else if (fmt[i] == 'w' && channel_writeable(channels[i])){
			assert(c == 0);
			c = channels[i];
		}
		else{
			queue_remove(&select_node[i]);
		}
	}
	assert(c != 0);
	//assert("won't be run here :\n");


    return c;    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %rsi, %rbx
movl %edi, %ebp
movq %rdx, 0x90(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0xa0(%rsp)
movq %r9, 0xa8(%rsp)
testb %al, %al
je 0x23e3
movaps %xmm0, 0xb0(%rsp)
movaps %xmm1, 0xc0(%rsp)
movaps %xmm2, 0xd0(%rsp)
movaps %xmm3, 0xe0(%rsp)
movaps %xmm4, 0xf0(%rsp)
movaps %xmm5, 0x100(%rsp)
movaps %xmm6, 0x110(%rsp)
movaps %xmm7, 0x120(%rsp)
movq %rsi, %rdi
callq 0x10e0
movq %rax, %r14
callq 0x2753
pushq $-0x1
popq %r12
testl %r14d, %r14d
js 0x25f8
movq %rax, %r15
movl %ebp, 0xc(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x350(%rsp), %rax
movq %rax, 0x18(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x10(%rsp)
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq 0x140(%rsp), %r13
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x24cc
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x2465
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x2473
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movl (%rax), %r12d
movl %r12d, 0x30(%rsp,%rbp,4)
movq %r15, (%r13)
movb (%rbx,%rbp), %al
cmpb $0x72, %al
jne 0x2499
movl %r12d, %edi
callq 0x2275
testl %eax, %eax
jne 0x25f8
movb (%rbx,%rbp), %al
cmpb $0x77, %al
jne 0x24b0
movl %r12d, %edi
callq 0x22bb
testl %eax, %eax
jne 0x25f8
movb (%rbx,%rbp), %al
cmpb $0x72, %al
je 0x24c0
movzbl %al, %eax
cmpl $0x77, %eax
jne 0x260d
incq %rbp
addq $0x18, %r13
jmp 0x2441
pushq $-0x1
popq %r12
cmpl $0x0, 0xc(%rsp)
jne 0x25f8
leaq 0x130(%rsp), %r15
xorl %r12d, %r12d
movl $0x2800, %r13d          # imm = 0x2800
cmpq %r12, %r14
je 0x257f
movl 0x30(%rsp,%r12,4), %ebp
movzbl (%rbx,%r12), %eax
cmpl $0x77, %eax
je 0x2539
cmpl $0x72, %eax
jne 0x260d
callq 0x266f
movq %rax, %rcx
movl %ebp, %eax
cltd
idivl %r13d
movslq %edx, %rax
movq 0x18(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x252d
cmpl %ebp, 0x10(%rax)
je 0x252f
xorl %eax, %eax
leaq 0x20(%rax), %rcx
addq $0x28, %rax
jmp 0x2563
callq 0x266f
movq %rax, %rcx
movl %ebp, %eax
cltd
idivl %r13d
movslq %edx, %rax
movq 0x18(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x2559
cmpl %ebp, 0x10(%rax)
je 0x255b
xorl %eax, %eax
leaq 0x38(%rax), %rcx
addq $0x40, %rax
movq (%rax), %rdx
movq %rdx, 0x8(%r15)
movq %r15, (%rdx)
movq %rcx, (%r15)
movq %r15, (%rax)
incq %r12
addq $0x18, %r15
jmp 0x24ec
callq 0x16a1
xorl %r15d, %r15d
leaq 0x138(%rsp), %r13
xorl %r12d, %r12d
cmpq %r15, %r14
je 0x25f3
movb (%rbx,%r15), %al
cmpb $0x72, %al
jne 0x25ba
movl 0x30(%rsp,%r15,4), %ebp
movl %ebp, %edi
callq 0x2275
testl %eax, %eax
je 0x25b6
testl %r12d, %r12d
je 0x25e7
jmp 0x2612
movb (%rbx,%r15), %al
cmpb $0x77, %al
jne 0x25d5
movl 0x30(%rsp,%r15,4), %ebp
movl %ebp, %edi
callq 0x22bb
testl %eax, %eax
je 0x25d5
testl %r12d, %r12d
je 0x25e7
jmp 0x2631
movq -0x8(%r13), %rax
movq (%r13), %rcx
movq %rax, (%rcx)
movq %rcx, 0x8(%rax)
movl %r12d, %ebp
incq %r15
addq $0x18, %r13
movl %ebp, %r12d
jmp 0x2592
testl %r12d, %r12d
je 0x2650
movl %r12d, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x12b0
leaq 0xacb(%rip), %rdi       # 0x30e4
leaq 0xa9c(%rip), %rsi       # 0x30bc
leaq 0xac4(%rip), %rcx       # 0x30eb
movl $0x366, %edx            # imm = 0x366
callq 0x1130
leaq 0xaac(%rip), %rdi       # 0x30e4
leaq 0xa7d(%rip), %rsi       # 0x30bc
leaq 0xaa5(%rip), %rcx       # 0x30eb
movl $0x36a, %edx            # imm = 0x36A
callq 0x1130
leaq 0xabf(%rip), %rdi       # 0x3116
leaq 0xa5e(%rip), %rsi       # 0x30bc
leaq 0xa86(%rip), %rcx       # 0x30eb
movl $0x371, %edx            # imm = 0x371
callq 0x1130