// File: /workspace/github_c_makefile_star2_O2/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 0x13812(%rip), %rdx     # 0x311af
pushq $0x1
popq %rsi
callq 0xfd80
movq %rax, %r14
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0xfc00
testl %eax, %eax
je 0x1da06
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x10b40
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)
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x106f0
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rbp
pushq $0x5
popq %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xf700
movq %rbx, %rdi
callq 0xf9d0
pushq $-0x2
popq %r15
movabsq $-0xffff0001, %rax      # imm = 0xFFFFFFFF0000FFFF
orq $0x7fff0000, %rax       # imm = 0x7FFF0000
movq %rax, (%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x10820
testl %eax, %eax
je 0x1d9e8
movq %rbx, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0xf660
movq %rax, %r13
movzbl (%rax), %r12d
cmpl $0x71, %r12d
jne 0x1da70
cmpb $0x72, 0x1(%r13)
jne 0x1da70
cmpb $0x0, 0x2(%r13)
je 0x1db9b
movq %r13, %rdi
leaq 0x13748(%rip), %rsi     # 0x311c2
callq 0x102e0
testl %eax, %eax
je 0x1dadb
cmpl $0x7a, %r12d
je 0x1db63
cmpl $0x72, %r12d
je 0x1dafc
cmpl $0x74, %r12d
je 0x1db37
cmpl $0x61, %r12d
jne 0x1db6a
cmpb $0x61, 0x1(%r13)
jne 0x1db6a
cmpb $0x0, 0x2(%r13)
jne 0x1db6a
movq %rbx, %rdi
callq 0x1deda
movzbl %al, %eax
shll $0x12, %eax
movq 0x5c(%r14), %rcx
movq $-0x40001, %rdx         # imm = 0xFFFBFFFF
jmp 0x1dbed
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0x10b40
andl $0xf, %eax
shll $0x13, %eax
movq 0x5c(%r14), %rcx
movq $-0x780001, %rdx        # imm = 0xFF87FFFF
jmp 0x1dbed
cmpb $0x64, 0x1(%r13)
jne 0x1db0e
cmpb $0x0, 0x2(%r13)
je 0x1dbd4
cmpb $0x61, 0x1(%r13)
jne 0x1db6a
cmpb $0x0, 0x2(%r13)
jne 0x1db6a
movq %rbx, %rdi
callq 0x1deda
movzbl %al, %eax
shll $0x1f, %eax
movq 0x5c(%r14), %rcx
andq (%rsp), %rcx
jmp 0x1dbf0
cmpb $0x63, 0x1(%r13)
jne 0x1db6a
cmpb $0x0, 0x2(%r13)
jne 0x1db6a
movq %rbx, %rdi
callq 0x1deda
movzbl %al, %eax
shll $0x11, %eax
movq 0x5c(%r14), %rcx
movq $-0x20001, %rdx         # imm = 0xFFFDFFFF
jmp 0x1dbed
cmpb $0x0, 0x1(%r13)
je 0x1dbb6
movq %r13, %rdi
leaq 0x13655(%rip), %rsi     # 0x311c9
callq 0x102e0
testl %eax, %eax
jne 0x1dbf7
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0x10b40
andl $0xf, %eax
shll $0x18, %eax
movq 0x5c(%r14), %rcx
movq $-0xf000001, %rdx       # imm = 0xF0FFFFFF
jmp 0x1dbed
movq %rbx, %rdi
callq 0x1deda
movzbl %al, %eax
shll $0x17, %eax
movq 0x5c(%r14), %rcx
movq $-0x800001, %rdx        # imm = 0xFF7FFFFF
jmp 0x1dbed
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0x10b40
andl $0x7, %eax
shll $0x1c, %eax
movq 0x5c(%r14), %rcx
movq $-0x70000001, %rdx      # imm = 0x8FFFFFFF
jmp 0x1dbed
movq %rbx, %rdi
callq 0x1deda
movzbl %al, %eax
shll $0x10, %eax
movq 0x5c(%r14), %rcx
movq $-0x10001, %rdx         # imm = 0xFFFEFFFF
andq %rdx, %rcx
orq %rax, %rcx
movq %rcx, 0x5c(%r14)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x106f0
jmp 0x1da36