// File: SYZYGYfpga[P]brain-tools/src/smartvio-brain.cpp
// Function: main
int main (int argc, char *argv[])
{
	// Options flags
	int rflag = 0;
	int sflag = 0;
	int jflag = 0;
	int hflag = 0;
	int wflag = 0;
	int dflag = 0;
	uint32_t svio1 = 0;
	uint32_t svio2 = 0;
	char i2c_filename[200];
	char dna_filename[200];
	uint8_t dna_buf[1320];
	int i2c_file;
	int dna_file;
	int dna_length = 0;
	int periph_num = 0;
	int curr_opt;
	json json_handler;
	uint16_t peripheral_address[] = {0x30, 0x31, 0x32, 0x33};

	// Parse args
	while ((curr_opt = getopt(argc, argv, "rsj1:2:w:d:p:h")) != -1) {
		switch(curr_opt)
		{
			case 'r':
				rflag = 1;
				break;
			case 's':
				sflag = 1;
				break;
			case 'j':
				jflag = 1;
				break;
			case '1':
				if (optarg){ 
					svio1 = atoi(optarg);
				} else {
					printf("No argument specified for -1\n");
					exit(EXIT_FAILURE);
				}
				break;
			case '2':
				if (optarg){ 
					svio2 = atoi(optarg);
				} else {
					printf("No argument specified for -2\n");
					exit(EXIT_FAILURE);
				}
				break;
			case 'w':
				wflag = 1;
				if (optarg){ 
					strcpy(dna_filename, optarg);
				} else {
					printf("No argument specified for -w\n");
					exit(EXIT_FAILURE);
				}
				break;
			case 'd':
				dflag = 1;
				if (optarg){ 
					strcpy(dna_filename, optarg);
				} else {
					printf("No argument specified for -d\n");
					exit(EXIT_FAILURE);
				}
				break;
			case 'p':
				if (optarg){ 
					periph_num = strtol(optarg, NULL, 0) - 1;
				} else {
					printf("No argument specified for -p\n");
					exit(EXIT_FAILURE);
				}
				break;
			case 'h':
				hflag = 1;
				break;
			case '?':
				printHelp(argv[0]);
				exit(EXIT_FAILURE);
			default:
				printHelp(argv[0]);
				exit(EXIT_FAILURE);
		}
	}

	if ((hflag == 1) || (argc == 1)) {
		printHelp(argv[0]);
		return 0;
	}

	// Extract i2c device
	if (optind < argc) {
		strcpy(i2c_filename, argv[optind]);
	} else {
		printf("I2C Device required.\n");
		exit(EXIT_FAILURE);
	}

	// Open I2C file
	i2c_file = open(i2c_filename, O_RDWR);
	if (i2c_file < 0) {
		printf("Error opening i2c device\n");
		exit(EXIT_FAILURE);
	}

	if ((rflag + sflag + jflag + hflag + wflag + dflag) > 1) {
		printf("Invalid set of options specified.\n");
		printHelp(argv[0]);
		return 0;
	}

	if ((wflag == 1) || (dflag == 1)) {
		if (i2cDetect(i2c_file, peripheral_address[periph_num]) != 0) {
			printf("Peripheral at %X not found\n", peripheral_address[periph_num]);
			exit(EXIT_FAILURE);
		}

		dna_file = open(dna_filename, O_RDWR | O_CREAT, 0666);
		if (dna_file < 0) {
			printf("Error opening DNA file\n");
			exit(EXIT_FAILURE);
		}
	}

	if (rflag == 1) { // Run the main SmartVIO procedure
		if (readDNA(i2c_file, &svio1, &svio2) != 0) {
			printf("Error obtaining a SmartVIO solution\n");
			exit(EXIT_FAILURE);
		}

		if (applyVIO(i2c_file, svio1, svio2) != 0) {
			printf("Error applying SmartVIO settings to power supplies\n");
			exit(EXIT_FAILURE);
		}

		if (printVIOStrings(json_handler, i2c_file) != 0) {
			printf("Error retrieving DNA strings\n");
			exit(EXIT_FAILURE);
		}
	} else if (sflag == 1) { // Apply a user specified VIO
		if (applyVIO(i2c_file, svio1, svio2) != 0) {
			printf("Error applying SmartVIO settings to power supplies\n");
			exit(EXIT_FAILURE);
		}
	} else if (jflag == 1) {
		readDNA(i2c_file, &svio1, &svio2);

		// Bounds check on the svio ranges
		if ((svio1 < 120) || (svio1 > 330) || (svio2 < 120) || (svio2 > 330)) {
			json_handler["vio"][0] = 0;
			json_handler["vio"][1] = 0;
		} else {
			json_handler["vio"][0] = svio1;
			json_handler["vio"][1] = svio2;
		}

		printVIOStrings(json_handler, i2c_file);

		printf(json_handler.dump().c_str());
		printf("\n");
	} else if (wflag == 1) { // Write DNA from a file to a peripheral
		if (read(dna_file, &dna_length, 2) != 2) {
			printf("Error reading from DNA file\n");
			exit(EXIT_FAILURE);
		}

		if (dna_length > 1318) {
			printf("Invalid DNA Length\n");
			exit(EXIT_FAILURE);
		}

		lseek(dna_file, 0, SEEK_SET);
		if (read(dna_file, dna_buf, dna_length) != dna_length) {
			printf("Error reading from DNA file\n");
			exit(EXIT_FAILURE);
		}

		if (writeMCU(i2c_file, peripheral_address[periph_num], 0x8000,
		             dna_buf, dna_length) != 0) {
			printf("Error writing to the MCU\n");
			exit(EXIT_FAILURE);
		}
	} else if (dflag == 1) { // Dump DNA from a peripheral to a file
		dna_length = dumpDNA(i2c_file, peripheral_address[periph_num], dna_buf);

		if (dna_length < 0) {
			printf("Error reading DNA from device\n");
			exit(EXIT_FAILURE);
		}
		
		if (write(dna_file, dna_buf, dna_length) != dna_length) {
			printf("Error writing to DNA file\n");
			exit(EXIT_FAILURE);
		}
	} else {
		printHelp(argv[0]);
		return 0;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x850, %rsp            # imm = 0x850
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x70c(%rbp)
movl $0x0, -0x710(%rbp)
leaq -0x728(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5610
movq 0x113a0(%rip), %rax     # 0x15f0c
movq %rax, -0x730(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xfd83(%rip), %rdx      # 0x14904
callq 0x3080
movl %eax, -0x714(%rbp)
cmpl $-0x1, %eax
je 0x4da0
movl -0x714(%rbp), %eax
addl $-0x31, %eax
movl %eax, %ecx
movq %rcx, -0x7b8(%rbp)
subl $0x46, %eax
ja 0x4d83
movq -0x7b8(%rbp), %rax
leaq 0xf446(%rip), %rcx      # 0x14004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x14(%rbp)
jmp 0x4d9b
movl $0x1, -0x18(%rbp)
jmp 0x4d9b
movl $0x1, -0x1c(%rbp)
jmp 0x4d9b
movq 0x1b3ce(%rip), %rax     # 0x1ffc0
cmpq $0x0, (%rax)
je 0x4c0c
movq 0x1b3c1(%rip), %rax     # 0x1ffc0
movq (%rax), %rdi
callq 0x33c0
movl %eax, -0x2c(%rbp)
jmp 0x4c3d
leaq 0xfd00(%rip), %rdi      # 0x14913
xorl %eax, %eax
callq 0x3050
jmp 0x4c1c
movl $0x1, %edi
callq 0x3320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x738(%rbp)
movl %eax, -0x73c(%rbp)
jmp 0x55d2
jmp 0x4d9b
movq 0x1b377(%rip), %rax     # 0x1ffc0
cmpq $0x0, (%rax)
je 0x4c63
movq 0x1b36a(%rip), %rax     # 0x1ffc0
movq (%rax), %rdi
callq 0x33c0
movl %eax, -0x30(%rbp)
jmp 0x4c7d
leaq 0xfcc7(%rip), %rdi      # 0x14931
xorl %eax, %eax
callq 0x3050
jmp 0x4c73
movl $0x1, %edi
callq 0x3320
jmp 0x4d9b
movl $0x1, -0x24(%rbp)
movq 0x1b330(%rip), %rax     # 0x1ffc0
cmpq $0x0, (%rax)
je 0x4cae
leaq -0x1d0(%rbp), %rdi
movq 0x1b31c(%rip), %rax     # 0x1ffc0
movq (%rax), %rsi
callq 0x3280
jmp 0x4cc8
leaq 0xfc9a(%rip), %rdi      # 0x1494f
xorl %eax, %eax
callq 0x3050
jmp 0x4cbe
movl $0x1, %edi
callq 0x3320
jmp 0x4d9b
movl $0x1, -0x28(%rbp)
movq 0x1b2e5(%rip), %rax     # 0x1ffc0
cmpq $0x0, (%rax)
je 0x4cf9
leaq -0x1d0(%rbp), %rdi
movq 0x1b2d1(%rip), %rax     # 0x1ffc0
movq (%rax), %rsi
callq 0x3280
jmp 0x4d13
leaq 0xfc6d(%rip), %rdi      # 0x1496d
xorl %eax, %eax
callq 0x3050
jmp 0x4d09
movl $0x1, %edi
callq 0x3320
jmp 0x4d9b
movq 0x1b2a1(%rip), %rax     # 0x1ffc0
cmpq $0x0, (%rax)
je 0x4d46
movq 0x1b294(%rip), %rax     # 0x1ffc0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x3380
subq $0x1, %rax
movl %eax, -0x710(%rbp)
jmp 0x4d60
leaq 0xfc3e(%rip), %rdi      # 0x1498b
xorl %eax, %eax
callq 0x3050
jmp 0x4d56
movl $0x1, %edi
callq 0x3320
jmp 0x4d9b
movl $0x1, -0x20(%rbp)
jmp 0x4d9b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4950
jmp 0x4d79
movl $0x1, %edi
callq 0x3320
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4950
jmp 0x4d91
movl $0x1, %edi
callq 0x3320
jmp 0x4b73
cmpl $0x1, -0x20(%rbp)
je 0x4dac
cmpl $0x1, -0x8(%rbp)
jne 0x4dd0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4950
jmp 0x4dba
movl $0x0, -0x4(%rbp)
movl $0x1, -0x740(%rbp)
jmp 0x55ba
movq 0x1b209(%rip), %rax     # 0x1ffe0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0x4dfe
leaq -0x100(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x1b1f0(%rip), %rcx     # 0x1ffe0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3280
jmp 0x4e18
leaq 0xfba4(%rip), %rdi      # 0x149a9
xorl %eax, %eax
callq 0x3050
jmp 0x4e0e
movl $0x1, %edi
callq 0x3320
xorl %eax, %eax
leaq -0x100(%rbp), %rdi
movl $0x2, %esi
callq 0x3230
movl %eax, -0x7bc(%rbp)
jmp 0x4e33
movl -0x7bc(%rbp), %eax
movl %eax, -0x704(%rbp)
cmpl $0x0, -0x704(%rbp)
jge 0x4e62
leaq 0xfb70(%rip), %rdi      # 0x149bf
xorl %eax, %eax
callq 0x3050
jmp 0x4e58
movl $0x1, %edi
callq 0x3320
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
addl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
addl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
cmpl $0x1, %eax
jle 0x4ead
leaq 0xfb59(%rip), %rdi      # 0x149d9
xorl %eax, %eax
callq 0x3050
jmp 0x4e89
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4950
jmp 0x4e97
movl $0x0, -0x4(%rbp)
movl $0x1, -0x740(%rbp)
jmp 0x55ba
cmpl $0x1, -0x24(%rbp)
je 0x4ebd
cmpl $0x1, -0x28(%rbp)
jne 0x4f64
movl -0x704(%rbp), %edi
movslq -0x710(%rbp), %rax
movzwl -0x730(%rbp,%rax,2), %esi
callq 0x35d0
movl %eax, -0x7c0(%rbp)
jmp 0x4edf
movl -0x7c0(%rbp), %eax
cmpl $0x0, %eax
je 0x4f13
movslq -0x710(%rbp), %rax
movzwl -0x730(%rbp,%rax,2), %esi
leaq 0xfafc(%rip), %rdi      # 0x149fc
xorl %eax, %eax
callq 0x3050
jmp 0x4f09
movl $0x1, %edi
callq 0x3320
xorl %eax, %eax
leaq -0x1d0(%rbp), %rdi
movl $0x42, %esi
movl $0x1b6, %edx            # imm = 0x1B6
callq 0x3230
movl %eax, -0x7c4(%rbp)
jmp 0x4f33
movl -0x7c4(%rbp), %eax
movl %eax, -0x708(%rbp)
cmpl $0x0, -0x708(%rbp)
jge 0x4f62
leaq 0xfac9(%rip), %rdi      # 0x14a18
xorl %eax, %eax
callq 0x3050
jmp 0x4f58
movl $0x1, %edi
callq 0x3320
jmp 0x4f64
cmpl $0x1, -0x14(%rbp)
jne 0x5030
movl -0x704(%rbp), %edi
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x3a20
movl %eax, -0x7c8(%rbp)
jmp 0x4f89
movl -0x7c8(%rbp), %eax
cmpl $0x0, %eax
je 0x4fae
leaq 0xfa95(%rip), %rdi      # 0x14a30
xorl %eax, %eax
callq 0x3050
jmp 0x4fa4
movl $0x1, %edi
callq 0x3320
movl -0x704(%rbp), %edi
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
callq 0x3c10
movl %eax, -0x7cc(%rbp)
jmp 0x4fc7
movl -0x7cc(%rbp), %eax
cmpl $0x0, %eax
je 0x4fec
leaq 0xfa7c(%rip), %rdi      # 0x14a55
xorl %eax, %eax
callq 0x3050
jmp 0x4fe2
movl $0x1, %edi
callq 0x3320
movl -0x704(%rbp), %esi
leaq -0x728(%rbp), %rdi
callq 0x3df0
movl %eax, -0x7d0(%rbp)
jmp 0x5006
movl -0x7d0(%rbp), %eax
cmpl $0x0, %eax
je 0x502b
leaq 0xfa71(%rip), %rdi      # 0x14a89
xorl %eax, %eax
callq 0x3050
jmp 0x5021
movl $0x1, %edi
callq 0x3320
jmp 0x55a9
cmpl $0x1, -0x18(%rbp)
jne 0x5079
movl -0x704(%rbp), %edi
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
callq 0x3c10
movl %eax, -0x7d4(%rbp)
jmp 0x504f
movl -0x7d4(%rbp), %eax
cmpl $0x0, %eax
je 0x5074
leaq 0xf9f4(%rip), %rdi      # 0x14a55
xorl %eax, %eax
callq 0x3050
jmp 0x506a
movl $0x1, %edi
callq 0x3320
jmp 0x55a7
cmpl $0x1, -0x1c(%rbp)
jne 0x5399
movl -0x704(%rbp), %edi
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x3a20
jmp 0x5098
cmpl $0x78, -0x2c(%rbp)
jb 0x50ba
cmpl $0x14a, -0x2c(%rbp)     # imm = 0x14A
ja 0x50ba
cmpl $0x78, -0x30(%rbp)
jb 0x50ba
cmpl $0x14a, -0x30(%rbp)     # imm = 0x14A
jbe 0x51ef
movl $0x0, -0x754(%rbp)
leaq -0x750(%rbp), %rdi
leaq -0x754(%rbp), %rsi
callq 0x5c20
leaq 0xf9c9(%rip), %rsi      # 0x14aa7
leaq -0x728(%rbp), %rdi
callq 0x5650
movq %rax, -0x7e0(%rbp)
jmp 0x50f3
movq -0x7e0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5890
movq %rax, -0x7e8(%rbp)
jmp 0x510c
movq -0x7e8(%rbp), %rdi
leaq -0x750(%rbp), %rsi
movq %rsi, -0x7f8(%rbp)
callq 0x5b20
movq -0x7f8(%rbp), %rdi
callq 0x5b90
movl $0x0, -0x76c(%rbp)
leaq -0x768(%rbp), %rdi
leaq -0x76c(%rbp), %rsi
callq 0x5c20
leaq 0xf951(%rip), %rsi      # 0x14aa7
leaq -0x728(%rbp), %rdi
callq 0x5650
movq %rax, -0x7f0(%rbp)
jmp 0x516b
movq -0x7f0(%rbp), %rdi
movl $0x1, %esi
callq 0x5890
movq %rax, -0x800(%rbp)
jmp 0x5185
movq -0x800(%rbp), %rdi
leaq -0x768(%rbp), %rsi
callq 0x5b20
leaq -0x768(%rbp), %rdi
callq 0x5b90
jmp 0x5307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x738(%rbp)
movl %eax, -0x73c(%rbp)
leaq -0x750(%rbp), %rdi
callq 0x5b90
jmp 0x55d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x738(%rbp)
movl %eax, -0x73c(%rbp)
leaq -0x768(%rbp), %rdi
callq 0x5b90
jmp 0x55d2
leaq -0x780(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x5c70
leaq 0xf8a1(%rip), %rsi      # 0x14aa7
leaq -0x728(%rbp), %rdi
callq 0x5650
movq %rax, -0x808(%rbp)
jmp 0x521b
movq -0x808(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5890
movq %rax, -0x810(%rbp)
jmp 0x5234
movq -0x810(%rbp), %rdi
leaq -0x780(%rbp), %rsi
movq %rsi, -0x820(%rbp)
callq 0x5b20
movq -0x820(%rbp), %rdi
callq 0x5b90
leaq -0x790(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5c70
leaq 0xf836(%rip), %rsi      # 0x14aa7
leaq -0x728(%rbp), %rdi
callq 0x5650
movq %rax, -0x818(%rbp)
jmp 0x5286
movq -0x818(%rbp), %rdi
movl $0x1, %esi
callq 0x5890
movq %rax, -0x828(%rbp)
jmp 0x52a0
movq -0x828(%rbp), %rdi
leaq -0x790(%rbp), %rsi
callq 0x5b20
leaq -0x790(%rbp), %rdi
callq 0x5b90
jmp 0x5307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x738(%rbp)
movl %eax, -0x73c(%rbp)
leaq -0x780(%rbp), %rdi
callq 0x5b90
jmp 0x55d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x738(%rbp)
movl %eax, -0x73c(%rbp)
leaq -0x790(%rbp), %rdi
callq 0x5b90
jmp 0x55d2
movl -0x704(%rbp), %esi
leaq -0x728(%rbp), %rdi
callq 0x3df0
jmp 0x531b
leaq -0x7b0(%rbp), %rdi
leaq -0x728(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x20, %ecx
xorl %r8d, %r8d
callq 0x5cc0
jmp 0x533d
leaq -0x7b0(%rbp), %rdi
callq 0x3120
movq %rax, %rdi
xorl %eax, %eax
callq 0x3050
jmp 0x5355
leaq -0x7b0(%rbp), %rdi
callq 0x31c0
leaq 0xf7bf(%rip), %rdi      # 0x14b27
xorl %eax, %eax
callq 0x3050
jmp 0x5371
jmp 0x55a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x738(%rbp)
movl %eax, -0x73c(%rbp)
leaq -0x7b0(%rbp), %rdi
callq 0x31c0
jmp 0x55d2
cmpl $0x1, -0x24(%rbp)
jne 0x54cd
movl -0x708(%rbp), %edi
leaq -0x70c(%rbp), %rsi
movl $0x2, %edx
callq 0x33a0
movq %rax, -0x830(%rbp)
jmp 0x53c3
movq -0x830(%rbp), %rax
cmpq $0x2, %rax
je 0x53ea
leaq 0xf6d4(%rip), %rdi      # 0x14aab
xorl %eax, %eax
callq 0x3050
jmp 0x53e0
movl $0x1, %edi
callq 0x3320
cmpl $0x526, -0x70c(%rbp)    # imm = 0x526
jle 0x5410
leaq 0xef4f(%rip), %rdi      # 0x1434c
xorl %eax, %eax
callq 0x3050
jmp 0x5406
movl $0x1, %edi
callq 0x3320
movl -0x708(%rbp), %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x3480
movl -0x708(%rbp), %edi
movslq -0x70c(%rbp), %rdx
leaq -0x700(%rbp), %rsi
callq 0x33a0
movq %rax, -0x838(%rbp)
jmp 0x5441
movq -0x838(%rbp), %rax
movslq -0x70c(%rbp), %rcx
cmpq %rcx, %rax
je 0x546e
leaq 0xf650(%rip), %rdi      # 0x14aab
xorl %eax, %eax
callq 0x3050
jmp 0x5464
movl $0x1, %edi
callq 0x3320
movl -0x704(%rbp), %edi
movslq -0x710(%rbp), %rax
movzwl -0x730(%rbp,%rax,2), %esi
movl -0x70c(%rbp), %r8d
movl $0x8000, %edx           # imm = 0x8000
leaq -0x700(%rbp), %rcx
callq 0x3820
movl %eax, -0x83c(%rbp)
jmp 0x54a3
movl -0x83c(%rbp), %eax
cmpl $0x0, %eax
je 0x54c8
leaq 0xf613(%rip), %rdi      # 0x14ac8
xorl %eax, %eax
callq 0x3050
jmp 0x54be
movl $0x1, %edi
callq 0x3320
jmp 0x55a3
cmpl $0x1, -0x28(%rbp)
jne 0x5580
movl -0x704(%rbp), %edi
movslq -0x710(%rbp), %rax
movzwl -0x730(%rbp,%rax,2), %esi
leaq -0x700(%rbp), %rdx
callq 0x3980
movl %eax, -0x840(%rbp)
jmp 0x5500
movl -0x840(%rbp), %eax
movl %eax, -0x70c(%rbp)
cmpl $0x0, -0x70c(%rbp)
jge 0x552f
leaq 0xf5c6(%rip), %rdi      # 0x14ae2
xorl %eax, %eax
callq 0x3050
jmp 0x5525
movl $0x1, %edi
callq 0x3320
movl -0x708(%rbp), %edi
movslq -0x70c(%rbp), %rdx
leaq -0x700(%rbp), %rsi
callq 0x30d0
movq %rax, -0x848(%rbp)
jmp 0x5551
movq -0x848(%rbp), %rax
movslq -0x70c(%rbp), %rcx
cmpq %rcx, %rax
je 0x557e
leaq 0xf596(%rip), %rdi      # 0x14b01
xorl %eax, %eax
callq 0x3050
jmp 0x5574
movl $0x1, %edi
callq 0x3320
jmp 0x55a1
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4950
jmp 0x558e
movl $0x0, -0x4(%rbp)
movl $0x1, -0x740(%rbp)
jmp 0x55ba
jmp 0x55a3
jmp 0x55a5
jmp 0x55a7
jmp 0x55a9
movl $0x0, -0x4(%rbp)
movl $0x1, -0x740(%rbp)
leaq -0x728(%rbp), %rdi
callq 0x5b90
movl -0x4(%rbp), %eax
addq $0x850, %rsp            # imm = 0x850
popq %rbp
retq
leaq -0x728(%rbp), %rdi
callq 0x5b90
movq -0x738(%rbp), %rdi
callq 0x3450
nopw (%rax,%rax)