// File: hyp1231[P]FMSS/generate_disk.cpp
// Function: main
int main() {
    ofstream ofile("./diskdata");				// create a new file

    // super block
    short basic_size = 1024;					// basic size of a block
    ofile.write((char*)&basic_size, sizeof(basic_size));

    char tmp = 0;

    // inode number of '/'
    ofile.write((char*)&tmp, sizeof(tmp));

    // inode bitmap[0] = 1
    tmp = 1;
    ofile.write((char*)&tmp, sizeof(tmp));
    tmp = 0;
    for(int i = 0; i < 9; ++i) {
    	ofile.write((char*)&tmp, sizeof(tmp));
    }

    // data block bitmap[0] = 1
    tmp = 1;
    ofile.write((char*)&tmp, sizeof(tmp));
    tmp = 0;

    // rest of super block
    for(int i = 0; i < 1024 - 2 - 1 - 10 - 1; ++i) {
	    ofile.write((char*)&tmp, sizeof(tmp));	// fill the file with '\0'
	}

	// first inode
	short num = 1;
	ofile.write((char*)&num, sizeof(num));
	tmp = '/';
	ofile.write((char*)&tmp, sizeof(tmp));
	tmp = 0;
	for(int i = 0; i < 7; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}
	
	// rest of inode table
	for(int i = 0; i < 5 * 1024 - 10; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}

	// first data block
	tmp = '.';
	ofile.write((char*)&tmp, sizeof(tmp));
	tmp = 0;
	for(int i = 0; i < 7; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}

	ofile.write((char*)&num, sizeof(num));

	for(int i = 0; i < 2; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}
	tmp = '.';
	for(int i = 0; i < 2; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}
	tmp = 0;
	for(int i = 0; i < 6; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}

	ofile.write((char*)&num, sizeof(num));

	// rest of data block
	for(int i = 0; i < 1024 - 12 - 10 + (1024 - 7) * 1024; ++i) {
		ofile.write((char*)&tmp, sizeof(tmp));
	}

	ofile.close();

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movl $0x0, -0x4(%rbp)
leaq 0xe0b(%rip), %rsi       # 0x2004
leaq -0x208(%rbp), %rdi
movq %rdi, -0x250(%rbp)
movl $0x10, %edx
callq 0x1040
movq -0x250(%rbp), %rdi
movw $0x400, -0x20a(%rbp)    # imm = 0x400
leaq -0x20a(%rbp), %rsi
movl $0x2, %edx
callq 0x1050
jmp 0x1234
movb $0x0, -0x21d(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x1255
movb $0x1, -0x21d(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x1276
movb $0x0, -0x21d(%rbp)
movl $0x0, -0x224(%rbp)
cmpl $0x9, -0x224(%rbp)
jge 0x12e0
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x12aa
jmp 0x12ac
movl -0x224(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x224(%rbp)
jmp 0x1287
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x1070
jmp 0x15f3
movb $0x1, -0x21d(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x1301
movb $0x0, -0x21d(%rbp)
movl $0x0, -0x228(%rbp)
cmpl $0x3f2, -0x228(%rbp)    # imm = 0x3F2
jge 0x134b
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x1338
jmp 0x133a
movl -0x228(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x228(%rbp)
jmp 0x1312
movw $0x1, -0x22a(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x22a(%rbp), %rsi
movl $0x2, %edx
callq 0x1050
jmp 0x136e
movb $0x2f, -0x21d(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x138f
movb $0x0, -0x21d(%rbp)
movl $0x0, -0x230(%rbp)
cmpl $0x7, -0x230(%rbp)
jge 0x13d6
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x13c3
jmp 0x13c5
movl -0x230(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x230(%rbp)
jmp 0x13a0
movl $0x0, -0x234(%rbp)
cmpl $0x13f6, -0x234(%rbp)   # imm = 0x13F6
jge 0x1419
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x1406
jmp 0x1408
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
jmp 0x13e0
movb $0x2e, -0x21d(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x143a
movb $0x0, -0x21d(%rbp)
movl $0x0, -0x238(%rbp)
cmpl $0x7, -0x238(%rbp)
jge 0x1481
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x146e
jmp 0x1470
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x144b
leaq -0x208(%rbp), %rdi
leaq -0x22a(%rbp), %rsi
movl $0x2, %edx
callq 0x1050
jmp 0x149b
movl $0x0, -0x23c(%rbp)
cmpl $0x2, -0x23c(%rbp)
jge 0x14db
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x14c8
jmp 0x14ca
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x14a5
movb $0x2e, -0x21d(%rbp)
movl $0x0, -0x240(%rbp)
cmpl $0x2, -0x240(%rbp)
jge 0x1522
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x150f
jmp 0x1511
movl -0x240(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x240(%rbp)
jmp 0x14ec
movb $0x0, -0x21d(%rbp)
movl $0x0, -0x244(%rbp)
cmpl $0x6, -0x244(%rbp)
jge 0x1569
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x1556
jmp 0x1558
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x1533
leaq -0x208(%rbp), %rdi
leaq -0x22a(%rbp), %rsi
movl $0x2, %edx
callq 0x1050
jmp 0x1583
movl $0x0, -0x248(%rbp)
cmpl $0xfe7ea, -0x248(%rbp)  # imm = 0xFE7EA
jge 0x15c6
leaq -0x208(%rbp), %rdi
leaq -0x21d(%rbp), %rsi
movl $0x1, %edx
callq 0x1050
jmp 0x15b3
jmp 0x15b5
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x158d
leaq -0x208(%rbp), %rdi
callq 0x1060
jmp 0x15d4
movl $0x0, -0x4(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x1070
movl -0x4(%rbp), %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
movq -0x218(%rbp), %rdi
callq 0x1090