// File: /workspace/github_c_makefile_star2_O0/kevinp89[P]Operating-System-EXT2-file-system-with-commands/ext2_mkdir.c
// Function: main
int main(int argc, char **argv) {
	// We need two arguments, so argc must be 3.
	if (argc != 3) {
		fprintf(stderr, "Usage: %s [disk] [path]\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);
	// Getting the parent inode index
	int parent_inode_index = check_parent(disk, argv[2]);
	if (parent_inode_index == -1) { // Directory not found.
		fprintf(stderr, "Directory does not exist.");
		exit(ENOENT);
	}
	// Get new dir name
	int i;
	int dir_len = 0;
	if (argv[2][strlen(argv[2]) -1] == '/') argv[2][strlen(argv[2])-1] = '\0';
	for (i = strlen(argv[2]); argv[2][i] != '/'; i--) {
		dir_len++;
		if (dir_len > 255) {
			fprintf(stderr, "Directory name too large.");
			exit(1);
		}
	}
	char new_dir[dir_len];
	strcpy(new_dir, argv[2] + i + 1);
	// Check that there aren't any files with that name.
	struct ext2_inode *parent = (struct ext2_inode *)((disk + 1024 * desc->bg_inode_table) +
		   											(sb->s_inode_size * parent_inode_index));
	if (search_directories(disk, parent, new_dir, 0) != -1) {
		fprintf(stderr, "Directory name already in use.\n");
		exit(EEXIST);
	}
	// Finding a free inode and allocating (set to 1)
	unsigned char *imap = (unsigned char *)(disk + 1024 * desc->bg_inode_bitmap);
	int inode;
	for (inode = 11; inode < sb->s_inodes_count; inode++) {
		if (check_node(inode, imap) == 0) {
			break;
		}
	}
	if (inode == sb->s_inodes_count) { // Maximum reached, no more inodes
		fprintf(stderr, "No more inodes available.");
		exit(1);
	}
	// Finding a free block and allocating (set to 1)
	unsigned char *bmap = (unsigned char *)(disk + 1024 * desc->bg_block_bitmap);
	int bnode;
	for (bnode = 22; bnode < sb->s_blocks_count; bnode++) {
		if (check_node(bnode, bmap) == 0) {
			break;
		}
	}
	if (bnode == sb->s_blocks_count) {
		fprintf(stderr, "No more blocks available.");
		exit(1);
	}
	// Actual allocation.
	set_node(inode, imap);
	set_node(bnode, bmap);
	adjust_free_blocks(-1, sb, desc);
	adjust_free_inodes(-1, sb, desc);
	// Writing data to the ext2_inode struct in the inode index.
	struct ext2_inode *new_inode = (struct ext2_inode *)((disk + 1024 * desc->bg_inode_table)
														 + (sb->s_inode_size * (inode)));
	new_inode->i_mode = EXT2_S_IFDIR;
	new_inode->i_uid = 0;
	new_inode->i_size = 1024;
	new_inode->i_ctime = (unsigned int) time(0);
	new_inode->i_dtime = 0;
	new_inode->i_gid = 0;
	new_inode->i_blocks = 2;
	new_inode->osd1 = 0;
	new_inode->i_block[0] = bnode;
	new_inode->i_generation = 0;
	new_inode->i_file_acl = 0;
	new_inode->i_dir_acl = 0;
	new_inode->i_faddr = 0;
	new_inode->i_links_count = 2; // Itself and from parent.
	parent->i_links_count++; // Parent gets one more link from parent dir in new directory.
	// Adding self and parent directories to allocated block.
	struct ext2_dir_entry *self = (struct ext2_dir_entry *)(disk + (1024 * bnode));
	self->inode = inode + 1; // the variable inode is the index, not actual inode.
	self->rec_len = 12; // self rec-len is always 12
	self->name_len = 1; // length of . is 1
	self->file_type = EXT2_FT_DIR;
	strncpy(self->name, ".", 1);
	struct ext2_dir_entry *par = (struct ext2_dir_entry *)(disk + (1024 * bnode) + self->rec_len);
	par->inode = parent_inode_index + 1;
	par->rec_len = 1024 - 12; // Fill in the rest of the 1024 bytes of space
	par->name_len = 2; // length of .. is 2
	par->file_type = EXT2_FT_DIR;
	strncpy(par->name, "..", 2);
	// Adding new inode/directory entry into the parent block.
	int par_block_index = 0;
	for (i = 0; parent->i_block[i] != 0; i++) {
		par_block_index = parent->i_block[i];
	}
	int total_rec_len;
	struct ext2_dir_entry *curdir = (struct ext2_dir_entry *)(disk + (1024 * par_block_index));
	// When this for loop exits, curdir should be the last directory 
	for (total_rec_len = 0; total_rec_len + curdir->rec_len < 1024; ) {
		total_rec_len += curdir->rec_len;
		curdir = (struct ext2_dir_entry *)(disk + (1024 * par_block_index) + total_rec_len);
	}
	// Check there's enough space to place the new dir entry in the current block
	// Reuse total_rec_len to find remaining bytes if curdir was reduced to proper size
	struct ext2_dir_entry *newdir;
	int remaining_rec_len = sizeof(curdir) + curdir->name_len; // Actual size of curdir
	remaining_rec_len += 4 - (remaining_rec_len % 4); // Add padding
	remaining_rec_len = 1024 - remaining_rec_len - total_rec_len; // Remaining space
	if (remaining_rec_len < (8 + strlen(new_dir))) { // Not enough space
		// Allocate new block
		int newblock;
		for (newblock = 22; newblock < sb->s_blocks_count; newblock++) {
			if (check_node(newblock, bmap) == 0) {
				break;
			}
		}
		if (newblock == sb->s_blocks_count) {
			fprintf(stderr, "No more blocks available.");
			exit(1);
		}
		set_node(newblock, bmap);
		adjust_free_blocks(-1, sb, desc);
		parent->i_block[i] = newblock; // i should still hold the first block space unused by parent
		parent->i_blocks += 2; // One more block being added
		newdir = (struct ext2_dir_entry *)(disk + (1024 * newblock));
		newdir->rec_len = 1024; // Takes up the whole of the new block.
	} else { // Enough space
		// Change curdir, add new directory
		curdir->rec_len = sizeof(curdir) + curdir->name_len;
		curdir->rec_len += 4 - (curdir->rec_len % 4);
		total_rec_len += curdir->rec_len;
		newdir = (struct ext2_dir_entry *)(disk + (1024 * par_block_index) + total_rec_len);
		newdir->rec_len = 1024 - total_rec_len; // Takes up the rest of the block.
	}
	newdir->inode = inode + 1;
	newdir->name_len = strlen(new_dir);
	newdir->file_type = EXT2_FT_DIR;
	strncpy(newdir->name, new_dir, newdir->name_len);

	// Done with the directories, minor upkeep
	desc->bg_used_dirs_count++;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x1798
movq 0x3882(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x1893(%rip), %rsi      # 0x301a
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x10f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x10d0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x17df
movq 0x383c(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x1865(%rip), %rsi      # 0x3033
movb $0x0, %al
callq 0x10a0
movl $0x2, %edi
callq 0x10f0
movl -0x14(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x20000, %esi          # imm = 0x20000
movl $0x3, %edx
movl $0x1, %ecx
movq %r9, %rdi
callq 0x1070
movq %rax, 0x389a(%rip)      # 0x50a0
movq $-0x1, %rax
cmpq %rax, 0x388c(%rip)      # 0x50a0
jne 0x182c
leaq 0x1831(%rip), %rdi      # 0x304e
callq 0x10e0
movl $0x1, %edi
callq 0x10f0
movq 0x386d(%rip), %rax      # 0x50a0
addq $0x400, %rax            # imm = 0x400
movq %rax, 0x3868(%rip)      # 0x50a8
movq 0x3859(%rip), %rax      # 0x50a0
addq $0x800, %rax            # imm = 0x800
movq %rax, 0x385c(%rip)      # 0x50b0
movq 0x3845(%rip), %rdi      # 0x50a0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x1510
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x1893
movq 0x3780(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x17d1(%rip), %rsi      # 0x3053
movb $0x0, %al
callq 0x10a0
movl $0x2, %edi
callq 0x10f0
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1060
movq %rax, %rcx
movq -0x98(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x18fb
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1060
movq %rax, %rcx
movq -0xa0(%rbp), %rax
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1060
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0x1961
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0xff, -0x20(%rbp)
jle 0x1954
movq 0x36bf(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x172a(%rip), %rsi      # 0x306d
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x10f0
jmp 0x1956
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x190b
movl -0x20(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x28(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0xa8(%rbp)
movq %rdi, %rsp
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0x1c(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
callq 0x1050
movq -0xa8(%rbp), %rdx
movq 0x36f0(%rip), %rax      # 0x50a0
movq 0x36f9(%rip), %rcx      # 0x50b0
movl 0x8(%rcx), %ecx
shll $0xa, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq 0x36df(%rip), %rcx      # 0x50a8
movzwl 0x58(%rcx), %ecx
imull -0x18(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq 0x36be(%rip), %rdi      # 0x50a0
movq -0x38(%rbp), %rsi
xorl %ecx, %ecx
callq 0x13c0
cmpl $-0x1, %eax
je 0x1a14
movq 0x35ff(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1684(%rip), %rsi      # 0x3087
movb $0x0, %al
callq 0x10a0
movl $0x11, %edi
callq 0x10f0
movq 0x3685(%rip), %rax      # 0x50a0
movq 0x368e(%rip), %rcx      # 0x50b0
movl 0x4(%rcx), %ecx
shll $0xa, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0xb, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq 0x3666(%rip), %rcx      # 0x50a8
cmpl (%rcx), %eax
jae 0x1a66
movl -0x44(%rbp), %edi
movq -0x40(%rbp), %rsi
callq 0x1210
cmpl $0x0, %eax
jne 0x1a59
jmp 0x1a66
jmp 0x1a5b
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1a38
movl -0x44(%rbp), %eax
movq 0x3638(%rip), %rcx      # 0x50a8
cmpl (%rcx), %eax
jne 0x1a96
movq 0x357d(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1622(%rip), %rsi      # 0x30a7
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x10f0
movq 0x3603(%rip), %rax      # 0x50a0
movq 0x360c(%rip), %rcx      # 0x50b0
movl (%rcx), %ecx
shll $0xa, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x16, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq 0x35e5(%rip), %rcx      # 0x50a8
cmpl 0x4(%rcx), %eax
jae 0x1ae8
movl -0x54(%rbp), %edi
movq -0x50(%rbp), %rsi
callq 0x1210
cmpl $0x0, %eax
jne 0x1adb
jmp 0x1ae8
jmp 0x1add
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1ab9
movl -0x54(%rbp), %eax
movq 0x35b6(%rip), %rcx      # 0x50a8
cmpl 0x4(%rcx), %eax
jne 0x1b19
movq 0x34fa(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x15b9(%rip), %rsi      # 0x30c1
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x10f0
movl -0x44(%rbp), %edi
movq -0x40(%rbp), %rsi
callq 0x1260
movl -0x54(%rbp), %edi
movq -0x50(%rbp), %rsi
callq 0x1260
movq 0x3570(%rip), %rsi      # 0x50a8
movq 0x3571(%rip), %rdx      # 0x50b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x16f0
movq 0x3558(%rip), %rsi      # 0x50a8
movq 0x3559(%rip), %rdx      # 0x50b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1720
movq 0x3538(%rip), %rax      # 0x50a0
movq 0x3541(%rip), %rcx      # 0x50b0
movl 0x8(%rcx), %ecx
shll $0xa, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq 0x3527(%rip), %rcx      # 0x50a8
movzwl 0x58(%rcx), %ecx
imull -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movw $0x4000, (%rax)         # imm = 0x4000
movq -0x60(%rbp), %rax
movw $0x0, 0x2(%rax)
movq -0x60(%rbp), %rax
movl $0x400, 0x4(%rax)       # imm = 0x400
xorl %eax, %eax
movl %eax, %edi
callq 0x10b0
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x60(%rbp), %rax
movw $0x0, 0x18(%rax)
movq -0x60(%rbp), %rax
movl $0x2, 0x1c(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x24(%rax)
movl -0x54(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x64(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x68(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x6c(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x70(%rax)
movq -0x60(%rbp), %rax
movw $0x2, 0x1a(%rax)
movq -0x38(%rbp), %rax
movw 0x1a(%rax), %cx
addw $0x1, %cx
movw %cx, 0x1a(%rax)
movq 0x345b(%rip), %rax      # 0x50a0
movl -0x54(%rbp), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movq -0x68(%rbp), %rax
movw $0xc, 0x4(%rax)
movq -0x68(%rbp), %rax
movb $0x1, 0x6(%rax)
movq -0x68(%rbp), %rax
movb $0x2, 0x7(%rax)
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
leaq 0x1452(%rip), %rsi      # 0x30dc
movl $0x1, %edx
callq 0x1040
movq 0x3405(%rip), %rax      # 0x50a0
movl -0x54(%rbp), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x68(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movw $0x3f4, 0x4(%rax)       # imm = 0x3F4
movq -0x70(%rbp), %rax
movb $0x2, 0x6(%rax)
movq -0x70(%rbp), %rax
movb $0x2, 0x7(%rax)
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
leaq 0x13ed(%rip), %rsi      # 0x30db
movl $0x2, %edx
callq 0x1040
movl $0x0, -0x74(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpl $0x0, 0x28(%rax,%rcx,4)
je 0x1d2f
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl 0x28(%rax,%rcx,4), %eax
movl %eax, -0x74(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d06
movq 0x336a(%rip), %rax      # 0x50a0
movl -0x74(%rbp), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq -0x80(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
addl %ecx, %eax
cmpl $0x400, %eax            # imm = 0x400
jge 0x1d8f
movq -0x80(%rbp), %rax
movzwl 0x4(%rax), %eax
addl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
movq 0x332a(%rip), %rax      # 0x50a0
movl -0x74(%rbp), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
jmp 0x1d4d
movq -0xa8(%rbp), %rdi
movq -0x80(%rbp), %rax
movzbl 0x6(%rax), %eax
addq $0x8, %rax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl $0x4, %eax
subl %edx, %eax
addl -0x8c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl $0x400, %eax            # imm = 0x400
subl -0x8c(%rbp), %eax
subl -0x78(%rbp), %eax
movl %eax, -0x8c(%rbp)
movslq -0x8c(%rbp), %rax
movq %rax, -0xb0(%rbp)
callq 0x1060
movq %rax, %rcx
movq -0xb0(%rbp), %rax
addq $0x8, %rcx
cmpq %rcx, %rax
jae 0x1ef5
movl $0x16, -0x90(%rbp)
movl -0x90(%rbp), %eax
movq 0x328a(%rip), %rcx      # 0x50a8
cmpl 0x4(%rcx), %eax
jae 0x1e4c
movl -0x90(%rbp), %edi
movq -0x50(%rbp), %rsi
callq 0x1210
cmpl $0x0, %eax
jne 0x1e39
jmp 0x1e4c
jmp 0x1e3b
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x1e11
movl -0x90(%rbp), %eax
movq 0x324f(%rip), %rcx      # 0x50a8
cmpl 0x4(%rcx), %eax
jne 0x1e80
movq 0x3193(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1252(%rip), %rsi      # 0x30c1
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x10f0
movl -0x90(%rbp), %edi
movq -0x50(%rbp), %rsi
callq 0x1260
movq 0x3212(%rip), %rsi      # 0x50a8
movq 0x3213(%rip), %rdx      # 0x50b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x16f0
movl -0x90(%rbp), %edx
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, 0x28(%rax,%rcx,4)
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0x1c(%rax)
movq 0x31d3(%rip), %rax      # 0x50a0
movl -0x90(%rbp), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movw $0x400, 0x4(%rax)       # imm = 0x400
jmp 0x1f78
movq -0x80(%rbp), %rax
movzbl 0x6(%rax), %eax
addq $0x8, %rax
movw %ax, %cx
movq -0x80(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x80(%rbp), %rax
movzwl 0x4(%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl $0x4, %edx
subl %eax, %edx
movq -0x80(%rbp), %rax
movzwl 0x4(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x4(%rax)
movq -0x80(%rbp), %rax
movzwl 0x4(%rax), %eax
addl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
movq 0x3158(%rip), %rax      # 0x50a0
movl -0x74(%rbp), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movl $0x400, %eax            # imm = 0x400
subl -0x78(%rbp), %eax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0xa8(%rbp), %rdi
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movq -0x88(%rbp), %rax
movl %ecx, (%rax)
callq 0x1060
movq -0xa8(%rbp), %rsi
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x6(%rax)
movq -0x88(%rbp), %rax
movb $0x2, 0x7(%rax)
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
movq -0x88(%rbp), %rax
movzbl 0x6(%rax), %eax
movl %eax, %edx
callq 0x1040
movq 0x30db(%rip), %rax      # 0x50b0
movw 0x10(%rax), %cx
addw $0x1, %cx
movw %cx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq