// File: /workspace/github_cpp_makefile_star2_O1/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 %r14d, %r14d
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x8390
leaq -0x430(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x8390
movq %r15, %rdi
movq %r12, %rsi
callq 0x85c0
movq %r15, %rdi
movl $0x2e, %esi
callq 0x86a0
testq %rax, %rax
je 0x5678f
movq %rax, %r12
leaq 0x1ee63(%rip), %rsi     # 0x753d1
movq %rax, %rdi
callq 0x8890
testl %eax, %eax
je 0x565e1
leaq 0x1ee53(%rip), %rsi     # 0x753d4
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x565e1
leaq 0x1ee43(%rip), %rsi     # 0x753d7
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x565e1
leaq 0x1ee34(%rip), %rsi     # 0x753db
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x565e1
leaq 0x1ee25(%rip), %rsi     # 0x753df
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x565e1
leaq 0x1ee17(%rip), %rsi     # 0x753e4
movq %r12, %rdi
callq 0x8890
testl %eax, %eax
je 0x565e1
xorl %r14d, %r14d
movb $0x1, %r13b
jmp 0x56649
movq %rbx, %rdi
movq %r15, %rsi
callq 0x85c0
subq %r15, %r12
movb $0x0, (%rbx,%r12)
leaq 0x1edee(%rip), %rsi     # 0x753e9
leaq -0xc30(%rbp), %r14
movq %r14, %rdi
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8120
movq %r14, %rdi
callq 0x8520
testl %eax, %eax
je 0x56631
movq %rbx, %rdi
callq 0x8b90
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x5678f
leaq -0x430(%rbp), %rdi
movq %rbx, %rsi
callq 0x85c0
movl $0x1, %r14d
xorl %r13d, %r13d
movq %r15, %rdi
movl $0x2e, %esi
callq 0x86a0
testq %rax, %rax
je 0x5678f
movq %rax, %r12
leaq 0x1ed9a(%rip), %rsi     # 0x75403
movq %rax, %rdi
callq 0x8890
testl %eax, %eax
je 0x566ff
testq %r12, %r12
je 0x5678f
movq %r12, %rdi
callq 0x8290
cmpq $0x4, %rax
jb 0x5678f
movzbl 0x3(%r12), %eax
orl $0x20, %eax
cmpl $0x64, %eax
jne 0x5678f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x85c0
cmpb $0x44, 0x3(%r12)
setne %al
shlb $0x5, %al
orb $0x4f, %al
subq %r15, %r12
movb %al, 0x3(%rbx,%r12)
leaq 0x1ed4f(%rip), %rsi     # 0x7541d
leaq -0xc30(%rbp), %r14
movq %r14, %rdi
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8120
movq %r14, %rdi
callq 0x8520
testl %eax, %eax
je 0x56778
movq %rbx, %rdi
callq 0x8b90
jmp 0x56770
movq %rbx, %rdi
movq %r15, %rsi
callq 0x85c0
subq %r15, %r12
movb $0x0, (%rbx,%r12)
leaq -0x1030(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x85c0
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x86a0
testq %rax, %rax
je 0x5673b
movb $0x0, (%rax)
jmp 0x56742
leaq 0x13eb3(%rip), %rbx     # 0x6a5f5
leaq 0x1ecbf(%rip), %rsi     # 0x75408
leaq -0xc30(%rbp), %r14
leaq -0x430(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8120
movq %r14, %rdi
callq 0x8520
testl %eax, %eax
je 0x56778
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x5677e
movl $0x1, %r14d
testb %r13b, %r13b
jne 0x5678f
leaq -0x430(%rbp), %rdi
callq 0x8b90
movl %r14d, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq