// File: DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::ftpthread(void*)
static void *ftpthread(void *arg)
#endif
	{
		ftp_t *ftp = (ftp_t *)arg;
		FILE *fp;
		gtime_t time;
		char remote[1024], local[1024], tmpfile[1024], errfile[1024], *p;
		char cmd[2048], env[1024] = "", opt[1024];
		const char *proxyopt = "";
		const char *proto;
		int ret;

		tracet(3, "ftpthread:\n");

		if (!*localdir) {
			tracet(1, "no local directory\n");
			ftp->error = 11;
			ftp->state = 3;
			return 0;
		}
		/* replace keyword in file path and local path */
		time = timeadd(utc2gpst(timeget()), ftp->topts[0]);
		reppath(ftp->file, remote, time, "", "");

		if ((p = strrchr(remote, '/'))) p++; else p = remote;
		sprintf(local, "%s%c%s", localdir, FILEPATHSEP, p);
		sprintf(errfile, "%s.err", local);

		/* if local file exist, skip download */
		strcpy(tmpfile, local);
		if ((p = strrchr(tmpfile, '.')) &&
			(!strcmp(p, ".z") || !strcmp(p, ".gz") || !strcmp(p, ".zip") ||
				!strcmp(p, ".Z") || !strcmp(p, ".GZ") || !strcmp(p, ".ZIP"))) {
			*p = '\0';
		}
		if ((fp = fopen(tmpfile, "rb"))) {
			fclose(fp);
			strcpy(ftp->local, tmpfile);
			tracet(3, "ftpthread: file exists %s\n", ftp->local);
			ftp->state = 2;
			return 0;
		}
		/* proxy settings for wget (ref [2]) */
		if (*proxyaddr) {
			proto = ftp->proto ? "http" : "ftp";
			sprintf(env, "set %s_proxy=http://%s & ", proto, proxyaddr);
			proxyopt = "--proxy=on ";
		}
		/* download command (ref [2]) */
		if (ftp->proto == 0) { /* ftp */
			sprintf(opt, "--ftp-user=%s --ftp-password=%s --glob=off --passive-ftp %s-t 1 -T %d -O \"%s\"",
				ftp->user, ftp->passwd, proxyopt, FTP_TIMEOUT, local);
			sprintf(cmd, "%s%s %s \"ftp://%s/%s\" 2> \"%s\"\n", env, FTP_CMD, opt, ftp->addr,
				remote, errfile);
		}
		else { /* http */
			sprintf(opt, "%s-t 1 -T %d -O \"%s\"", proxyopt, FTP_TIMEOUT, local);
			sprintf(cmd, "%s%s %s \"http://%s/%s\" 2> \"%s\"\n", env, FTP_CMD, opt, ftp->addr,
				remote, errfile);
		}
		/* execute download command */
		if ((ret = execcmd(cmd))) {
			remove(local);
			tracet(1, "execcmd error: cmd=%s ret=%d\n", cmd, ret);
			ftp->error = ret;
			ftp->state = 3;
			return 0;
		}
		remove(errfile);

		/* uncompress downloaded file */
		if ((p = strrchr(local, '.')) &&
			(!strcmp(p, ".z") || !strcmp(p, ".gz") || !strcmp(p, ".zip") ||
				!strcmp(p, ".Z") || !strcmp(p, ".GZ") || !strcmp(p, ".ZIP"))) {

			if (rtk_uncompress(local, tmpfile)) {
				remove(local);
				strcpy(local, tmpfile);
			}
			else {
				tracet(1, "file uncompact error: %s\n", local);
				ftp->error = 12;
				ftp->state = 3;
				return 0;
			}
		}
		strcpy(ftp->local, local);
		ftp->state = 2; /* ftp completed */

		tracet(3, "ftpthread: complete cmd=%s\n", cmd);
		return 0;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20b0, %rsp           # imm = 0x20B0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq -0x1c40(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x93d0
leaq 0x154f6(%rip), %rax     # 0xbcd07
movq %rax, -0x2048(%rbp)
movl $0x3, %edi
leaq 0x22584(%rip), %rsi     # 0xc9da8
movb $0x0, %al
callq 0x95890
cmpb $0x0, 0x6842e(%rip)     # 0x10fc60
jne 0xa7869
movl $0x1, %edi
leaq 0x22574(%rip), %rsi     # 0xc9db4
movb $0x0, %al
callq 0x95890
movq -0x18(%rbp), %rax
movl $0xb, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x3, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xa7e36
callq 0x8e920
movq %rax, -0x2088(%rbp)
movsd %xmm0, -0x2080(%rbp)
movq -0x2088(%rbp), %rdi
movsd -0x2080(%rbp), %xmm0
callq 0x8f0a0
movq %rax, -0x2078(%rbp)
movsd %xmm0, -0x2070(%rbp)
movq -0x18(%rbp), %rax
cvtsi2sdl 0xe0c(%rax), %xmm1
movq -0x2078(%rbp), %rdi
movsd -0x2070(%rbp), %xmm0
callq 0x8e860
movq %rax, -0x2068(%rbp)
movsd %xmm0, -0x2060(%rbp)
movq -0x2068(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x2060(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
addq $0x40c, %rdi            # imm = 0x40C
leaq -0x430(%rbp), %rsi
movq -0x30(%rbp), %rax
movq %rax, -0x2098(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x2090(%rbp)
movq -0x2098(%rbp), %rdx
movsd -0x2090(%rbp), %xmm0
leaq 0x153e4(%rip), %r8      # 0xbcd07
movq %r8, %rcx
callq 0x95e20
leaq -0x430(%rbp), %rdi
movl $0x2f, %esi
callq 0x9820
movq %rax, -0x1038(%rbp)
cmpq $0x0, %rax
je 0xa795d
movq -0x1038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1038(%rbp)
jmp 0xa796b
leaq -0x430(%rbp), %rax
movq %rax, -0x1038(%rbp)
leaq -0x830(%rbp), %rdi
movq -0x1038(%rbp), %r8
leaq 0x22448(%rip), %rsi     # 0xc9dc8
leaq 0x682d9(%rip), %rdx     # 0x10fc60
movl $0x2f, %ecx
movb $0x0, %al
callq 0x9150
leaq -0x1030(%rbp), %rdi
leaq -0x830(%rbp), %rdx
leaq 0x22427(%rip), %rsi     # 0xc9dcf
movb $0x0, %al
callq 0x9150
leaq -0xc30(%rbp), %rdi
leaq -0x830(%rbp), %rsi
callq 0x96f0
leaq -0xc30(%rbp), %rdi
movl $0x2e, %esi
callq 0x9820
movq %rax, -0x1038(%rbp)
cmpq $0x0, %rax
je 0xa7a7e
movq -0x1038(%rbp), %rdi
leaq 0x20621(%rip), %rsi     # 0xc8013
callq 0x9a60
cmpl $0x0, %eax
je 0xa7a74
movq -0x1038(%rbp), %rdi
leaq 0x2060f(%rip), %rsi     # 0xc8019
callq 0x9a60
cmpl $0x0, %eax
je 0xa7a74
movq -0x1038(%rbp), %rdi
leaq 0x205ff(%rip), %rsi     # 0xc8021
callq 0x9a60
cmpl $0x0, %eax
je 0xa7a74
movq -0x1038(%rbp), %rdi
leaq 0x205dc(%rip), %rsi     # 0xc8016
callq 0x9a60
cmpl $0x0, %eax
je 0xa7a74
movq -0x1038(%rbp), %rdi
leaq 0x205cb(%rip), %rsi     # 0xc801d
callq 0x9a60
cmpl $0x0, %eax
je 0xa7a74
movq -0x1038(%rbp), %rdi
leaq 0x205bc(%rip), %rsi     # 0xc8026
callq 0x9a60
cmpl $0x0, %eax
jne 0xa7a7e
movq -0x1038(%rbp), %rax
movb $0x0, (%rax)
leaq -0xc30(%rbp), %rdi
leaq 0x2117f(%rip), %rsi     # 0xc8c0b
callq 0x98d0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0xa7af0
movq -0x20(%rbp), %rdi
callq 0x9770
movq -0x18(%rbp), %rdi
addq $0xa0c, %rdi            # imm = 0xA0C
leaq -0xc30(%rbp), %rsi
callq 0x96f0
movq -0x18(%rbp), %rdx
addq $0xa0c, %rdx            # imm = 0xA0C
movl $0x3, %edi
leaq 0x22304(%rip), %rsi     # 0xc9dd6
movb $0x0, %al
callq 0x95890
movq -0x18(%rbp), %rax
movl $0x2, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xa7e36
cmpb $0x0, 0x68569(%rip)     # 0x110060
je 0xa7b4d
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x2225c(%rip), %rax     # 0xc9d63
leaq 0x22250(%rip), %rcx     # 0xc9d5e
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x2050(%rbp)
leaq -0x1c40(%rbp), %rdi
movq -0x2050(%rbp), %rdx
leaq 0x222c0(%rip), %rsi     # 0xc9df1
leaq 0x68528(%rip), %rcx     # 0x110060
movb $0x0, %al
callq 0x9150
leaq 0x222c5(%rip), %rax     # 0xc9e0b
movq %rax, -0x2048(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xa7be9
leaq -0x2040(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x80c, %rdx            # imm = 0x80C
movq -0x18(%rbp), %rcx
addq $0x90c, %rcx            # imm = 0x90C
movq -0x2048(%rbp), %r8
leaq -0x830(%rbp), %rax
leaq 0x2228a(%rip), %rsi     # 0xc9e17
movl $0x1e, %r9d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9150
leaq -0x1840(%rbp), %rdi
leaq -0x1c40(%rbp), %rdx
leaq -0x2040(%rbp), %r8
movq -0x18(%rbp), %r9
addq $0xc, %r9
leaq -0x430(%rbp), %r10
leaq -0x1030(%rbp), %rax
leaq 0x22295(%rip), %rsi     # 0xc9e65
leaq 0x222ad(%rip), %rcx     # 0xc9e84
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x9150
jmp 0xa7c5a
leaq -0x2040(%rbp), %rdi
movq -0x2048(%rbp), %rdx
leaq -0x830(%rbp), %r8
leaq 0x2224b(%rip), %rsi     # 0xc9e50
movl $0x1e, %ecx
movb $0x0, %al
callq 0x9150
leaq -0x1840(%rbp), %rdi
leaq -0x1c40(%rbp), %rdx
leaq -0x2040(%rbp), %r8
movq -0x18(%rbp), %r9
addq $0xc, %r9
leaq -0x430(%rbp), %r10
leaq -0x1030(%rbp), %rax
leaq 0x22246(%rip), %rsi     # 0xc9e89
leaq 0x2223a(%rip), %rcx     # 0xc9e84
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x9150
leaq -0x1840(%rbp), %rdi
callq 0x95910
movl %eax, -0x2054(%rbp)
cmpl $0x0, %eax
je 0xa7cc1
leaq -0x830(%rbp), %rdi
callq 0x9d90
leaq -0x1840(%rbp), %rdx
movl -0x2054(%rbp), %ecx
movl $0x1, %edi
leaq 0x22213(%rip), %rsi     # 0xc9ea9
movb $0x0, %al
callq 0x95890
movl -0x2054(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x3, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xa7e36
leaq -0x1030(%rbp), %rdi
callq 0x9d90
leaq -0x830(%rbp), %rdi
movl $0x2e, %esi
callq 0x9820
movq %rax, -0x1038(%rbp)
cmpq $0x0, %rax
je 0xa7df3
movq -0x1038(%rbp), %rdi
leaq 0x20316(%rip), %rsi     # 0xc8013
callq 0x9a60
cmpl $0x0, %eax
je 0xa7d7f
movq -0x1038(%rbp), %rdi
leaq 0x20304(%rip), %rsi     # 0xc8019
callq 0x9a60
cmpl $0x0, %eax
je 0xa7d7f
movq -0x1038(%rbp), %rdi
leaq 0x202f4(%rip), %rsi     # 0xc8021
callq 0x9a60
cmpl $0x0, %eax
je 0xa7d7f
movq -0x1038(%rbp), %rdi
leaq 0x202d1(%rip), %rsi     # 0xc8016
callq 0x9a60
cmpl $0x0, %eax
je 0xa7d7f
movq -0x1038(%rbp), %rdi
leaq 0x202c0(%rip), %rsi     # 0xc801d
callq 0x9a60
cmpl $0x0, %eax
je 0xa7d7f
movq -0x1038(%rbp), %rdi
leaq 0x202b1(%rip), %rsi     # 0xc8026
callq 0x9a60
cmpl $0x0, %eax
jne 0xa7df3
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
callq 0x99390
cmpl $0x0, %eax
je 0xa7db8
leaq -0x830(%rbp), %rdi
callq 0x9d90
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
callq 0x96f0
jmp 0xa7df1
leaq -0x830(%rbp), %rdx
movl $0x1, %edi
leaq 0x220fc(%rip), %rsi     # 0xc9ec7
movb $0x0, %al
callq 0x95890
movq -0x18(%rbp), %rax
movl $0xc, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x3, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xa7e36
jmp 0xa7df3
movq -0x18(%rbp), %rdi
addq $0xa0c, %rdi            # imm = 0xA0C
leaq -0x830(%rbp), %rsi
callq 0x96f0
movq -0x18(%rbp), %rax
movl $0x2, (%rax)
leaq -0x1840(%rbp), %rdx
movl $0x3, %edi
leaq 0x220ba(%rip), %rsi     # 0xc9ee1
movb $0x0, %al
callq 0x95890
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20b0, %rsp           # imm = 0x20B0
popq %rbp
retq
nopw %cs:(%rax,%rax)