// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebp
movw $0x72, 0x18(%rsp)
movw $0x77, 0x6(%rsp)
leaq 0x2528b(%rip), %rdx     # 0x41a04
callq 0x3210
testl %eax, %eax
js 0x1c894
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x1, %r12d
movq $0x0, 0x20(%rsp)
leaq 0x25263(%rip), %r13     # 0x41a04
movq $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x1, %r15d
cmpl $0x53, %eax
jle 0x1c7e9
cmpl $0x72, %eax
jg 0x1c801
cmpl $0x54, %eax
je 0x1c822
cmpl $0x6f, %eax
jne 0x1ca48
movq 0x32809(%rip), %rax     # 0x4efe0
movq (%rax), %rdi
callq 0x3570
movq %rax, 0x10(%rsp)
jmp 0x1c86b
cmpl $0x31, %eax
je 0x1c856
cmpl $0x3f, %eax
je 0x1c84c
cmpl $0x53, %eax
jne 0x1ca48
xorl %r15d, %r15d
jmp 0x1c86b
cmpl $0x75, %eax
je 0x1c838
cmpl $0x73, %eax
jne 0x1ca48
cmpl $-0x1, %ebx
jne 0x1cad9
xorl %r12d, %r12d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1c86b
movq 0x327b7(%rip), %rax     # 0x4efe0
movq (%rax), %rdi
callq 0x3570
movq %rax, 0x20(%rsp)
jmp 0x1c86b
cmpl $0x1, %r12d
jne 0x1caf8
movl $0x1, %r12d
xorl %ebx, %ebx
jmp 0x1c86b
movl $0x1, 0xc(%rsp)
jmp 0x1c86b
movl $0x1, %ebx
cmpl $0x1, %r12d
movl $0x1, %r12d
jne 0x1cb17
movl %ebp, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3210
testl %eax, %eax
jns 0x1c7b8
testl %r15d, %r15d
sete %al
testl %r12d, %r12d
sete %r12b
movq 0x20(%rsp), %r13
jmp 0x1c8b2
xorl %eax, %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
movq 0x326ff(%rip), %rcx     # 0x4efb8
cmpl %ebp, (%rcx)
je 0x1ca48
movq %rcx, %rbp
testb %al, %al
jne 0x1c8d9
leaq 0x18(%rsp), %rdi
callq 0x3360
movw $0x62, 0x18(%rsp,%rax)
testb %r12b, %r12b
jne 0x1c8ef
leaq 0x6(%rsp), %rdi
callq 0x3360
movw $0x62, 0x6(%rsp,%rax)
leaq 0x6(%rsp), %rdi
callq 0x3360
movw $0x68, 0x6(%rsp,%rax)
testl %ebx, %ebx
js 0x1c91c
addb $0x30, %bl
leaq 0x1e(%rsp), %rsi
movb %bl, (%rsi)
movb $0x0, 0x1(%rsi)
leaq 0x6(%rsp), %rdi
callq 0x3480
testq %r13, %r13
je 0x1c93c
movq %r13, %rdi
callq 0x27ea0
movq %rax, %r12
movq %r13, %r15
movq %r13, %rdi
callq 0x2ee9e
movq %rax, %r13
jmp 0x1c945
movq %r13, %r15
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x10(%rsp), %rbx
movslq (%rbp), %rax
movq (%r14,%rax,8), %rdi
leaq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x278cd
movq %rax, %rbp
testq %rax, %rax
movq %r12, 0x10(%rsp)
je 0x1ca59
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x1ca63
movq %rbp, %r12
addq $0x10, %r12
cmpq $0x0, 0x38(%rax)
je 0x1ca38
cmpl $0x0, 0x30(%rax)
je 0x1ca38
testq %r15, %r15
je 0x1ca7c
movq (%r12), %rdi
movq %r13, %rsi
callq 0x1c50b
movq %rax, %r14
testq %rbx, %rbx
leaq 0x2249d(%rip), %rdi     # 0x3ee58
cmovneq %rbx, %rdi
leaq 0x6(%rsp), %rsi
movq %r14, %rdx
callq 0x278cd
testq %rax, %rax
je 0x1caa5
movq %rax, %r12
movq %rbp, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x1b864
movl %eax, %r15d
testq %r13, %r13
je 0x1c9f6
movq %r13, %rdi
callq 0x2e970
cmpq 0x10(%rbp), %r14
je 0x1ca04
movq %r14, %rdi
callq 0x22e78
movq %rbp, %rdi
callq 0x27d21
movq %r12, %rdi
callq 0x27d21
movq 0x10(%rsp), %rdi
callq 0x3350
movq %rbx, %rdi
callq 0x3350
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %r12, %rsi
callq 0x45d7
jmp 0x1c999
movl 0xc(%rsp), %edi
callq 0x4418
movl $0x1, %r15d
jmp 0x1ca26
movq %r14, %rdi
callq 0x4683
jmp 0x1ca6b
movq %r14, %rdi
callq 0x4654
movl $0x1, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x1c9e9
movq 0x32565(%rip), %rax     # 0x4efe8
movq (%rax), %rcx
leaq 0x25089(%rip), %rdi     # 0x41b16
movl $0x52, %esi
movl $0x1, %edx
callq 0x3700
movq (%r12), %r14
jmp 0x1c9b1
testq %rbx, %rbx
movq 0x32539(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
leaq 0x22858(%rip), %rdx     # 0x3f311
cmovneq %rbx, %rdx
leaq 0x250a5(%rip), %rsi     # 0x41b69
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x3750
movl $0x1, %r15d
jmp 0x1c9e9
leaq 0x24f2e(%rip), %rdi     # 0x41a0e
leaq 0x24a9d(%rip), %rsi     # 0x41584
leaq 0x24f35(%rip), %rcx     # 0x41a23
movl $0x188, %edx            # imm = 0x188
callq 0x31b0
leaq 0x24f45(%rip), %rdi     # 0x41a44
leaq 0x24a7e(%rip), %rsi     # 0x41584
leaq 0x24f16(%rip), %rcx     # 0x41a23
movl $0x18a, %edx            # imm = 0x18A
callq 0x31b0
leaq 0x24f26(%rip), %rdi     # 0x41a44
leaq 0x24a5f(%rip), %rsi     # 0x41584
leaq 0x24ef7(%rip), %rcx     # 0x41a23
movl $0x18b, %edx            # imm = 0x18B
callq 0x31b0
nop