// File: /workspace/github_c_makefile_star2_O1/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 0x2d17
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 0x3031
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %r14d, %r14d
js 0x2fba
movl %ebp, 0x4(%rsp)
movq %r14, 0x8(%rsp)
movq 0x140c8(%rax), %r12
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)
je 0x2e12
movq 0x8(%rsp), %r13
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leaq 0x140(%rsp), %rbp
xorl %r14d, %r14d
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x2da7
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x2db5
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movl (%rax), %r15d
movl %r15d, 0x30(%rsp,%r14,4)
movq %r12, (%rbp)
cmpb $0x72, (%rbx,%r14)
jne 0x2dd8
movl %r15d, %edi
callq 0x2b5a
testl %eax, %eax
jne 0x2fba
cmpb $0x77, (%rbx,%r14)
jne 0x2def
movl %r15d, %edi
callq 0x2bc0
testl %eax, %eax
jne 0x2fba
movzbl (%rbx,%r14), %eax
cmpl $0x72, %eax
je 0x2e02
cmpl $0x77, %eax
jne 0x2fcf
incq %r14
addq $0x18, %rbp
cmpq %r14, %r13
jne 0x2d8c
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x4(%rsp)
jne 0x2fba
movq 0x8(%rsp), %r14
testl %r14d, %r14d
je 0x2f08
cmpl $0x2, %r14d
movl $0x1, %r15d
cmovgel %r14d, %r15d
leaq 0x130(%rsp), %r12
xorl %r13d, %r13d
movl 0x30(%rsp,%r13,4), %ebp
movzbl (%rbx,%r13), %eax
cmpl $0x77, %eax
je 0x2ea6
cmpl $0x72, %eax
jne 0x2fcf
callq 0x3031
movslq %ebp, %rcx
imulq $0x66666667, %rcx, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x2c, %rcx
addl %edx, %ecx
shll $0xb, %ecx
leal (%rcx,%rcx,4), %ecx
movl %ebp, %edx
subl %ecx, %edx
movslq %edx, %rcx
movq 0x18(%rax,%rcx,8), %rax
testq %rax, %rax
je 0x2e9a
cmpl %ebp, 0x10(%rax)
je 0x2e9c
xorl %eax, %eax
leaq 0x20(%rax), %rcx
addq $0x28, %rax
jmp 0x2ee6
callq 0x3031
movslq %ebp, %rcx
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x2c, %rdx
addl %esi, %edx
shll $0xb, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %ecx
movslq %ecx, %rcx
movq 0x18(%rax,%rcx,8), %rax
testq %rax, %rax
je 0x2edc
cmpl %ebp, 0x10(%rax)
je 0x2ede
xorl %eax, %eax
leaq 0x38(%rax), %rcx
addq $0x40, %rax
movq (%rax), %rdx
movq %rdx, 0x8(%r12)
movq %r12, (%rdx)
movq %rcx, (%r12)
movq %r12, (%rax)
incq %r13
addq $0x18, %r12
cmpq %r13, %r15
jne 0x2e4a
callq 0x3031
movq 0x140c0(%rax), %rsi
movq 0x140c8(%rax), %rdi
addq $0x48, %rdi
addq $0x48, %rsi
callq 0x312c
testl %r14d, %r14d
je 0x2fb2
cmpl $0x2, %r14d
movq %r14, %rax
movl $0x1, %r14d
cmovgel %eax, %r14d
xorl %r12d, %r12d
leaq 0x130(%rsp), %r13
xorl %ebp, %ebp
cmpb $0x72, (%rbx,%r12)
jne 0x2f6d
movl 0x30(%rsp,%r12,4), %r15d
movl %r15d, %edi
callq 0x2b5a
testl %eax, %eax
je 0x2f6d
testl %ebp, %ebp
je 0x2fa1
jmp 0x2fd4
cmpb $0x77, (%rbx,%r12)
jne 0x2f8b
movl 0x30(%rsp,%r12,4), %r15d
movl %r15d, %edi
callq 0x2bc0
testl %eax, %eax
je 0x2f8b
testl %ebp, %ebp
je 0x2fa1
jmp 0x2ff3
movq (%r13), %rax
movq 0x8(%r13), %rcx
movq %rax, (%rcx)
movq (%r13), %rax
movq %rcx, 0x8(%rax)
movl %ebp, %r15d
incq %r12
addq $0x18, %r13
movl %r15d, %ebp
cmpq %r12, %r14
jne 0x2f4f
jmp 0x2fb5
xorl %r15d, %r15d
testl %r15d, %r15d
je 0x3012
movl %r15d, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x12b0
leaq 0x1109(%rip), %rdi      # 0x40e4
leaq 0x10da(%rip), %rsi      # 0x40bc
leaq 0x1102(%rip), %rcx      # 0x40eb
movl $0x366, %edx            # imm = 0x366
callq 0x1130
leaq 0x10ea(%rip), %rdi      # 0x40e4
leaq 0x10bb(%rip), %rsi      # 0x40bc
leaq 0x10e3(%rip), %rcx      # 0x40eb
movl $0x36a, %edx            # imm = 0x36A
callq 0x1130
leaq 0x10fd(%rip), %rdi      # 0x4116
leaq 0x109c(%rip), %rsi      # 0x40bc
leaq 0x10c4(%rip), %rcx      # 0x40eb
movl $0x371, %edx            # imm = 0x371
callq 0x1130