// File: /workspace/github_c_makefile_star2_O3/yhg926[P]public_kssd/command_set.c
// Function: combin_pans
int combin_pans()
{
  const char *pan_dstat_fpath = test_get_fullpath(set_opt.remaining_args[0], co_dstat);
 FILE * co_stat_fp = fopen(pan_dstat_fpath,"rb") ;
  if( co_stat_fp == NULL ) err(errno,"combin_pans():%s", pan_dstat_fpath);
 co_dstat_t co_dstat_one, co_dstat_it;
  fread(&co_dstat_one, sizeof(co_dstat_t), 1, co_stat_fp);
 fclose(co_stat_fp) ;
 ctx_obj_ct_t *ctx_ct = calloc( set_opt.num_remaining_args , sizeof(ctx_obj_ct_t) );
 llong all_ctx_ct = 0;
 char tmppath[PATHLEN];
 FILE** com_cofp = malloc( sizeof(FILE*) * co_dstat_one.comp_num);
 FILE** indexfp = malloc( sizeof(FILE*) * co_dstat_one.comp_num);
 size_t *index_offset = calloc(co_dstat_one.comp_num,sizeof(size_t));
 mkdir(set_opt.outdir,0777);
 for(int c = 0; c < co_dstat_one.comp_num; c++){
      sprintf(tmppath,"%s/%s.%d",set_opt.outdir,skch_prefix,c);
      com_cofp[c] = fopen(tmppath,"wb");
      if(com_cofp[c] == NULL) err(errno,"%s",tmppath);
   sprintf(tmppath,"%s/%s.%d",set_opt.outdir,idx_prefix,c);
      indexfp[c] = fopen(tmppath,"wb");
      if(indexfp[c] == NULL) err(errno,"%s",tmppath);
   fwrite(index_offset+c, sizeof(size_t),1,indexfp[c]);
  }
 struct stat file_stat;
 for(int i=0; i<set_opt.num_remaining_args;i++){
  pan_dstat_fpath = test_get_fullpath(set_opt.remaining_args[i], co_dstat);
  if( ( co_stat_fp = fopen(pan_dstat_fpath,"rb")) == NULL ) err(errno,"combin_pans():%s", pan_dstat_fpath);
  fread(&co_dstat_it, sizeof(co_dstat_t), 1, co_stat_fp);
  fclose(co_stat_fp) ;
  if( co_dstat_one.shuf_id != co_dstat_it.shuf_id )
   err(errno,"combin_pans(): %dth shuf_id: %u not match 0th shuf_id: %u\n",i, co_dstat_it.shuf_id, co_dstat_one.shuf_id);
  else if (co_dstat_one.comp_num != co_dstat_it.comp_num )
   err(errno,"combin_pans(): %dth comp_num: %u not match 0th comp_num: %u\n",i, co_dstat_it.comp_num, co_dstat_one.comp_num);
  for(int c = 0; c < co_dstat_one.comp_num; c++){
   sprintf(tmppath,"%s/%s.%d",set_opt.remaining_args[i],pan_prefix,c);
   if(stat(tmppath, &file_stat) == -1) {
    sprintf(tmppath,"%s/%s.%d",set_opt.remaining_args[i],uniq_pan_prefix,c);
    if(stat(tmppath, &file_stat) == -1)
     err(errno,"%s",tmppath);
   }
   unsigned int *tmpco = malloc(file_stat.st_size);
   FILE *pan_fp = fopen(tmppath,"rb");
   fread(tmpco,file_stat.st_size, 1, pan_fp);
   fwrite(tmpco,file_stat.st_size, 1, com_cofp[c]);
   fclose(pan_fp);
   index_offset[c] += file_stat.st_size/ sizeof(unsigned int);
   fwrite(index_offset+c, sizeof(size_t),1,indexfp[c]);
   ctx_ct[i] += file_stat.st_size/ sizeof(unsigned int);
  }
  all_ctx_ct+= ctx_ct[i];
 }
 for(int c = 0; c < co_dstat_one.comp_num; c++) {
  fclose(com_cofp[c]) ;
  fclose(indexfp[c]);
 }
 free(com_cofp);
 free(indexfp);
 free(index_offset);
 co_dstat_one.infile_num = set_opt.num_remaining_args;
 co_dstat_one.all_ctx_ct = all_ctx_ct ;
 sprintf(tmppath,"%s/%s",set_opt.outdir,co_dstat);
 if( (co_stat_fp = fopen(tmppath,"wb") ) == NULL) { err(errno,"%s",tmppath) ;} ;
 fwrite(&co_dstat_one,sizeof(co_dstat_t),1,co_stat_fp);
 fwrite(ctx_ct,sizeof(ctx_obj_ct_t), set_opt.num_remaining_args, co_stat_fp);
 for(int i=0; i<set_opt.num_remaining_args;i++)
   fwrite(set_opt.remaining_args[i],1, PATHLEN,co_stat_fp);
 fclose(co_stat_fp) ;
 free(ctx_ct);
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq 0xda24(%rip), %rax      # 0x1d680
movq (%rax), %rdi
leaq 0x5b4a(%rip), %rsi      # 0x157b0
callq 0x6d79
movq %rax, %rbx
leaq 0x53f2(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x1017f
movq %rax, %r14
leaq 0x40(%rsp), %r15
movl $0x20, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
movslq 0xd9ca(%rip), %rdi      # 0x1d67c
movl $0x4, %esi
callq 0x32a0
movq %rax, 0x8(%rsp)
movslq 0x10(%r15), %r14
leaq (,%r14,8), %r15
movq %r15, %rdi
callq 0x3340
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x3340
movq %rax, 0x28(%rsp)
movl $0x8, %esi
movq %r14, %rdi
callq 0x32a0
movq %rax, 0x20(%rsp)
leaq 0xdc88(%rip), %rdi      # 0x1d988
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl %r14d, %eax
movq %rax, 0x18(%rsp)
testq %r14, %r14
jle 0xfdec
leaq 0x533c(%rip), %r15      # 0x1505e
leaq 0xdc5f(%rip), %rbp      # 0x1d988
leaq 0x80(%rsp), %r13
movq 0x20(%rsp), %r12
xorl %r14d, %r14d
movq %r13, %rdi
movq %r15, %rbx
movq %r15, %rsi
movq %rbp, %rdx
leaq 0x7280(%rip), %rcx      # 0x16fcc
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
movq %r13, %r15
leaq 0x5307(%rip), %rsi      # 0x1506a
callq 0x33a0
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
je 0x10118
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rbx
movq %rbp, %rdx
leaq 0x7246(%rip), %rcx      # 0x16fd3
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %r13
movq %r15, %rdi
leaq 0x52c6(%rip), %rsi      # 0x1506a
callq 0x33a0
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
je 0x10118
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0x3450
incq %r14
addq $0x8, %r12
cmpq %r14, 0x18(%rsp)
leaq 0x527b(%rip), %r15      # 0x1505e
movq %rbx, %rbp
jne 0xfd39
movl 0xd88a(%rip), %ebx      # 0x1d67c
testl %ebx, %ebx
jle 0xffe8
movl 0x40(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0x80(%rsp), %r14
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r13, 0x30(%rsp)
movq 0xd864(%rip), %rax      # 0x1d680
movq (%rax,%r12,8), %rdi
leaq 0x5989(%rip), %rsi      # 0x157b0
callq 0x6d79
movq %rax, %r15
movq %rax, %rdi
leaq 0x522e(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x1016c
movq %rax, %r13
movl $0x20, %esi
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
movq %rax, %rcx
callq 0x30c0
movq %r13, %rdi
callq 0x3100
movl 0x60(%rsp), %ebp
cmpl %ebp, 0x4(%rsp)
jne 0x1014d
movl 0x70(%rsp), %ebp
movq 0x18(%rsp), %rbx
cmpl %ebp, %ebx
jne 0x10135
testl %ebx, %ebx
jle 0xffbf
movq 0x20(%rsp), %rbp
xorl %r13d, %r13d
movq %r12, 0x38(%rsp)
movq 0xd7dc(%rip), %rax      # 0x1d680
movq (%rax,%r12,8), %rdx
movq %r14, %rdi
leaq 0x51ac(%rip), %rsi      # 0x1505e
leaq 0x7127(%rip), %rcx      # 0x16fe0
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x188(%rsp), %rsi
callq 0x32e0
cmpl $-0x1, %eax
jne 0xff17
movq 0xd7a1(%rip), %rax      # 0x1d680
movq (%rax,%r12,8), %rdx
movq %r14, %rdi
leaq 0x5171(%rip), %rsi      # 0x1505e
leaq 0x70f0(%rip), %rcx      # 0x16fe4
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x188(%rsp), %rsi
callq 0x32e0
cmpl $-0x1, %eax
je 0x10118
movq 0x1b8(%rsp), %r15
movq %r15, %rdi
callq 0x3340
movq %rax, %rbx
movq %r14, %rdi
leaq 0x5133(%rip), %rsi      # 0x15067
callq 0x33a0
movq %r14, %r12
movq %rax, %r14
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rcx
callq 0x30c0
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3450
movq %r14, %rdi
movq %r12, %r14
movq 0x38(%rsp), %r12
callq 0x3100
shrq $0x2, %r15
addq %r15, (%rbp)
movq 0x28(%rsp), %rax
movq (%rax,%r13,8), %rcx
movl $0x8, %esi
movl $0x1, %edx
movq %rbp, %rdi
callq 0x3450
movq 0x8(%rsp), %rax
addl (%rax,%r12,4), %r15d
movl %r15d, (%rax,%r12,4)
incq %r13
addq $0x8, %rbp
cmpq %r13, 0x18(%rsp)
jne 0xfe9d
jmp 0xffc8
movq 0x8(%rsp), %rax
movl (%rax,%r12,4), %r15d
movl %r15d, %eax
movq 0x30(%rsp), %r13
addq %rax, %r13
incq %r12
movslq 0xd69f(%rip), %rbx      # 0x1d67c
cmpq %rbx, %r12
jl 0xfe10
jmp 0xffeb
xorl %r13d, %r13d
movq 0x18(%rsp), %r12
testl %r12d, %r12d
movq 0x28(%rsp), %r15
jle 0x10021
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq (%r14,%rbx,8), %rdi
callq 0x3100
movq (%r15,%rbx,8), %rdi
callq 0x3100
incq %rbx
cmpq %rbx, %r12
jne 0x10001
movl 0xd65b(%rip), %ebx      # 0x1d67c
movq 0x10(%rsp), %rdi
callq 0x3040
movq %r15, %rdi
callq 0x3040
movq 0x20(%rsp), %rdi
callq 0x3040
movl %ebx, 0x54(%rsp)
movq %r13, 0x58(%rsp)
leaq 0x5396(%rip), %rsi      # 0x153e3
leaq 0xd934(%rip), %rdx      # 0x1d988
leaq 0x5755(%rip), %rcx      # 0x157b0
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x4ff6(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x10118
movq %rax, %r14
leaq 0x40(%rsp), %rdi
movl $0x20, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x3450
movslq 0xd5d6(%rip), %rdx      # 0x1d67c
movl $0x4, %esi
movq 0x8(%rsp), %rdi
movq %r14, %rcx
callq 0x3450
cmpl $0x0, 0xd5bd(%rip)      # 0x1d67c
jle 0x100ef
xorl %ebx, %ebx
movq 0xd5b6(%rip), %rax      # 0x1d680
movq (%rax,%rbx,8), %rdi
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
movq %r14, %rcx
callq 0x3450
incq %rbx
movslq 0xd592(%rip), %rax      # 0x1d67c
cmpq %rax, %rbx
jl 0x100c3
movq %r14, %rdi
callq 0x3100
movq 0x8(%rsp), %rdi
callq 0x3040
movl $0x1, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x62a0(%rip), %rsi      # 0x163c6
leaq 0x80(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x6fc9(%rip), %rsi      # 0x1710c
movl %r12d, %edx
movl %ebp, %ecx
movl %ebx, %r8d
jmp 0x10165
callq 0x3060
movl (%rax), %edi
leaq 0x6f76(%rip), %rsi      # 0x170d1
movl %r12d, %edx
movl %ebp, %ecx
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x6f46(%rip), %rsi      # 0x170c0
movq %r15, %rdx
jmp 0x1012e
callq 0x3060
movl (%rax), %edi
leaq 0x6f33(%rip), %rsi      # 0x170c0
movq %rbx, %rdx
jmp 0x1012e