// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
testb %al, %al
je 0x3147
movaps %xmm0, -0x310(%rbp)
movaps %xmm1, -0x300(%rbp)
movaps %xmm2, -0x2f0(%rbp)
movaps %xmm3, -0x2e0(%rbp)
movaps %xmm4, -0x2d0(%rbp)
movaps %xmm5, -0x2c0(%rbp)
movaps %xmm6, -0x2b0(%rbp)
movaps %xmm7, -0x2a0(%rbp)
movq %r9, -0x318(%rbp)
movq %r8, -0x320(%rbp)
movq %rcx, -0x328(%rbp)
movq %rdx, -0x330(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10c0
movl %eax, -0x34(%rbp)
movq $0x0, -0x278(%rbp)
callq 0x3890
movq %rax, -0x280(%rbp)
movl $0x0, -0x288(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x31a9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3708
leaq -0x30(%rbp), %rax
leaq -0x340(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movl $0x0, -0x288(%rbp)
movl -0x288(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x332c
leaq -0x30(%rbp), %rax
movq %rax, -0x350(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x344(%rbp)
cmpl $0x28, %eax
ja 0x3221
movq -0x350(%rbp), %rcx
movl -0x344(%rbp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, -0x358(%rbp)
jmp 0x323e
movq -0x350(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, -0x358(%rbp)
movq -0x358(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x284(%rbp)
movl -0x284(%rbp), %ecx
movslq -0x288(%rbp), %rax
movl %ecx, -0x270(%rbp,%rax,4)
movq -0x280(%rbp), %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x72, %eax
jne 0x32b3
movl -0x284(%rbp), %edi
callq 0x2ef0
cmpl $0x0, %eax
je 0x32b3
movl -0x284(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3708
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
jne 0x32e5
movl -0x284(%rbp), %edi
callq 0x2f70
cmpl $0x0, %eax
je 0x32e5
movl -0x284(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3708
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
je 0x3312
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x72, %eax
je 0x3312
callq 0x1290
jmp 0x3314
jmp 0x3316
jmp 0x3318
movl -0x288(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x288(%rbp)
jmp 0x31d7
leaq -0x30(%rbp), %rax
cmpl $0x0, -0x8(%rbp)
je 0x3342
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3708
movl $0x0, -0x288(%rbp)
movl -0x288(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x3551
movslq -0x288(%rbp), %rax
movl -0x270(%rbp,%rax,4), %eax
movl %eax, -0x284(%rbp)
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x72, %eax
jne 0x343e
callq 0x38c0
movq %rax, %rdi
movl -0x284(%rbp), %esi
callq 0x2660
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movslq -0x288(%rbp), %rax
leaq -0x220(%rbp), %rcx
imulq $0x18, %rax, %rax
addq %rax, %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x278(%rbp), %rcx
addq $0x20, %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x288(%rbp), %rax
leaq -0x220(%rbp), %rcx
imulq $0x18, %rax, %rax
addq %rax, %rcx
movq -0x278(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x353b
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
jne 0x350a
callq 0x38c0
movq %rax, %rdi
movl -0x284(%rbp), %esi
callq 0x2660
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movslq -0x288(%rbp), %rax
leaq -0x220(%rbp), %rcx
imulq $0x18, %rax, %rax
addq %rax, %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x278(%rbp), %rcx
addq $0x38, %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x288(%rbp), %rax
leaq -0x220(%rbp), %rcx
imulq $0x18, %rax, %rax
addq %rax, %rcx
movq -0x278(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x3539
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
je 0x3537
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x72, %eax
je 0x3537
callq 0x1290
jmp 0x3539
jmp 0x353b
jmp 0x353d
movl -0x288(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x288(%rbp)
jmp 0x334c
callq 0x1880
movl $0x0, -0x284(%rbp)
movl $0x0, -0x288(%rbp)
movl -0x288(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x36d5
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x72, %eax
jne 0x35e8
movslq -0x288(%rbp), %rax
movl -0x270(%rbp,%rax,4), %edi
callq 0x2ef0
cmpl $0x0, %eax
je 0x35e8
cmpl $0x0, -0x284(%rbp)
jne 0x35b0
jmp 0x35cf
leaq 0xba1(%rip), %rdi       # 0x4158
leaq 0xb47(%rip), %rsi       # 0x4105
movl $0x366, %edx            # imm = 0x366
leaq 0xb95(%rip), %rcx       # 0x415f
callq 0x1110
movslq -0x288(%rbp), %rax
movl -0x270(%rbp,%rax,4), %eax
movl %eax, -0x284(%rbp)
jmp 0x36bf
movq -0x10(%rbp), %rax
movslq -0x288(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
jne 0x3654
movslq -0x288(%rbp), %rax
movl -0x270(%rbp,%rax,4), %edi
callq 0x2f70
cmpl $0x0, %eax
je 0x3654
cmpl $0x0, -0x284(%rbp)
jne 0x361f
jmp 0x363e
leaq 0xb32(%rip), %rdi       # 0x4158
leaq 0xad8(%rip), %rsi       # 0x4105
movl $0x36a, %edx            # imm = 0x36A
leaq 0xb26(%rip), %rcx       # 0x415f
callq 0x1110
movslq -0x288(%rbp), %rax
movl -0x270(%rbp,%rax,4), %eax
movl %eax, -0x284(%rbp)
jmp 0x36bd
movslq -0x288(%rbp), %rcx
leaq -0x220(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movslq -0x288(%rbp), %rcx
leaq -0x220(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movslq -0x288(%rbp), %rdx
leaq -0x220(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
jmp 0x36bf
jmp 0x36c1
movl -0x288(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x288(%rbp)
jmp 0x356a
cmpl $0x0, -0x284(%rbp)
je 0x36e0
jmp 0x36ff
leaq 0xaa3(%rip), %rdi       # 0x418a
leaq 0xa17(%rip), %rsi       # 0x4105
movl $0x371, %edx            # imm = 0x371
leaq 0xa65(%rip), %rcx       # 0x415f
callq 0x1110
movl -0x284(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
nopw %cs:(%rax,%rax)