#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_RAW;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ parse_dns_reply(unsigned char *, int, char *);
int recvfrom(int, unsigned char *, int, int /*<<< orphan*/, struct sockaddr *,
             int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void sniff_dns_replies(char *domain) {
  int sniffer, sockaddr_size = sizeof(struct sockaddr), len_pkt;
  unsigned char *buffer = (unsigned char *)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 i64 @calloc(i32 65560, i32 1)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_RAW
%12 = load i32, i32* @IPPROTO_UDP
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
br label %18
18: ; preds = %24, %23, %17
%19 = load i32, i32* %3
%20 = load i8*, i8** %6
%21 = call i32 @recvfrom(i32 %19, i8* %20, i32 65536, i32 0, %struct.sockaddr* %7, i32* %4)
store i32 %21, i32* %5
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %18
br label %18
24: ; preds = %18
%25 = load i8*, i8** %6
%26 = load i32, i32* %5
%27 = load i8*, i8** %2
%28 = call i32 @parse_dns_reply(i8* %25, i32 %26, i8* %27)
br label %18
}

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 i64 @calloc(i32 65560, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = bitcast %struct.sockaddr* %3 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_RAW
%10 = load i32, i32* @IPPROTO_UDP
%11 = tail call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
br label %16
16: ; preds = %21, %15
%17 = call i32 @recvfrom(i32 %11, i8* %6, i32 65536, i32 0, %struct.sockaddr* %3, i32* %2)
%18 = icmp slt i32 %17, 1
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @parse_dns_reply(i8* %6, i32 %17, i8* %0)
br label %21
21: ; preds = %19, %16
br label %16
}