// File: rpavlik[P]edid-decode/edid-decode.cpp
// Function: parse_cvt(char*)
static void parse_cvt(char *optarg)
{
	unsigned w = 0, h = 0;
	double fps = 0;
	unsigned rb = RB_NONE;
	bool interlaced = false;
	bool alt = false;
	bool overscan = false;

	while (*optarg != '\0') {
		int opt;
		double opt_val;

		opt = parse_cvt_subopt(&optarg, &opt_val);

		switch (opt) {
		case CVT_WIDTH:
			w = round(opt_val);
			break;
		case CVT_HEIGHT:
			h = round(opt_val);
			break;
		case CVT_FPS:
			fps = opt_val;
			break;
		case CVT_RB:
			rb = opt_val;
			break;
		case CVT_OVERSCAN:
			overscan = true;
			break;
		case CVT_INTERLACED:
			interlaced = opt_val;
			break;
		case CVT_ALT:
			alt = opt_val;
			break;
		default:
			break;
		}
	}

	if (!w || !h || !fps) {
		fprintf(stderr, "Missing width, height and/or fps.\n");
		usage();
		std::exit(EXIT_FAILURE);
	}
	if (interlaced)
		fps /= 2;
	timings t = state.calc_cvt_mode(w, h, fps, rb, interlaced, overscan, alt);
	state.print_timings("", &t, "CVT", "", true, false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movb $0x0, -0x1d(%rbp)
movb $0x0, -0x1e(%rbp)
movb $0x0, -0x1f(%rbp)
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x9775
leaq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa040
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq %rax, -0x90(%rbp)
subq $0x6, %rax
ja 0x976e
movq -0x90(%rbp), %rax
leaq 0x25ab2(%rip), %rcx     # 0x2f19c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsd -0x30(%rbp), %xmm0
callq 0x4160
cvttsd2si %xmm0, %rax
movl %eax, -0xc(%rbp)
jmp 0x9770
movsd -0x30(%rbp), %xmm0
callq 0x4160
cvttsd2si %xmm0, %rax
movl %eax, -0x10(%rbp)
jmp 0x9770
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x9770
cvttsd2si -0x30(%rbp), %rax
movl %eax, -0x1c(%rbp)
jmp 0x9770
movb $0x1, -0x1f(%rbp)
jmp 0x9770
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
setne %al
setp %cl
orb %cl, %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
jmp 0x9770
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
setne %al
setp %cl
orb %cl, %al
andb $0x1, %al
movb %al, -0x1e(%rbp)
jmp 0x9770
jmp 0x9770
jmp 0x96a8
cmpl $0x0, -0xc(%rbp)
je 0x9791
cmpl $0x0, -0x10(%rbp)
je 0x9791
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x97b8
jp 0x97b8
movq 0x41840(%rip), %rax     # 0x4afd8
movq (%rax), %rdi
leaq 0x279b7(%rip), %rsi     # 0x31159
movb $0x0, %al
callq 0x4450
callq 0x9650
movl $0x1, %edi
callq 0x43c0
testb $0x1, -0x1d(%rbp)
je 0x97d4
movsd -0x18(%rbp), %xmm0
movsd 0x25845(%rip), %xmm1    # 0x2f010
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
movsd -0x18(%rbp), %xmm0
movl -0x1c(%rbp), %r8d
movb -0x1d(%rbp), %r9b
movb -0x1f(%rbp), %r10b
movb -0x1e(%rbp), %al
leaq -0x84(%rbp), %rdi
leaq 0x42354(%rip), %rsi     # 0x4bb50
andb $0x1, %r9b
andb $0x1, %r10b
andb $0x1, %al
movzbl %r9b, %r9d
movzbl %r10b, %r10d
movl %r10d, (%rsp)
movzbl %al, %eax
movl %eax, 0x8(%rsp)
callq 0x2d890
leaq 0x4232b(%rip), %rdi     # 0x4bb50
leaq 0x2668d(%rip), %r8      # 0x2feb9
leaq -0x84(%rbp), %rdx
leaq 0x26639(%rip), %rcx     # 0x2fe73
movl $0x1, %r9d
xorl %eax, %eax
movq %r8, %rsi
movl $0x0, (%rsp)
callq 0x50c0
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)