// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/dns.c
// Function: pkt_setflags
static int pkt_setflags(lua_State *L) {
	struct dns_packet *P = luaL_checkudata(L, 1, PACKET_CLASS);
	struct dns_header *hdr = dns_header(P);

	if (lua_isnumber(L, 2)) {
		int flags = luaL_checkint(L, 2);

		hdr->qr = 0x01 & (flags >> 15);
		hdr->opcode = 0x0f & (flags >> 11);
		hdr->aa = 0x01 & (flags >> 10);
		hdr->tc = 0x01 & (flags >> 9);
		hdr->rd = 0x01 & (flags >> 8);
		hdr->ra = 0x01 & (flags >> 7);
		hdr->unused = 0x07 & (flags >> 4);
		hdr->rcode = 0x0f & (flags >> 0);
	} else {
		luaL_checktype(L, 2, LUA_TTABLE);

		for (lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) {
			const char *flag = luaL_checkstring(L, -2);

			if (pkt_isflag(flag, "qr")) {
				hdr->qr = pkt_tobool(L, -1);
			} else if (pkt_isflag(flag, "opcode")) {
				hdr->opcode = luaL_checkint(L, -1);
			} else if (pkt_isflag(flag, "aa")) {
				hdr->aa = pkt_tobool(L, -1);
			} else if (pkt_isflag(flag, "tc")) {
				hdr->tc = pkt_tobool(L, -1);
			} else if (pkt_isflag(flag, "rd")) {
				hdr->rd = pkt_tobool(L, -1);
			} else if (pkt_isflag(flag, "ra")) {
				hdr->ra = pkt_tobool(L, -1);
			} else if (pkt_isflag(flag, "z")) {
				hdr->unused = luaL_checkint(L, -1);
			} else if (pkt_isflag(flag, "rcode")) {
				hdr->rcode = luaL_checkint(L, -1);
			}
		}
	}

	lua_settop(L, 1);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x16349(%rip), %rdx     # 0x361af
movl $0x1, %esi
callq 0xfcf0
movq %rax, %r14
movq %rbx, %rdi
movl $0x2, %esi
callq 0xfb80
movq %rbx, %rdi
movl $0x2, %esi
testl %eax, %eax
je 0x1fed8
callq 0x10a60
movl %eax, %ecx
shll $0x8, %ecx
movabsq $-0xffff0001, %rdx      # imm = 0xFFFFFFFF0000FFFF
andq 0x5c(%r14), %rdx
shll $0x18, %eax
andl $0xff0000, %ecx         # imm = 0xFF0000
orq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x5c(%r14)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10640
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x5, %edx
callq 0xf6c0
movq %rbx, %rdi
callq 0xf980
movq %rbx, %rdi
movl $0x2, %esi
callq 0x10760
testl %eax, %eax
je 0x1feb7
leaq 0x162c0(%rip), %r15     # 0x361c2
leaq 0x162c0(%rip), %r12     # 0x361c9
movabsq $-0xffff0001, %rax      # imm = 0xFFFFFFFF0000FFFF
orq $0x7fff0000, %rax       # imm = 0x7FFF0000
movq %rax, (%rsp)
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
xorl %edx, %edx
callq 0xf620
movq %rax, %r13
movzbl (%rax), %ebp
cmpl $0x71, %ebp
jne 0x1ff92
cmpb $0x72, 0x1(%r13)
jne 0x1ff49
cmpb $0x0, 0x2(%r13)
je 0x20049
movq %r13, %rdi
movq %r15, %rsi
callq 0x10250
testl %eax, %eax
je 0x1ffec
movq %r13, %rdi
movq %r12, %rsi
callq 0x10250
testl %eax, %eax
jne 0x2006c
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10a60
andl $0xf, %eax
shll $0x18, %eax
movq 0x5c(%r14), %rcx
movq $-0xf000001, %rdx       # imm = 0xF0FFFFFF
jmp 0x20062
movq %r13, %rdi
movq %r15, %rsi
callq 0x10250
testl %eax, %eax
je 0x1ffec
cmpl $0x73, %ebp
jg 0x2000c
cmpl $0x61, %ebp
je 0x20093
cmpl $0x72, %ebp
jne 0x1ff5c
cmpb $0x64, 0x1(%r13)
jne 0x1ffc6
cmpb $0x0, 0x2(%r13)
je 0x200f8
cmpb $0x61, 0x1(%r13)
jne 0x1ff5c
cmpb $0x0, 0x2(%r13)
jne 0x1ff5c
movq %rbx, %rdi
callq 0x20410
movzbl %al, %eax
shll $0x1f, %eax
movq 0x5c(%r14), %rcx
andq (%rsp), %rcx
jmp 0x20065
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10a60
andl $0xf, %eax
shll $0x13, %eax
movq 0x5c(%r14), %rcx
movq $-0x780001, %rdx        # imm = 0xFF87FFFF
jmp 0x20062
cmpl $0x74, %ebp
je 0x200c4
cmpl $0x7a, %ebp
jne 0x1ff5c
cmpb $0x0, 0x1(%r13)
jne 0x1ff5c
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10a60
andl $0x7, %eax
shll $0x1c, %eax
movq 0x5c(%r14), %rcx
movq $-0x70000001, %rdx      # imm = 0x8FFFFFFF
jmp 0x20062
movq %rbx, %rdi
callq 0x20410
movzbl %al, %eax
shll $0x17, %eax
movq 0x5c(%r14), %rcx
movq $-0x800001, %rdx        # imm = 0xFF7FFFFF
andq %rdx, %rcx
orq %rax, %rcx
movq %rcx, 0x5c(%r14)
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
movq %rbx, %rdi
movl $0x2, %esi
callq 0x10760
testl %eax, %eax
jne 0x1ff1d
jmp 0x1feb7
cmpb $0x61, 0x1(%r13)
jne 0x1ff5c
cmpb $0x0, 0x2(%r13)
jne 0x1ff5c
movq %rbx, %rdi
callq 0x20410
movzbl %al, %eax
shll $0x12, %eax
movq 0x5c(%r14), %rcx
movq $-0x40001, %rdx         # imm = 0xFFFBFFFF
jmp 0x20062
cmpb $0x63, 0x1(%r13)
jne 0x1ff5c
cmpb $0x0, 0x2(%r13)
jne 0x1ff5c
movq %rbx, %rdi
callq 0x20410
movzbl %al, %eax
shll $0x11, %eax
movq 0x5c(%r14), %rcx
movq $-0x20001, %rdx         # imm = 0xFFFDFFFF
jmp 0x20062
movq %rbx, %rdi
callq 0x20410
movzbl %al, %eax
shll $0x10, %eax
movq 0x5c(%r14), %rcx
movq $-0x10001, %rdx         # imm = 0xFFFEFFFF
jmp 0x20062