// File: /workspace/github_cpp_makefile_star2_O3/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
movq %r14, %rdi
movl $0x2e, %esi
callq 0x86a0
testq %rax, %rax
je 0x55cda
movq %rax, %r12
cmpb $0x2e, (%rax)
jne 0x55aea
cmpb $0x7a, 0x1(%r12)
jne 0x55ada
cmpb $0x0, 0x2(%r12)
je 0x55b3e
cmpb $0x5a, 0x1(%r12)
jne 0x55aea
cmpb $0x0, 0x2(%r12)
je 0x55b3e
leaq 0x1f8c0(%rip), %rsi     # 0x753b1
movq %r12, %rdi
callq 0x8880
testl %eax, %eax
je 0x55b3e
leaq 0x1f8b1(%rip), %rsi     # 0x753b5
movq %r12, %rdi
callq 0x8880
testl %eax, %eax
je 0x55b3e
leaq 0x1f8a2(%rip), %rsi     # 0x753b9
movq %r12, %rdi
callq 0x8880
testl %eax, %eax
je 0x55b3e
leaq 0x1f894(%rip), %rsi     # 0x753be
movq %r12, %rdi
callq 0x8880
testl %eax, %eax
je 0x55b3e
xorl %r15d, %r15d
movb $0x1, %r13b
jmp 0x55ba9
movq %rbx, %rdi
movq %r14, %rsi
callq 0x85c0
subq %r14, %r12
movb $0x0, (%rbx,%r12)
leaq 0x1f86b(%rip), %rsi     # 0x753c3
leaq -0xc30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8120
movq %r15, %rdi
callq 0x8520
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x55b91
movq %rbx, %r14
movq %r14, %rdi
callq 0x8b80
jmp 0x55cda
leaq -0x430(%rbp), %rdi
movq %rbx, %rsi
callq 0x85c0
movl $0x1, %r15d
xorl %r13d, %r13d
movq %r14, %rdi
movl $0x2e, %esi
callq 0x86a0
testq %rax, %rax
je 0x55cda
movq %rax, %r12
leaq 0x1f814(%rip), %rsi     # 0x753dd
movq %rax, %rdi
callq 0x8880
testl %eax, %eax
je 0x55c5c
movq %r12, %rdi
callq 0x8290
cmpq $0x4, %rax
jb 0x55cda
movzbl 0x3(%r12), %eax
orl $0x20, %eax
cmpl $0x64, %eax
jne 0x55cda
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 0x1f7d2(%rip), %rsi     # 0x753f7
leaq -0xc30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8120
movq %r15, %rdi
callq 0x8520
testl %eax, %eax
je 0x55cef
movq %rbx, %rdi
callq 0x8b80
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x55cd1
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
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x86a0
testq %rax, %rax
je 0x55c98
movb $0x0, (%rax)
jmp 0x55c9f
leaq 0x14956(%rip), %rbx     # 0x6a5f5
leaq 0x1f73c(%rip), %rsi     # 0x753e2
xorl %r15d, %r15d
leaq -0xc30(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8120
movq %r12, %rdi
callq 0x8520
negl %eax
sbbl %r15d, %r15d
orl $0x1, %r15d
testb %r13b, %r13b
je 0x55b84
movl %r15d, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %r15d
jmp 0x55cd1