#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_RAW;
char *calloc(int, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ parse_dns_reply(char *, int, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void sniff_dns_replies(char *domain) {
  int sniffer;
  socklen_t sockaddr_size = sizeof(struct sockaddr), len_pkt;
  char *buffer = calloc(65560, 1);
  struct sockaddr saddr;
  if ((sniffer = socket(AF_INET, SOCK_RAW, IPPROTO_UDP)) < 0)
    error("[!] Error socket:");
  for (;;) {
    if ((len_pkt =
             recvfrom(sniffer, buffer, 65536, 0, &saddr, &sockaddr_size)) < 1)
      continue;
    parse_dns_reply(buffer, len_pkt, domain);
  }
}


x86 assembly (clang, -O0):
<sniff_dns_replies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x4,-0x10(%rbp)
mov    $0x10018,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11ae <sniff_dns_replies+0x5e>
lea    0xe57(%rip),%rdi
call   1060 <error@plt>
jmp    11b3 <sniff_dns_replies+0x63>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
lea    -0x10(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x1,%eax
jge    11df <sniff_dns_replies+0x8f>
jmp    11b3 <sniff_dns_replies+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1030 <parse_dns_reply@plt>
jmp    11b3 <sniff_dns_replies+0x63>

x86 assembly (clang, -O2):
<sniff_dns_replies>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movl   $0x4,0x4(%rsp)
mov    $0x10018,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ab <sniff_dns_replies+0x5b>
lea    0xe5a(%rip),%rdi
call   1060 <error@plt>
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1050 <recvfrom@plt>
test   %eax,%eax
jle    11c0 <sniff_dns_replies+0x70>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <parse_dns_reply@plt>
jmp    11c0 <sniff_dns_replies+0x70>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [18 x i8] c"[!] Error socket:\00"
define void @sniff_dns_replies(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.sockaddr
store i8* %0, i8** %2
store i32 4, i32* %4
%8 = call i8* @calloc(i32 65560, i32 1)
store i8* %8, i8** %6
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_RAW
%11 = load i32, i32* @IPPROTO_UDP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
br label %17
17: ; preds = %23, %22, %16
%18 = load i32, i32* %3
%19 = load i8*, i8** %6
%20 = call i32 @recvfrom(i32 %18, i8* %19, i32 65536, i32 0, %struct.sockaddr* %7, i32* %4)
store i32 %20, i32* %5
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
br label %17
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = load i32, i32* %5
%26 = load i8*, i8** %2
%27 = call i32 @parse_dns_reply(i8* %24, i32 %25, i8* %26)
br label %17
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [18 x i8] c"[!] Error socket:\00"
define void @sniff_dns_replies(i8* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr
%4 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%5 = tail call dereferenceable_or_null(65560) i8* @calloc(i32 65560, i32 1)
%6 = bitcast %struct.sockaddr* %3 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_RAW
%9 = load i32, i32* @IPPROTO_UDP
%10 = tail call i32 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
br label %15
15: ; preds = %20, %14
%16 = call i32 @recvfrom(i32 %10, i8* %5, i32 65536, i32 0, %struct.sockaddr* %3, i32* %2)
%17 = icmp slt i32 %16, 1
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @parse_dns_reply(i8* %5, i32 %16, i8* %0)
br label %20
20: ; preds = %18, %15
br label %15
}