// File: /workspace/github_c_makefile_star2_O1/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 0x1623d(%rip), %rdx     # 0x361e7
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 0x20000
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)
jmp 0x20225
movl $0x5, %edx
callq 0xf6c0
movq %rbx, %rdi
callq 0xf980
movq %rbx, %rdi
movl $0x2, %esi
callq 0x10760
testl %eax, %eax
je 0x20225
movabsq $-0xffff0001, %rax      # imm = 0xFFFFFFFF0000FFFF
leaq 0x163e1(%rip), %r15     # 0x36419
leaq 0x161bb(%rip), %r12     # 0x361fa
leaq 0x163d6(%rip), %r13     # 0x3641c
addq $0x7fff0000, %rax       # imm = 0x7FFF0000
movq %rax, (%rsp)
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
xorl %edx, %edx
callq 0xf620
movq %rax, %rbp
movq %rax, %rdi
movq %r15, %rsi
callq 0x10250
testl %eax, %eax
je 0x20131
movq %rbp, %rdi
movq %r12, %rsi
callq 0x10250
testl %eax, %eax
je 0x2014f
movq %rbp, %rdi
movq %r13, %rsi
callq 0x10250
testl %eax, %eax
je 0x20172
movq %rbp, %rdi
leaq 0x1637a(%rip), %rsi     # 0x3641f
callq 0x10250
testl %eax, %eax
je 0x2018d
movq %rbp, %rdi
leaq 0x15e11(%rip), %rsi     # 0x35ecd
callq 0x10250
testl %eax, %eax
je 0x201a8
movq %rbp, %rdi
leaq 0x1634f(%rip), %rsi     # 0x36422
callq 0x10250
testl %eax, %eax
je 0x201c3
movq %rbp, %rdi
leaq 0x1553a(%rip), %rsi     # 0x35624
callq 0x10250
testl %eax, %eax
je 0x201db
movq %rbp, %rdi
leaq 0x16100(%rip), %rsi     # 0x36201
callq 0x10250
testl %eax, %eax
jne 0x20203
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 0x201f9
movq %rbx, %rdi
callq 0x20540
movzbl %al, %eax
shll $0x17, %eax
movq 0x5c(%r14), %rcx
movq $-0x800001, %rdx        # imm = 0xFF7FFFFF
jmp 0x201f9
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 0x201f9
movq %rbx, %rdi
callq 0x20540
movzbl %al, %eax
shll $0x12, %eax
movq 0x5c(%r14), %rcx
movq $-0x40001, %rdx         # imm = 0xFFFBFFFF
jmp 0x201f9
movq %rbx, %rdi
callq 0x20540
movzbl %al, %eax
shll $0x11, %eax
movq 0x5c(%r14), %rcx
movq $-0x20001, %rdx         # imm = 0xFFFDFFFF
jmp 0x201f9
movq %rbx, %rdi
callq 0x20540
movzbl %al, %eax
shll $0x10, %eax
movq 0x5c(%r14), %rcx
movq $-0x10001, %rdx         # imm = 0xFFFEFFFF
jmp 0x201f9
movq %rbx, %rdi
callq 0x20540
movzbl %al, %eax
shll $0x1f, %eax
movq 0x5c(%r14), %rcx
andq (%rsp), %rcx
jmp 0x201fc
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
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 0x20050
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