// File: hey-yahei[P]ConvNet/src/Concat.cpp
// Function: Concat::Run(float*, ...)
float* Concat::Run(float* in_data, ...) {
	va_list ap;
	
	int offset = 0;
	int *ishape;
	int input_size;
	int idx_input = 0;
	int cnt = 0;

	out_data = (float*)malloc(sizeof(float) * out_shape[0] * out_chw);

	va_start(ap, in_data);
	while (cnt++ < in_shape.size()) {
		for (int idx_bs = 0; idx_bs < out_shape[0]; idx_bs++) {
			ishape = in_shape[idx_input];
			input_size = ishape[1] * ishape[2] * ishape[3];
			memcpy(out_data + idx_bs * out_chw + offset, in_data, sizeof(float) * input_size);
			offset += input_size;

			if (!keep_in[idx_input])
				free(in_data);
		}
		idx_input++;

		// Next input
		in_data = va_arg(ap, float*);
	}
	va_end(ap);

	if (idx_input != in_shape.size()) {
		cerr << "Concat: run failed" << endl;
		exit(1);
	}

	return out_data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
testb %al, %al
je 0x3ba1
movaps %xmm0, -0xe0(%rbp)
movaps %xmm1, -0xd0(%rbp)
movaps %xmm2, -0xc0(%rbp)
movaps %xmm3, -0xb0(%rbp)
movaps %xmm4, -0xa0(%rbp)
movaps %xmm5, -0x90(%rbp)
movaps %xmm6, -0x80(%rbp)
movaps %xmm7, -0x70(%rbp)
movq %r9, -0xe8(%rbp)
movq %r8, -0xf0(%rbp)
movq %rcx, -0xf8(%rbp)
movq %rdx, -0x100(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x118(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movslq 0x18(%rax), %rdi
shlq $0x2, %rdi
movslq 0x50(%rax), %rax
imulq %rax, %rdi
callq 0x22e0
movq %rax, %rcx
movq -0x118(%rbp), %rax
movq %rcx, 0x58(%rax)
leaq -0x30(%rbp), %rax
leaq -0x110(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x118(%rbp), %rdi
movl -0x4c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x4c(%rbp)
cltq
movq %rax, -0x120(%rbp)
callq 0x4030
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x3da4
movl $0x0, -0x50(%rbp)
movq -0x118(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x3d30
movq -0x118(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0x4050
movq -0x118(%rbp), %rcx
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x40(%rbp), %rdx
imull 0x8(%rdx), %eax
movq -0x40(%rbp), %rdx
imull 0xc(%rdx), %eax
movl %eax, -0x44(%rbp)
movq 0x58(%rcx), %rdi
movl -0x50(%rbp), %eax
imull 0x50(%rcx), %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movslq -0x34(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x44(%rbp), %rdx
shlq $0x2, %rdx
callq 0x2180
movq -0x118(%rbp), %rdi
movl -0x44(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
addq $0x28, %rdi
movslq -0x48(%rbp), %rsi
callq 0x4070
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x40d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x3d17
jmp 0x3d20
movq -0x10(%rbp), %rdi
callq 0x2280
jmp 0x3d22
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x3c66
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0x130(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x124(%rbp)
cmpl $0x28, %eax
ja 0x3d74
movq -0x130(%rbp), %rcx
movl -0x124(%rbp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, -0x138(%rbp)
jmp 0x3d91
movq -0x130(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x3c2c
movq -0x118(%rbp), %rdi
leaq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rax
movq %rax, -0x140(%rbp)
callq 0x4030
movq %rax, %rcx
movq -0x140(%rbp), %rax
cmpq %rcx, %rax
je 0x3dfa
movq 0xe21b(%rip), %rdi      # 0x11ff0
leaq 0x84d7(%rip), %rsi      # 0xc2b3
callq 0x21c0
movq %rax, %rdi
movq 0xe1d5(%rip), %rsi      # 0x11fc0
callq 0x2200
movl $0x1, %edi
callq 0x2290
movq -0x118(%rbp), %rax
movq 0x58(%rax), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nop