// File: dcdolson[P]nsh-sf-devkit/src/NetInterfaceFactory/NetInterfaceFactory.cpp
// Function: nshdev::NetInterfaceFactory::CreateInterfaceFromArgs(int&, char**&)
std::unique_ptr<NetInterface>
NetInterfaceFactory::CreateInterfaceFromArgs(int& argc,
                                             char**& argv)
{
	// cache the "starting" values so that later users of the args can use getopt

	const int old_optind = optind;
	const int old_optopt = optopt;
	char * const old_optarg = optarg;

    InterfaceOptions options(argc, argv);
	
	// restore
	optind = old_optind;
	optopt = old_optopt;
	optarg = old_optarg;

    argc -= options.GetNumArgsConsumed();
    argv += options.GetNumArgsConsumed();

	if(!options.GetDpdkPciAddress().empty())
    {
        return CreateDpdkIf(options.GetDpdkPciAddress());
    }
    else
    {
        return std::make_unique<PacketSocket>(options.GetIfIndex());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xd8(%rbp)
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq 0x70d9(%rip), %rax      # 0xafc8
movq %rax, -0xc8(%rbp)
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq 0x70ae(%rip), %rax      # 0xafb0
movq %rax, -0xc0(%rbp)
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq 0x7083(%rip), %rax      # 0xaf98
movq %rax, -0xb8(%rbp)
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x58(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x5120
movq -0xc8(%rbp), %rdx
movq -0xc0(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq -0xb0(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl %esi, (%rdx)
movl -0x20(%rbp), %edx
movl %edx, (%rcx)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
callq 0x5280
movl %eax, -0xa8(%rbp)
jmp 0x3f7a
movl -0xa8(%rbp), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x5280
movl %eax, -0xdc(%rbp)
jmp 0x3f9b
movl -0xdc(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movl %edx, %edx
leaq (%rcx,%rdx,8), %rcx
movq %rcx, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x5260
movq %rax, -0xe8(%rbp)
jmp 0x3fc3
movq -0xe8(%rbp), %rdi
callq 0x3350
testb $0x1, %al
jne 0x406f
leaq -0x58(%rbp), %rdi
callq 0x5260
movq %rax, -0xf0(%rbp)
jmp 0x3fe9
movq -0xf0(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x3110
jmp 0x3ffe
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3cb0
jmp 0x4010
movq -0xd8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4260
leaq -0x70(%rbp), %rdi
callq 0x42b0
leaq -0x90(%rbp), %rdi
callq 0x3150
movl $0x1, -0x94(%rbp)
jmp 0x40ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x40e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3150
jmp 0x40e3
leaq -0x58(%rbp), %rdi
callq 0x5250
movl %eax, -0xf4(%rbp)
jmp 0x4080
movl -0xf4(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa4(%rbp), %rsi
callq 0x4320
jmp 0x40a1
movq -0xd8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x43a0
leaq -0xa0(%rbp), %rdi
callq 0x43f0
movl $0x1, -0x94(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4450
movq -0xd0(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x4450
movq -0x60(%rbp), %rdi
callq 0x3390
nopw %cs:(%rax,%rax)
nop