// File: /workspace/github_cpp_makefile_star2_O1/lns[P]team-tactic-topic-model/main.cpp
// Function: main
int main(int argc, char* argv[])
{
	if(argc<20) {
		printf(" Usage: %s\n",argv[0]);
		printf("    input_file_name\n");
		printf("    out_topics_file_name\n");
		printf("    out_position_file_name\n");
		printf("    out_assign_file_name\n");
		printf("    out_theta_file_name\n");
		printf("    use_pos\n");
		printf("    n_word\n");
		printf("    K\n");
		printf("    alpha\n");
		printf("    beta\n");
		printf("    mu0_x\n");
		printf("    mu0_y\n");
		printf("    kappa0\n");
		printf("    Lambda0_xx\n");
		printf("    Lambda0_xy\n");
		printf("    Lambda0_yy\n");
		printf("    nu0\n");
		printf("    n_iter\n");
		printf("    seed\n");
		printf("  (See main.cpp for details)\n");
		return 0;
	}
	// argv[1] is input, argv[2] is out_topics,
	// argv[3] is out_pos, argv[4] is out_assign,
	// argv[5] is out_theta,
	uint32_t _ = 6; 
	uint32_t use_pos =  strtol(argv[_++],NULL,10);
	uint32_t n_word =   strtol(argv[_++],NULL,10);
	uint32_t K =        strtol(argv[_++],NULL,10);
	double alpha =      strtod(argv[_++],NULL);
	double beta =       strtod(argv[_++],NULL);
	double mu0_x =      strtod(argv[_++],NULL);
	double mu0_y =      strtod(argv[_++],NULL);
	double kappa0 =     strtod(argv[_++],NULL);
	double Lambda0_xx = strtod(argv[_++],NULL);
	double Lambda0_xy = strtod(argv[_++],NULL);
	double Lambda0_yy = strtod(argv[_++],NULL);
	double nu0 =        strtod(argv[_++],NULL);
	uint32_t n_iter =   strtol(argv[_++],NULL,10);
	uint64_t seed =     strtol(argv[_++],NULL,10);

	lcg64(seed);
	LDA<uint32_t,uint32_t,uint8_t> lda;
	// Order matters: 1. Read data. 2. set K. 3. config prior
	//lda.read_lda_c("../hdp/ap/ap.dat");
	lda.read_data(argv[1]);
	lda.n_word = n_word;
	printf("Read file done: %u doc, %u word\n",lda.dat.size(),lda.n_word);
	lda.set_K(K);
	printf("Set K = %u\n",lda.topic.size());
	// alpha, beta, mu0_x, mu0_y, kappa0, Lambda0_xx, Lambda0_xy, Lambda0_yy, nu0
	lda.config({alpha,beta,mu0_x,mu0_y,kappa0,Lambda0_xx,Lambda0_xy,Lambda0_yy,nu0},65536*8);
	lda.use_position = use_pos>0?true:false;

	//lda.print();
	lda.init();
	for(uint32_t i=0;i<n_iter;i++) {
		lda.gibbs();
		if((i+1)%10==0) {
			printf("iter: %u\n",i+1);
			fflush(stdout);
		}
	}
	FILE* f_topic = fopen(argv[2],"w");
	lda.output_topics(f_topic);
	fclose(f_topic);
	FILE* f_pos = fopen(argv[3],"w");
	lda.output_positions(f_pos);
	fclose(f_pos);
	FILE* f_assign = fopen(argv[4],"w");
	lda.output_assignments(f_assign);
	fclose(f_assign);
	FILE* f_theta = fopen(argv[5],"w");
	lda.output_theta(f_theta);
	fclose(f_theta);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %rbx
cmpl $0x13, %edi
jg 0x154f
movq (%rbx), %rsi
leaq 0x2c25(%rip), %rdi      # 0x4078
xorl %eax, %eax
callq 0x1040
leaq 0x2ccd(%rip), %rdi      # 0x412e
callq 0x1160
leaq 0x2cd5(%rip), %rdi      # 0x4142
callq 0x1160
leaq 0x2ce2(%rip), %rdi      # 0x415b
callq 0x1160
leaq 0x2cf1(%rip), %rdi      # 0x4176
callq 0x1160
leaq 0x2cfe(%rip), %rdi      # 0x418f
callq 0x1160
leaq 0x2d0a(%rip), %rdi      # 0x41a7
callq 0x1160
leaq 0x2d0a(%rip), %rdi      # 0x41b3
callq 0x1160
leaq 0x2d09(%rip), %rdi      # 0x41be
callq 0x1160
leaq 0x2d03(%rip), %rdi      # 0x41c4
callq 0x1160
leaq 0x2d01(%rip), %rdi      # 0x41ce
callq 0x1160
leaq 0x2cfe(%rip), %rdi      # 0x41d7
callq 0x1160
leaq 0x2cfc(%rip), %rdi      # 0x41e1
callq 0x1160
leaq 0x2cfa(%rip), %rdi      # 0x41eb
callq 0x1160
leaq 0x2cf9(%rip), %rdi      # 0x41f6
callq 0x1160
leaq 0x2cfc(%rip), %rdi      # 0x4205
callq 0x1160
leaq 0x2cff(%rip), %rdi      # 0x4214
callq 0x1160
leaq 0x2d02(%rip), %rdi      # 0x4223
callq 0x1160
leaq 0x2cfe(%rip), %rdi      # 0x422b
callq 0x1160
leaq 0x2cfd(%rip), %rdi      # 0x4236
callq 0x1160
leaq 0x2cfa(%rip), %rdi      # 0x423f
callq 0x1160
jmp 0x1960
movq 0x30(%rbx), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
movl $0xa, %edx
callq 0x1140
movq %rax, %r14
movq 0x38(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1140
movq %rax, %r12
movq 0x40(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1140
movq %rax, %r13
movq 0x48(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x48(%rsp)
movq 0x50(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x40(%rsp)
movq 0x58(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x38(%rsp)
movq 0x60(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x30(%rsp)
movq 0x68(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x28(%rsp)
movq 0x70(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x20(%rsp)
movq 0x78(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x18(%rsp)
movq 0x80(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x10(%rsp)
movq 0x88(%rbx), %rdi
xorl %esi, %esi
callq 0x10a0
movsd %xmm0, 0x8(%rsp)
movq 0x90(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1140
movq %rax, %r15
movq 0x98(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1140
movq %rax, 0x5aa7(%rip)      # 0x7100
leaq 0x50(%rsp), %rdi
movq %rbp, 0xf8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0xe8(%rdi)
movl %ebp, 0x8(%rdi)
movl %ebp, 0x4(%rdi)
movups %xmm0, 0x58(%rdi)
movups %xmm0, 0x68(%rdi)
movups %xmm0, 0x78(%rdi)
movups %xmm0, 0x88(%rdi)
movups %xmm0, 0x94(%rdi)
movups %xmm0, 0xa8(%rdi)
movups %xmm0, 0xb4(%rdi)
movups %xmm0, 0xc8(%rdi)
movups %xmm0, 0xd4(%rdi)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movups %xmm0, 0x20(%rdi)
movq %rax, 0x30(%rdi)
movq %rax, 0x38(%rdi)
movq %rbp, 0x40(%rdi)
movq %rax, 0x48(%rdi)
movq %rax, 0x50(%rdi)
movq %rbx, (%rsp)
movq 0x8(%rbx), %rsi
callq 0x198e
leaq 0x50(%rsp), %rbp
movl %r12d, 0x4(%rbp)
movq 0x60(%rbp), %rax
subq 0x58(%rbp), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
leaq 0x2978(%rip), %rdi      # 0x4084
movl %r12d, %edx
xorl %eax, %eax
callq 0x1040
movzbl %r13b, %esi
movq %rbp, %rdi
callq 0x1b5a
leaq 0x50(%rsp), %r12
movq 0x78(%r12), %rsi
subq 0x70(%r12), %rsi
sarq $0x6, %rsi
leaq 0x2969(%rip), %rdi      # 0x40a5
xorl %eax, %eax
callq 0x1040
leaq 0x150(%rsp), %rsi
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rsi)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x8(%rsi)
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x10(%rsi)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x18(%rsi)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x20(%rsi)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x28(%rsi)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x30(%rsi)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x38(%rsi)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%rsi)
movq %r12, %rdi
movl $0x80000, %edx          # imm = 0x80000
callq 0x1c7e
testl %r14d, %r14d
leaq 0x50(%rsp), %rdi
setne (%rdi)
movl $0x1, %esi
callq 0x1cf2
testl %r15d, %r15d
je 0x1846
negl %r15d
movl $0x1, %r12d
movl $0xcccccccd, %ebp       # imm = 0xCCCCCCCD
leaq 0x50(%rsp), %r14
leaq 0x28c3(%rip), %r13      # 0x40b1
movq 0x57d3(%rip), %rbx      # 0x6fc8
movq %r14, %rdi
xorl %esi, %esi
callq 0x1cf2
movl %r12d, %eax
imulq %rbp, %rax
shrq $0x23, %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
movl $0x1, %ecx
subl %eax, %ecx
addl %r12d, %ecx
cmpl $0x1, %ecx
jne 0x1833
movq %r13, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x1040
movq (%rbx), %rdi
callq 0x1100
leal (%r15,%r12), %eax
incl %eax
movl %r12d, %ecx
incl %ecx
movl %ecx, %r12d
cmpl $0x1, %eax
jne 0x17f5
movq (%rsp), %rbx
movq 0x10(%rbx), %rdi
leaq 0x2866(%rip), %r15      # 0x40bb
movq %r15, %rsi
callq 0x1110
movq %rax, %r12
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x1e84
movq %r12, %rdi
callq 0x10d0
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x1110
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
callq 0x1f3a
movq %r12, %rdi
callq 0x10d0
movq 0x20(%rbx), %rdi
movq %r15, %rsi
callq 0x1110
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
callq 0x2058
movq %r12, %rdi
callq 0x10d0
movq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0x1110
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x214a
movq %rbx, %rdi
callq 0x10d0
movq 0xf8(%r14), %rdi
testq %rdi, %rdi
je 0x18fb
callq 0x1130
movq $0x0, 0x148(%rsp)
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x1919
callq 0x1130
movq $0x0, 0x128(%rsp)
leaq 0xa8(%rsp), %rbx
leaq 0xc0(%rsp), %r14
movq 0x48(%r14), %rdi
testq %rdi, %rdi
je 0x1943
callq 0x1130
movq $0x0, 0x108(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x229e
movq %r14, %rdi
callq 0x22ec
movq %rbx, %rdi
callq 0x232e
xorl %eax, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1978
jmp 0x1978
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2224
movq %rbx, %rdi
callq 0x1180
nop