// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/padding.c
// Function: main_pad2unpad
int main_pad2unpad(int argc, char *argv[])
{
	samfile_t *in = 0, *out = 0;
        bam_header_t *h = 0;
	faidx_t *fai = 0;
	int c, is_bamin = 1, compress_level = -1, is_bamout = 1, is_long_help = 0;
	char in_mode[5], out_mode[5], *fn_out = 0, *fn_list = 0, *fn_ref = 0;
        int ret=0;

	/* parse command-line options */
	strcpy(in_mode, "r"); strcpy(out_mode, "w");
	while ((c = getopt(argc, argv, "Sso:u1T:?")) >= 0) {
		switch (c) {
		case 'S': is_bamin = 0; break;
		case 's': assert(compress_level == -1); is_bamout = 0; break;
		case 'o': fn_out = strdup(optarg); break;
		case 'u': assert(is_bamout == 1); compress_level = 0; break;
		case '1': assert(is_bamout == 1); compress_level = 1; break;
		case 'T': fn_ref = strdup(optarg); break;
                case '?': is_long_help = 1; break;
		default: return usage(is_long_help);
		}
        }
	if (argc == optind) return usage(is_long_help);

	if (is_bamin) strcat(in_mode, "b");
	if (is_bamout) strcat(out_mode, "b");
	strcat(out_mode, "h");
	if (compress_level >= 0) {
		char tmp[2];
		tmp[0] = compress_level + '0'; tmp[1] = '\0';
		strcat(out_mode, tmp);
	}

	// Load FASTA reference (also needed for SAM -> BAM if missing header)
	if (fn_ref) {
		fn_list = samfaipath(fn_ref);
		fai = fai_load(fn_ref);
	}
	// open file handlers
	if ((in = samopen(argv[optind], in_mode, fn_list)) == 0) {
		fprintf(stderr, "[depad] failed to open \"%s\" for reading.\n", argv[optind]);
		ret = 1;
		goto depad_end;
	}
	if (in->header == 0) {
		fprintf(stderr, "[depad] failed to read the header from \"%s\".\n", argv[optind]);
		ret = 1;
		goto depad_end;
	}
	if (in->header->text == 0 || in->header->l_text == 0) {
		fprintf(stderr, "[depad] Warning - failed to read any header text from \"%s\".\n", argv[optind]);
		assert (0 == in->header->l_text);
		assert (0 == in->header->text);
	}
	if (fn_ref) {
		h = fix_header(in->header, fai);
	} else {
		fprintf(stderr, "[depad] Warning - reference lengths will not be corrected without FASTA reference\n");
		h = in->header;
	}
	if ((out = samopen(fn_out? fn_out : "-", out_mode, h)) == 0) {
		fprintf(stderr, "[depad] failed to open \"%s\" for writing.\n", fn_out? fn_out : "standard output");
		ret = 1;
		goto depad_end;
	}

	// Do the depad
	ret = bam_pad2unpad(in, out, fai);

depad_end:
	// close files, free and return
	if (fai) fai_destroy(fai);
	if (h != in->header) bam_header_destroy(h);
	samclose(in);
	samclose(out);
	free(fn_list); free(fn_out);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl %edi, %ebp
movw $0x72, 0x1a(%rsp)
movw $0x77, 0xe(%rsp)
leaq 0x25d77(%rip), %rdx     # 0x42a54
callq 0x3210
testl %eax, %eax
js 0x1ce19
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x1, %r12d
movq $0x0, 0x20(%rsp)
leaq 0x25d4f(%rip), %r13     # 0x42a54
movq $0x0, 0x28(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x1, %r15d
cmpl $0x53, %eax
jle 0x1cd4d
cmpl $0x72, %eax
jg 0x1cd65
cmpl $0x54, %eax
je 0x1cd86
cmpl $0x6f, %eax
jne 0x1d060
movq 0x332a5(%rip), %rax     # 0x4ffe0
movq (%rax), %rdi
callq 0x3570
movq %rax, 0x28(%rsp)
jmp 0x1cdcf
cmpl $0x31, %eax
je 0x1cdba
cmpl $0x3f, %eax
je 0x1cdb0
cmpl $0x53, %eax
jne 0x1d060
xorl %r15d, %r15d
jmp 0x1cdcf
cmpl $0x75, %eax
je 0x1cd9c
cmpl $0x73, %eax
jne 0x1d060
cmpl $-0x1, %ebx
jne 0x1d074
xorl %r12d, %r12d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1cdcf
movq 0x33253(%rip), %rax     # 0x4ffe0
movq (%rax), %rdi
callq 0x3570
movq %rax, 0x20(%rsp)
jmp 0x1cdcf
cmpl $0x1, %r12d
jne 0x1d093
movl $0x1, %r12d
xorl %ebx, %ebx
jmp 0x1cdcf
movl $0x1, 0x14(%rsp)
jmp 0x1cdcf
movl $0x1, %ebx
cmpl $0x1, %r12d
movl $0x1, %r12d
jne 0x1d0b2
movl %ebp, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3210
testl %eax, %eax
jns 0x1cd1c
movq 0x331cd(%rip), %rax     # 0x4ffb8
movl (%rax), %r13d
cmpl %ebp, %r13d
je 0x1d060
testl %r15d, %r15d
je 0x1ce0d
leaq 0x1a(%rsp), %rdi
callq 0x3360
movw $0x62, 0x1a(%rsp,%rax)
testl %r12d, %r12d
movq 0x20(%rsp), %r15
jne 0x1ce4e
jmp 0x1ce5f
movq 0x33198(%rip), %rax     # 0x4ffb8
movl (%rax), %r13d
cmpl %ebp, %r13d
je 0x1d058
leaq 0x1a(%rsp), %rdi
callq 0x3360
movw $0x62, 0x1a(%rsp,%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movq $0x0, 0x28(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x3360
movw $0x62, 0xe(%rsp,%rax)
leaq 0xe(%rsp), %rdi
callq 0x3360
movw $0x68, 0xe(%rsp,%rax)
testl %ebx, %ebx
js 0x1ce8c
addb $0x30, %bl
leaq 0x30(%rsp), %rsi
movb %bl, (%rsi)
movb $0x0, 0x1(%rsi)
leaq 0xe(%rsp), %rdi
callq 0x3480
testq %r15, %r15
je 0x1ceb3
movq %r15, %rdi
callq 0x284ea
movq %rax, %r12
movq %r15, %rdi
callq 0x2faa6
movq %rax, %rbx
movq 0x3310a(%rip), %rax     # 0x4ffb8
movl (%rax), %r13d
jmp 0x1ceb8
xorl %ebx, %ebx
xorl %r12d, %r12d
movslq %r13d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x1a(%rsp), %rsi
movq %r12, %rdx
callq 0x27ef0
movq %rax, %rbp
testq %rax, %rax
movq %r12, 0x20(%rsp)
je 0x1cfc4
movq 0x10(%rbp), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %r13
je 0x1cfe2
movq %rbp, %r12
addq $0x10, %r12
cmpq $0x0, 0x38(%rdi)
je 0x1cfa6
cmpl $0x0, 0x30(%rdi)
je 0x1cfa6
testq %r15, %r15
je 0x1cffb
movq %rbx, %rsi
callq 0x1ca70
movq %rax, %r14
testq %r13, %r13
leaq 0x22f67(%rip), %rdi     # 0x3fe90
cmovneq %r13, %rdi
leaq 0xe(%rsp), %rsi
movq %r14, %rdx
callq 0x27ef0
testq %rax, %rax
je 0x1d024
movq %rax, %r12
movq %rbp, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x1bd6b
movl %eax, %r15d
testq %rbx, %rbx
je 0x1cf64
movq %rbx, %rdi
callq 0x2f578
cmpq 0x10(%rbp), %r14
je 0x1cf72
movq %r14, %rdi
callq 0x23577
movq %rbp, %rdi
callq 0x2836b
movq %r12, %rdi
callq 0x2836b
movq 0x20(%rsp), %rdi
callq 0x3350
movq %r13, %rdi
callq 0x3350
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %rax
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %r14
movq %rax, %rdx
callq 0x45d2
movq (%r14), %rdi
jmp 0x1cf0b
movq %r14, %rdi
callq 0x468d
movl $0x1, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x28(%rsp), %r13
jmp 0x1cf57
movq %r14, %rdi
callq 0x465e
movl $0x1, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x1cf57
movq 0x32fe6(%rip), %rax     # 0x4ffe8
movq (%rax), %rcx
leaq 0x25b5a(%rip), %rdi     # 0x42b66
movl $0x52, %esi
movl $0x1, %edx
callq 0x3700
movq (%r12), %r14
jmp 0x1cf1f
testq %r13, %r13
movq 0x32fba(%rip), %rax     # 0x4ffe8
movq (%rax), %rdi
leaq 0x23311(%rip), %rdx     # 0x40349
cmovneq %r13, %rdx
leaq 0x25b76(%rip), %rsi     # 0x42bb9
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x3750
movl $0x1, %r15d
jmp 0x1cf57
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %edi
callq 0x4413
movl $0x1, %r15d
jmp 0x1cf94
leaq 0x259e3(%rip), %rdi     # 0x42a5e
leaq 0x25552(%rip), %rsi     # 0x425d4
leaq 0x259ea(%rip), %rcx     # 0x42a73
movl $0x188, %edx            # imm = 0x188
callq 0x31b0
leaq 0x259fa(%rip), %rdi     # 0x42a94
leaq 0x25533(%rip), %rsi     # 0x425d4
leaq 0x259cb(%rip), %rcx     # 0x42a73
movl $0x18a, %edx            # imm = 0x18A
callq 0x31b0
leaq 0x259db(%rip), %rdi     # 0x42a94
leaq 0x25514(%rip), %rsi     # 0x425d4
leaq 0x259ac(%rip), %rcx     # 0x42a73
movl $0x18b, %edx            # imm = 0x18B
callq 0x31b0
nopl (%rax)