// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rtkcmn.cpp
// Function: bamboo::rtk_uncompress(char const*, char*)
extern int rtk_uncompress(const char *file, char *uncfile)
{
    int stat=0;
    char *p,cmd[2048]="",tmpfile[1024]="",buff[1024],*fname,*dir="";
    
    trace(3,"rtk_uncompress: file=%s\n",file);
    
    strcpy(tmpfile,file);
    if (!(p=strrchr(tmpfile,'.'))) return 0;
    
    /* uncompress by gzip */
    if (!strcmp(p,".z"  )||!strcmp(p,".Z"  )||
        !strcmp(p,".gz" )||!strcmp(p,".GZ" )||
        !strcmp(p,".zip")||!strcmp(p,".ZIP")) {
        
        strcpy(uncfile,tmpfile); uncfile[p-tmpfile]='\0';
        sprintf(cmd,"gzip -f -d -c \"%s\" > \"%s\"",tmpfile,uncfile);
        
        if (execcmd(cmd)) {
            remove(uncfile);
            return -1;
        }
        strcpy(tmpfile,uncfile);
        stat=1;
    }
    /* extract tar file */
    if ((p=strrchr(tmpfile,'.'))&&!strcmp(p,".tar")) {
        
        strcpy(uncfile,tmpfile); uncfile[p-tmpfile]='\0';
        strcpy(buff,tmpfile);
        fname=buff;
#ifdef WIN32
        if ((p=strrchr(buff,'\\'))) {
            *p='\0'; dir=fname; fname=p+1;
        }
        sprintf(cmd,"set PATH=%%CD%%;%%PATH%% & cd /D \"%s\" & tar -xf \"%s\"",
                dir,fname);
#else
        if ((p=strrchr(buff,'/'))) {
            *p='\0'; dir=fname; fname=p+1;
        }
        sprintf(cmd,"tar -C \"%s\" -xf \"%s\"",dir,tmpfile);
#endif
        if (execcmd(cmd)) {
            if (stat) remove(tmpfile);
            return -1;
        }
        if (stat) remove(tmpfile);
        stat=1;
    }
    /* extract hatanaka-compressed file by cnx2rnx */
    else if ((p=strrchr(tmpfile,'.'))&&strlen(p)>3&&(*(p+3)=='d'||*(p+3)=='D')) {
        
        strcpy(uncfile,tmpfile);
        uncfile[p-tmpfile+3]=*(p+3)=='D'?'O':'o';
        sprintf(cmd,"crx2rnx < \"%s\" > \"%s\"",tmpfile,uncfile);
        
        if (execcmd(cmd)) {
            remove(uncfile);
            if (stat) remove(tmpfile);
            return -1;
        }
        if (stat) remove(tmpfile);
        stat=1;
    }
    trace(3,"rtk_uncompress: stat=%d\n",stat);
    return stat;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq %rsi, %rbx
movq %rdi, %r12
leaq -0xc30(%rbp), %rdi
xorl %r15d, %r15d
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x8390
leaq -0x430(%rbp), %r14
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x8390
movq %r14, %rdi
movq %r12, %rsi
callq 0x85c0
pushq $0x2e
popq %rsi
movq %r14, %rdi
callq 0x8690
testq %rax, %rax
je 0x4d1be
movq %rax, %r12
cmpb $0x2e, (%rax)
pushq $-0x1
popq %r13
jne 0x4cfd7
cmpb $0x7a, 0x1(%r12)
jne 0x4cfc7
cmpb $0x0, 0x2(%r12)
je 0x4d02d
cmpb $0x5a, 0x1(%r12)
jne 0x4cfd7
cmpb $0x0, 0x2(%r12)
je 0x4d02d
leaq 0x1e3e9(%rip), %rsi     # 0x6b3c7
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x4d02d
leaq 0x1e3da(%rip), %rsi     # 0x6b3cb
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x4d02d
leaq 0x1e3cb(%rip), %rsi     # 0x6b3cf
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x4d02d
leaq 0x1e3bd(%rip), %rsi     # 0x6b3d4
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x4d02d
xorl %r15d, %r15d
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x4d097
movq %rbx, %rdi
movq %r14, %rsi
callq 0x85c0
subq %r14, %r12
movb $0x0, (%rbx,%r12)
leaq 0x1e392(%rip), %rsi     # 0x6b3d9
leaq -0xc30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8110
movq %r15, %rdi
callq 0x8520
testl %eax, %eax
je 0x4d07d
movq %rbx, %r14
movq %r14, %rdi
callq 0x8b80
movl %r13d, %r15d
jmp 0x4d1be
leaq -0x430(%rbp), %rdi
movq %rbx, %rsi
callq 0x85c0
pushq $0x1
popq %r15
movl $0x0, -0x2c(%rbp)
pushq $0x2e
popq %rsi
movq %r14, %rdi
callq 0x8690
testq %rax, %rax
je 0x4d1be
movq %rax, %r12
leaq 0x1e33e(%rip), %rsi     # 0x6b3f3
movq %rax, %rdi
callq 0x8890
testl %eax, %eax
je 0x4d13e
movq %r12, %rdi
callq 0x8290
cmpq $0x4, %rax
jb 0x4d1be
movzbl 0x3(%r12), %eax
orl $0x20, %eax
cmpl $0x64, %eax
jne 0x4d1be
movq %rbx, %rdi
movq %r14, %rsi
callq 0x85c0
cmpb $0x44, 0x3(%r12)
setne %al
shlb $0x5, %al
orb $0x4f, %al
subq %r14, %r12
movb %al, 0x3(%rbx,%r12)
leaq 0x1e300(%rip), %rsi     # 0x6b40d
leaq -0xc30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8110
movq %r15, %rdi
callq 0x8520
testl %eax, %eax
je 0x4d1d3
movq %rbx, %rdi
callq 0x8b80
jmp 0x4d1b1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x85c0
subq %r14, %r12
movb $0x0, (%rbx,%r12)
leaq -0x1030(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x85c0
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x8690
testq %rax, %rax
je 0x4d178
movb $0x0, (%rax)
jmp 0x4d17f
leaq 0x13466(%rip), %rbx     # 0x605e5
leaq 0x1e272(%rip), %rsi     # 0x6b3f8
xorl %r13d, %r13d
leaq -0xc30(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8110
movq %r15, %rdi
callq 0x8520
negl %eax
sbbl %r13d, %r13d
orl $0x1, %r13d
movl %r13d, %r15d
cmpb $0x0, -0x2c(%rbp)
je 0x4d06d
movl %r15d, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %r13
jmp 0x4d1b1