// File: /workspace/github_c_makefile_star2_O3/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, %r15d
movq %rdx, 0x90(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0xa0(%rsp)
movq %r9, 0xa8(%rsp)
testb %al, %al
je 0x2ca0
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 0x2fcb
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %r14d, %r14d
js 0x2f35
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)
movq %r14, (%rsp)
je 0x2e86
movl %r15d, 0xc(%rsp)
movl %r14d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leaq 0x140(%rsp), %r15
xorl %r14d, %r14d
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x2d2d
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x2d3b
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movl (%rax), %ebp
movl %ebp, 0x30(%rsp,%r14,4)
movq %r12, (%r15)
movb (%rbx,%r14), %al
cmpb $0x72, %al
jne 0x2d60
movl %ebp, %edi
callq 0x2b00
testl %eax, %eax
jne 0x2f35
movb (%rbx,%r14), %al
cmpb $0x77, %al
jne 0x2d77
movl %ebp, %edi
callq 0x2b5a
testl %eax, %eax
jne 0x2f35
movb (%rbx,%r14), %al
cmpb $0x72, %al
je 0x2d87
movzbl %al, %eax
cmpl $0x77, %eax
jne 0x2f49
incq %r14
addq $0x18, %r15
cmpq %r14, %r13
jne 0x2d12
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x0, 0xc(%rsp)
jne 0x2f35
movq (%rsp), %r15
testl %r15d, %r15d
je 0x2f8c
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq 0x130(%rsp), %r12
xorl %r13d, %r13d
movl 0x30(%rsp,%r13,4), %ebp
movzbl (%rbx,%r13), %eax
cmpl $0x77, %eax
je 0x2e22
cmpl $0x72, %eax
jne 0x2f49
callq 0x2fcb
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 0x2e16
cmpl %ebp, 0x10(%rax)
je 0x2e18
xorl %eax, %eax
leaq 0x20(%rax), %rcx
addq $0x28, %rax
jmp 0x2e62
callq 0x2fcb
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 0x2e58
cmpl %ebp, 0x10(%rax)
je 0x2e5a
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 0x2dc6
jmp 0x2e8f
testl %r15d, %r15d
jne 0x2f35
callq 0x2fcb
movq 0x140c0(%rax), %rsi
movq 0x140c8(%rax), %rdi
addq $0x48, %rdi
addq $0x48, %rsi
callq 0x30b0
cmpl $0x0, (%rsp)
je 0x2fac
movq (%rsp), %r13
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
leaq 0x138(%rsp), %r12
xorl %ebp, %ebp
movb (%rbx,%r14), %al
cmpb $0x72, %al
jne 0x2ef7
movl 0x30(%rsp,%r14,4), %r15d
movl %r15d, %edi
callq 0x2b00
testl %eax, %eax
je 0x2ef3
testl %ebp, %ebp
movl %r15d, %ebp
je 0x2f25
jmp 0x2f4e
movb (%rbx,%r14), %al
cmpb $0x77, %al
jne 0x2f15
movl 0x30(%rsp,%r14,4), %r15d
movl %r15d, %edi
callq 0x2b5a
testl %eax, %eax
je 0x2f15
testl %ebp, %ebp
movl %r15d, %ebp
je 0x2f25
jmp 0x2f6d
movq -0x8(%r12), %rax
movq (%r12), %rcx
movq %rax, (%rcx)
movq %rcx, 0x8(%rax)
incq %r14
addq $0x18, %r12
cmpq %r14, %r13
jne 0x2ed1
testl %ebp, %ebp
je 0x2fac
movl %ebp, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x12b0
leaq 0x118f(%rip), %rdi      # 0x40e4
leaq 0x1160(%rip), %rsi      # 0x40bc
leaq 0x1188(%rip), %rcx      # 0x40eb
movl $0x366, %edx            # imm = 0x366
callq 0x1130
leaq 0x1170(%rip), %rdi      # 0x40e4
leaq 0x1141(%rip), %rsi      # 0x40bc
leaq 0x1169(%rip), %rcx      # 0x40eb
movl $0x36a, %edx            # imm = 0x36A
callq 0x1130
callq 0x2fcb
movq 0x140c0(%rax), %rsi
movq 0x140c8(%rax), %rdi
addq $0x48, %rdi
addq $0x48, %rsi
callq 0x30b0
leaq 0x1163(%rip), %rdi      # 0x4116
leaq 0x1102(%rip), %rsi      # 0x40bc
leaq 0x112a(%rip), %rcx      # 0x40eb
movl $0x371, %edx            # imm = 0x371
callq 0x1130