// File: /workspace/github_c_makefile_star2_O3/kevinp89[P]Operating-System-EXT2-file-system-with-commands/ext2_checker.c
// Function: main
int main(int argc, char **argv) {
	if (argc != 2) { // Requires only one argument, an ext2 formatted disk.
		fprintf(stderr, "Usage: %s [disk]\n", argv[0]);
		exit(1);
	}
	// Opening disk
	int fd = open(argv[1], O_RDWR);
	if (!fd) {
		fprintf(stderr, "Disk image '%s' not found.", argv[1]);
		exit(ENOENT);
	}
	// mmap the disk
	disk = mmap(NULL, 128*1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (disk == MAP_FAILED) {
		perror("mmap");
		exit(1);
	}
	// Grabbing super block and block descriptor
	sb = (struct ext2_super_block *)(disk + 1024);
	desc = (struct ext2_group_desc *)(disk + 2*1024);

	int errors = 0; // Total number of errors fixed, increment for every fix.
	// Allocating the bitmaps.
	unsigned char *map = (unsigned char *)(disk + 1024 * desc->bg_block_bitmap);
	unsigned char *imap = (unsigned char *)(disk + 1024 * desc->bg_inode_bitmap);

	// Count the free blocks based on the bitmap.
	int free = sb->s_blocks_count; // Total number of blocks.
	int diff; // Value to allocate the difference if there is one.
	int i;
	for (i = 0; i < sb->s_blocks_count; i++) {
		if (check_node(i, map)) free--;
	}
	// Check free versus the counts in sb and desc.
	// Block bitmap vs superblock
	if (free != sb->s_free_blocks_count) {
		diff = abs(sb->s_free_blocks_count - free);
		printf("Fixed: superblock's free block counter was off by %d compared to the bitmap\n",
					diff);
		sb->s_free_blocks_count = free;
		errors += diff;
	}
	// Block bitmap vs group descriptor
	if (free != desc->bg_free_blocks_count) {
		diff = abs(desc->bg_free_blocks_count - free);
		printf("Fixed: block group's free block counter was off by %d compared to the bitmap\n",
					diff);
		desc->bg_free_blocks_count = free;
		errors += diff;
	}
	// Reset free for the inode bitmap, loop through.
	free = sb->s_inodes_count;
	for (i = 0; i < sb->s_inodes_count; i++) {
		if (check_node(i, imap)) free--;
	}
	// Check free versus the counts in sb and desc.
	// Inode bitmap vs superblock
	if (free != sb->s_free_inodes_count) {
		diff = abs(sb->s_free_inodes_count - free);
		printf("Fixed: superblock's free inode counter was off by %d compared to the bitmap\n",
					diff);
		sb->s_free_inodes_count = free;
		errors += diff;
	}
	// Inode bitmap vs group desc
	if (free != desc->bg_free_inodes_count) {
		diff = abs(desc->bg_free_inodes_count - free);
		printf("Fixed: block group's free inode counter was off by %d compared to the bitmap\n",
					diff);
		desc->bg_free_inodes_count = free;
		errors += diff;
	}

	// Check each directory entry for matching file type with its inode.
	// Straight from readimage to get directory blocks.
	struct ext2_inode *curinode;
	struct ext2_inode *file_node;
	for (i = 0; i < sb->s_inodes_count; i++) {
		if ((check_node(i, imap) && (i == 1 || i >= 11)) || i == 1) {
			curinode = (struct ext2_inode *)((disk + 1024 * desc->bg_inode_table) + (sb->s_inode_size * i));
			if (get_inode_type(curinode) == 'd') {
				// Looping through blocks to find ext2_dir_entry details
				unsigned int cur_rec_len;
				unsigned char file_type;
				struct ext2_dir_entry *curdir;
				int x; // Need some new loop integer since i is already in use.
				for (x = 0; curinode->i_block[x] != 0; x++) {
					for (cur_rec_len = 0; cur_rec_len < 1024; ) {
						curdir = (struct ext2_dir_entry *)(disk + (1024 * curinode->i_block[x]) + cur_rec_len);
						file_type = get_dir_type(curdir->file_type);
						file_node = (struct ext2_inode *)((disk + 1024 * desc->bg_inode_table) +
															(sb->s_inode_size * (curdir->inode-1)));
						cur_rec_len += curdir->rec_len;
						if (file_type != get_inode_type(file_node)) {
							printf("Fixed: Entry type vs inode mismatch: inode %d\n", curdir->inode);
							errors++;
							set_dir_type(curdir, get_inode_type(file_node));
						}

						// Check that the directory's inode is allocated
						if (!check_node(curdir->inode - 1, imap)) { // Inode is not allocated
							errors++;
							printf("Fixed: inode %d not marked as in-use\n", curdir->inode);
							set_node(curdir->inode-1, imap);
							adjust_free_inodes(-1, sb, desc);
						}

						// Check inodes i_dtime to be 0
						if (file_node->i_dtime != 0) {
							errors++;
							printf("Fixed: valid inode marked for deletion: %d\n", curdir->inode);
							file_node->i_dtime = 0;
						}

						// Check the directory's data blocks for allocation
						int y; // Another random counter...
						int block_counter = 0; // Counting amount of blocks not allocated.
						for (y = 0; file_node->i_block[y] != 0; y++) {
							if (!check_node(file_node->i_block[y] - 1, map)) {
								block_counter++;
								set_node(file_node->i_block[y] - 1, map);
								adjust_free_blocks(-1, sb, desc);
							}
						}
						if (block_counter > 0) {
							errors++;
							printf("Fixed: %d in-use data blocks not marked in data bitmap for inode: %d\n",
									block_counter, curdir->inode);
						}	
					}
				}
			}
		}
	}

	// Output final message
	if (errors > 0) {
		printf("%d file system inconsistencies repaired!\n", errors);
	} else {
		printf("No file system inconsistencies detected!\n");
	}
		
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
cmpl $0x2, %edi
jne 0x1db1
movq 0x8(%rbx), %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x10d0
testl %eax, %eax
je 0x1db9
xorl %r12d, %r12d
movl $0x20000, %esi          # imm = 0x20000
xorl %edi, %edi
movl $0x3, %edx
movl $0x1, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x1070
movq %rax, 0x2ac8(%rip)      # 0x40a8
cmpq $-0x1, %rax
je 0x1dc5
movq %rax, %r13
addq $0x400, %rax            # imm = 0x400
movq %rax, 0x2ab6(%rip)      # 0x40b0
leaq 0x800(%r13), %rcx
movq %rcx, 0x2ab0(%rip)      # 0x40b8
movl 0x800(%r13), %r14d
shll $0xa, %r14d
addq %r13, %r14
movl 0x804(%r13), %ebx
movl 0x404(%r13), %esi
testl %esi, %esi
je 0x17b9
leal 0x3(%rsi), %edx
andl $-0x4, %edx
movd %esi, %xmm11
decl %esi
movd %esi, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa 0x9c6(%rip), %xmm1      # 0x2010
xorl %esi, %esi
movdqa 0x9cc(%rip), %xmm2      # 0x2020
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
pxor %xmm4, %xmm4
movdqa 0x9c8(%rip), %xmm5      # 0x2030
movdqa 0x9d0(%rip), %xmm7      # 0x2040
movdqa 0x9d7(%rip), %xmm9      # 0x2050
movdqa %xmm11, %xmm8
movdqa %xmm1, %xmm6
pxor %xmm2, %xmm6
pcmpgtd %xmm0, %xmm6
movd %xmm6, %edi
notl %edi
testb $0x1, %dil
je 0x16a5
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r14,%rdi), %edi
movd %edi, %xmm10
movdqa %xmm6, %xmm11
pxor %xmm3, %xmm11
pextrw $0x2, %xmm11, %edi
testb $0x1, %dil
je 0x16ef
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r14,%rdi), %edi
shll $0x8, %edi
movd %xmm10, %r8d
movzbl %r8b, %r9d
orl %edi, %r9d
movl %r8d, %edi
andl $0xff0000, %edi         # imm = 0xFF0000
orl %r9d, %edi
andl $0xff000000, %r8d       # imm = 0xFF000000
orl %edi, %r8d
movd %r8d, %xmm10
pextrw $0x4, %xmm11, %edi
testb $0x1, %dil
je 0x1723
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r14,%rdi), %edi
shll $0x10, %edi
movd %xmm10, %r8d
movzwl %r8w, %r9d
orl %edi, %r9d
andl $0xff000000, %r8d       # imm = 0xFF000000
orl %r9d, %r8d
movd %r8d, %xmm10
pextrw $0x6, %xmm11, %edi
testb $0x1, %dil
je 0x1750
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r14,%rdi), %edi
shll $0x18, %edi
movd %xmm10, %r8d
andl $0xffffff, %r8d         # imm = 0xFFFFFF
orl %edi, %r8d
movd %r8d, %xmm10
punpcklbw %xmm4, %xmm10   # xmm10 = xmm10[0],xmm4[0],xmm10[1],xmm4[1],xmm10[2],xmm4[2],xmm10[3],xmm4[3],xmm10[4],xmm4[4],xmm10[5],xmm4[5],xmm10[6],xmm4[6],xmm10[7],xmm4[7]
punpcklwd %xmm4, %xmm10   # xmm10 = xmm10[0],xmm4[0],xmm10[1],xmm4[1],xmm10[2],xmm4[2],xmm10[3],xmm4[3]
movdqa %xmm1, %xmm11
pslld $0x17, %xmm11
pand %xmm5, %xmm11
paddd %xmm7, %xmm11
cvttps2dq %xmm11, %xmm11
pand %xmm10, %xmm11
pcmpgtd %xmm4, %xmm11
paddd %xmm8, %xmm11
addl $0x4, %esi
paddd %xmm9, %xmm1
cmpl %esi, %edx
jne 0x1679
pand %xmm6, %xmm8
pandn %xmm11, %xmm6
por %xmm8, %xmm6
pshufd $0xee, %xmm6, %xmm0     # xmm0 = xmm6[2,3,2,3]
paddd %xmm6, %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
paddd %xmm0, %xmm1
movd %xmm1, %r12d
shll $0xa, %ebx
movl 0x40c(%r13), %edx
xorl %ebp, %ebp
subl %r12d, %edx
je 0x17f3
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
leaq 0x8d0(%rip), %rdi       # 0x20a8
movl %esi, %ebp
xorl %eax, %eax
callq 0x1080
movq 0x28c8(%rip), %rax      # 0x40b0
movl %r12d, 0xc(%rax)
movq 0x28c5(%rip), %rcx      # 0x40b8
movzwl 0xc(%rcx), %edx
subl %r12d, %edx
jne 0x1801
movl %ebp, %r12d
jmp 0x1835
movl %edx, %r15d
negl %r15d
cmovsl %edx, %r15d
leaq 0x8e3(%rip), %rdi       # 0x20f5
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movq 0x2895(%rip), %rcx      # 0x40b8
movw %r12w, 0xc(%rcx)
movl %ebp, %r12d
addl %r15d, %r12d
movq 0x287b(%rip), %rax      # 0x40b0
addq %rbx, %r13
movl (%rax), %esi
testl %esi, %esi
je 0x19d4
leal 0x3(%rsi), %edx
andl $-0x4, %edx
movd %esi, %xmm11
decl %esi
movd %esi, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa 0x7b0(%rip), %xmm1      # 0x2010
xorl %esi, %esi
movdqa 0x7b6(%rip), %xmm2      # 0x2020
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
pxor %xmm4, %xmm4
movdqa 0x7b2(%rip), %xmm5      # 0x2030
movdqa 0x7ba(%rip), %xmm7      # 0x2040
movdqa 0x7c1(%rip), %xmm9      # 0x2050
movdqa %xmm11, %xmm8
movdqa %xmm1, %xmm6
pxor %xmm2, %xmm6
pcmpgtd %xmm0, %xmm6
movd %xmm6, %edi
notl %edi
testb $0x1, %dil
je 0x18bc
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r13,%rdi), %edi
movd %edi, %xmm10
movdqa %xmm6, %xmm11
pxor %xmm3, %xmm11
pextrw $0x2, %xmm11, %edi
testb $0x1, %dil
je 0x1907
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r13,%rdi), %edi
shll $0x8, %edi
movd %xmm10, %r8d
movzbl %r8b, %r9d
orl %edi, %r9d
movl %r8d, %edi
andl $0xff0000, %edi         # imm = 0xFF0000
orl %r9d, %edi
andl $0xff000000, %r8d       # imm = 0xFF000000
orl %edi, %r8d
movd %r8d, %xmm10
pextrw $0x4, %xmm11, %edi
testb $0x1, %dil
je 0x193c
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r13,%rdi), %edi
shll $0x10, %edi
movd %xmm10, %r8d
movzwl %r8w, %r9d
orl %edi, %r9d
andl $0xff000000, %r8d       # imm = 0xFF000000
orl %r9d, %r8d
movd %r8d, %xmm10
pextrw $0x6, %xmm11, %edi
testb $0x1, %dil
je 0x196a
movl %esi, %edi
shrl $0x3, %edi
movzbl (%r13,%rdi), %edi
shll $0x18, %edi
movd %xmm10, %r8d
andl $0xffffff, %r8d         # imm = 0xFFFFFF
orl %edi, %r8d
movd %r8d, %xmm10
punpcklbw %xmm4, %xmm10   # xmm10 = xmm10[0],xmm4[0],xmm10[1],xmm4[1],xmm10[2],xmm4[2],xmm10[3],xmm4[3],xmm10[4],xmm4[4],xmm10[5],xmm4[5],xmm10[6],xmm4[6],xmm10[7],xmm4[7]
punpcklwd %xmm4, %xmm10   # xmm10 = xmm10[0],xmm4[0],xmm10[1],xmm4[1],xmm10[2],xmm4[2],xmm10[3],xmm4[3]
movdqa %xmm1, %xmm11
pslld $0x17, %xmm11
pand %xmm5, %xmm11
paddd %xmm7, %xmm11
cvttps2dq %xmm11, %xmm11
pand %xmm10, %xmm11
pcmpgtd %xmm4, %xmm11
paddd %xmm8, %xmm11
addl $0x4, %esi
paddd %xmm9, %xmm1
cmpl %esi, %edx
jne 0x188f
pand %xmm6, %xmm8
pandn %xmm11, %xmm6
por %xmm8, %xmm6
pshufd $0xee, %xmm6, %xmm0     # xmm0 = xmm6[2,3,2,3]
paddd %xmm6, %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
paddd %xmm0, %xmm1
movd %xmm1, %ebx
jmp 0x19d6
xorl %ebx, %ebx
movl 0x10(%rax), %edx
subl %ebx, %edx
je 0x1a0c
movl %edx, %r15d
negl %r15d
cmovsl %edx, %r15d
leaq 0x755(%rip), %rdi       # 0x2143
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movq 0x26b1(%rip), %rax      # 0x40b0
movl %ebx, 0x10(%rax)
addl %r15d, %r12d
movq 0x26ac(%rip), %rcx      # 0x40b8
movzwl 0xe(%rcx), %ecx
subl %ebx, %ecx
je 0x1a44
movl %ecx, %r15d
negl %r15d
cmovsl %ecx, %r15d
leaq 0x76b(%rip), %rdi       # 0x2190
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movq 0x2682(%rip), %rax      # 0x40b8
movw %bx, 0xe(%rax)
addl %r15d, %r12d
movq 0x266c(%rip), %rax      # 0x40b0
movl (%rax), %ecx
testl %ecx, %ecx
je 0x1d7c
xorl %edi, %edi
movq %r13, 0x18(%rsp)
movl %edi, %edx
shrl $0x3, %edx
movzbl (%r13,%rdx), %edx
movl %edi, %esi
andl $0x7, %esi
btl %esi, %edx
jae 0x1a81
cmpl $0x1, %edi
sete %dl
cmpl $0xb, %edi
setae %sil
orb %dl, %sil
jne 0x1a8a
jmp 0x1d72
cmpl $0x1, %edi
jne 0x1d72
movq 0x2627(%rip), %rdx      # 0x40b8
movl 0x8(%rdx), %r8d
shll $0xa, %r8d
addq 0x2608(%rip), %r8       # 0x40a8
movzwl 0x58(%rax), %esi
movl %edi, %edx
imulq %rsi, %rdx
movzwl (%rdx,%r8), %esi
andl $0xf000, %esi           # imm = 0xF000
cmpl $0x4000, %esi           # imm = 0x4000
jne 0x1d72
addq %rdx, %r8
cmpl $0x0, 0x28(%r8)
je 0x1d72
movl %edi, 0xc(%rsp)
addq $0x28, %r8
xorl %eax, %eax
movq %r8, 0x20(%rsp)
movq %r8, 0x28(%rsp)
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
movq 0x25b6(%rip), %rsi      # 0x40a8
movq 0x20(%rsp), %rax
movl (%rax), %r15d
shll $0xa, %r15d
addq %rsi, %r15
movl %r13d, %edi
movzbl 0x7(%rdi,%r15), %eax
movl %eax, %ecx
shll $0x3, %ecx
movabsq $0x6c3f3f3f3f64663f, %rdx # imm = 0x6C3F3F3F3F64663F
shrq %cl, %rdx
cmpb $0x8, %al
movl $0x3f, %eax
cmovael %eax, %edx
movq 0x258b(%rip), %rax      # 0x40b8
movl 0x8(%rax), %eax
shll $0xa, %eax
movq %rsi, 0x40(%rsp)
movq %rax, 0x38(%rsp)
leaq (%rsi,%rax), %rbx
movq 0x2568(%rip), %rax      # 0x40b0
movzwl 0x58(%rax), %ebp
movl (%rdi,%r15), %esi
leal -0x1(%rsi), %eax
imull %eax, %ebp
movzwl (%rbp,%rbx), %ecx
andl $0xf000, %ecx           # imm = 0xF000
cmpl $0xa000, %ecx           # imm = 0xA000
je 0x1b81
cmpl $0x8000, %ecx           # imm = 0x8000
je 0x1b7d
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x1b85
movb $0x64, %cl
jmp 0x1b87
movb $0x66, %cl
jmp 0x1b87
movb $0x6c, %cl
jmp 0x1b87
movb $0x3f, %cl
movzwl 0x4(%rdi,%r15), %r8d
movl %r8d, 0x10(%rsp)
cmpb %cl, %dl
movq %rdi, (%rsp)
movl %r13d, 0x14(%rsp)
jne 0x1ba4
movl %r12d, %r13d
jmp 0x1bf8
leaq 0x633(%rip), %rdi       # 0x21de
xorl %eax, %eax
callq 0x1080
movzwl (%rbx,%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
je 0x1bdc
cmpl $0xa000, %eax           # imm = 0xA000
je 0x1bd8
cmpl $0x8000, %eax           # imm = 0x8000
movq (%rsp), %rdi
jne 0x1be4
movb $0x1, %al
jmp 0x1be6
movb $0x7, %al
jmp 0x1bde
movb $0x2, %al
movq (%rsp), %rdi
jmp 0x1be6
xorl %eax, %eax
incl %r12d
movl %r12d, %r13d
movb %al, 0x7(%r15,%rdi)
movl (%r15,%rdi), %esi
leal -0x1(%rsi), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movq 0x18(%rsp), %r12
movzbl (%r12,%rcx), %ecx
andl $0x7, %eax
btl %eax, %ecx
jb 0x1c66
incl %r13d
leaq 0x5eb(%rip), %rdi       # 0x220d
xorl %eax, %eax
callq 0x1080
movq (%rsp), %rdi
movl (%r15,%rdi), %eax
leal -0x1(%rax), %edx
movl %edx, %ecx
andb $0x7, %cl
movl $0x1, %esi
shll %cl, %esi
addl $0x6, %eax
testl %edx, %edx
cmovnsl %edx, %eax
sarl $0x3, %eax
cltq
xorb %sil, (%r12,%rax)
movq 0x2458(%rip), %rax      # 0x40b0
movq 0x2459(%rip), %rcx      # 0x40b8
decl 0x10(%rax)
decw 0xe(%rcx)
cmpl $0x0, 0x14(%rbx,%rbp)
je 0x1c8f
movl %r13d, %r12d
incl %r12d
movl (%r15,%rdi), %esi
leaq 0x5b5(%rip), %rdi       # 0x2233
xorl %eax, %eax
callq 0x1080
movl $0x0, 0x14(%rbx,%rbp)
jmp 0x1c92
movl %r13d, %r12d
movl 0x28(%rbx,%rbp), %edx
testl %edx, %edx
movl 0x14(%rsp), %r13d
je 0x1d2b
addq 0x38(%rsp), %rbp
movq 0x40(%rsp), %rax
addq %rbp, %rax
addq $0x2c, %rax
xorl %esi, %esi
leal -0x1(%rdx), %r8d
addl $0x6, %edx
testl %r8d, %r8d
cmovnsl %r8d, %edx
sarl $0x3, %edx
movl %r8d, %ecx
andb $0x7, %cl
movl $0x1, %edi
shll %cl, %edi
movslq %edx, %rcx
movzbl (%r14,%rcx), %edx
andl $0x7, %r8d
btl %r8d, %edx
jb 0x1d04
xorb %dl, %dil
movb %dil, (%r14,%rcx)
movq 0x23bc(%rip), %rcx      # 0x40b0
movq 0x23bd(%rip), %rdx      # 0x40b8
decl 0xc(%rcx)
incl %esi
decw 0xc(%rdx)
movl (%rax), %edx
addq $0x4, %rax
testl %edx, %edx
jne 0x1cb6
testl %esi, %esi
movq (%rsp), %rax
jle 0x1d2b
incl %r12d
movl (%r15,%rax), %edx
leaq 0x53b(%rip), %rdi       # 0x225f
xorl %eax, %eax
callq 0x1080
addl 0x10(%rsp), %r13d
cmpl $0x400, %r13d           # imm = 0x400
jb 0x1aeb
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %rax
leaq (%r8,%rax,4), %rcx
addq $0x4, %rcx
incq %rax
movq %rcx, 0x20(%rsp)
cmpl $0x0, (%rcx)
jne 0x1ae3
movq 0x2349(%rip), %rax      # 0x40b0
movl (%rax), %ecx
movq 0x18(%rsp), %r13
movl 0xc(%rsp), %edi
incl %edi
cmpl %ecx, %edi
jb 0x1a55
testl %r12d, %r12d
jle 0x1d94
leaq 0x51d(%rip), %rdi       # 0x22a5
movl %r12d, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x1da0
leaq 0x534(%rip), %rdi       # 0x22cf
callq 0x1060
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1155
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x1191
callq 0x117c