// File: 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
subq $0x1050, %rsp           # imm = 0x1050
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
leaq -0x830(%rbp), %rdi
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x93d0
leaq -0xc30(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x93d0
leaq 0x23930(%rip), %rax     # 0xbcd07
movq %rax, -0x1040(%rbp)
movq -0x10(%rbp), %rdx
movl $0x3, %edi
leaq 0x2ec0c(%rip), %rsi     # 0xc7ffa
movb $0x0, %al
callq 0x8b980
leaq -0xc30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x96f0
leaq -0xc30(%rbp), %rdi
movl $0x2e, %esi
callq 0x9820
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x9942c
movl $0x0, -0x4(%rbp)
jmp 0x99790
movq -0x28(%rbp), %rdi
leaq 0x2ebdc(%rip), %rsi     # 0xc8013
callq 0x9a60
cmpl $0x0, %eax
je 0x994ae
movq -0x28(%rbp), %rdi
leaq 0x2ebca(%rip), %rsi     # 0xc8016
callq 0x9a60
cmpl $0x0, %eax
je 0x994ae
movq -0x28(%rbp), %rdi
leaq 0x2ebb8(%rip), %rsi     # 0xc8019
callq 0x9a60
cmpl $0x0, %eax
je 0x994ae
movq -0x28(%rbp), %rdi
leaq 0x2eba7(%rip), %rsi     # 0xc801d
callq 0x9a60
cmpl $0x0, %eax
je 0x994ae
movq -0x28(%rbp), %rdi
leaq 0x2eb96(%rip), %rsi     # 0xc8021
callq 0x9a60
cmpl $0x0, %eax
je 0x994ae
movq -0x28(%rbp), %rdi
leaq 0x2eb86(%rip), %rsi     # 0xc8026
callq 0x9a60
cmpl $0x0, %eax
jne 0x99531
movq -0x18(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
callq 0x96f0
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
leaq -0xc30(%rbp), %rdx
subq %rdx, %rcx
movb $0x0, (%rax,%rcx)
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x2eb3e(%rip), %rsi     # 0xc802b
movb $0x0, %al
callq 0x9150
leaq -0x830(%rbp), %rdi
callq 0x95910
cmpl $0x0, %eax
je 0x9951a
movq -0x18(%rbp), %rdi
callq 0x9d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x99790
leaq -0xc30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x96f0
movl $0x1, -0x1c(%rbp)
leaq -0xc30(%rbp), %rdi
movl $0x2e, %esi
callq 0x9820
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x9965f
movq -0x28(%rbp), %rdi
leaq 0x2eaea(%rip), %rsi     # 0xc8045
callq 0x9a60
cmpl $0x0, %eax
jne 0x9965f
movq -0x18(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
callq 0x96f0
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
leaq -0xc30(%rbp), %rdx
subq %rdx, %rcx
movb $0x0, (%rax,%rcx)
leaq -0x1030(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
callq 0x96f0
leaq -0x1030(%rbp), %rax
movq %rax, -0x1038(%rbp)
leaq -0x1030(%rbp), %rdi
movl $0x2f, %esi
callq 0x9820
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x995ef
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x1038(%rbp), %rax
movq %rax, -0x1040(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1038(%rbp)
leaq -0x830(%rbp), %rdi
movq -0x1040(%rbp), %rdx
leaq -0xc30(%rbp), %rcx
leaq 0x2ea3f(%rip), %rsi     # 0xc804a
movb $0x0, %al
callq 0x9150
leaq -0x830(%rbp), %rdi
callq 0x95910
cmpl $0x0, %eax
je 0x99641
cmpl $0x0, -0x1c(%rbp)
je 0x99635
leaq -0xc30(%rbp), %rdi
callq 0x9d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x99790
cmpl $0x0, -0x1c(%rbp)
je 0x99653
leaq -0xc30(%rbp), %rdi
callq 0x9d90
movl $0x1, -0x1c(%rbp)
jmp 0x99774
leaq -0xc30(%rbp), %rdi
movl $0x2e, %esi
callq 0x9820
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x99772
movq -0x28(%rbp), %rdi
callq 0x92e0
cmpq $0x3, %rax
jbe 0x99772
movq -0x28(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x64, %eax
je 0x996af
movq -0x28(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x44, %eax
jne 0x99772
movq -0x18(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
callq 0x96f0
movq -0x28(%rbp), %rax
movsbl 0x3(%rax), %ecx
movb $0x4f, %al
movb $0x6f, %dl
movb %dl, -0x1042(%rbp)
cmpl $0x44, %ecx
movb %al, -0x1041(%rbp)
je 0x996e8
movb -0x1042(%rbp), %al
movb %al, -0x1041(%rbp)
movb -0x1041(%rbp), %dl
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
leaq -0xc30(%rbp), %rsi
subq %rsi, %rcx
movb %dl, 0x3(%rax,%rcx)
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x2e942(%rip), %rsi     # 0xc805f
movb $0x0, %al
callq 0x9150
leaq -0x830(%rbp), %rdi
callq 0x95910
cmpl $0x0, %eax
je 0x99759
movq -0x18(%rbp), %rdi
callq 0x9d90
cmpl $0x0, -0x1c(%rbp)
je 0x99750
leaq -0xc30(%rbp), %rdi
callq 0x9d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x99790
cmpl $0x0, -0x1c(%rbp)
je 0x9976b
leaq -0xc30(%rbp), %rdi
callq 0x9d90
movl $0x1, -0x1c(%rbp)
jmp 0x99774
movl -0x1c(%rbp), %edx
movl $0x3, %edi
leaq 0x2e8f2(%rip), %rsi     # 0xc8075
movb $0x0, %al
callq 0x8b980
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1050, %rsp           # imm = 0x1050
popq %rbp
retq
nopl (%rax)