#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ sa_data;
};
struct sockaddr_ll {
  scalar_t__ ifr_ifindex;
  scalar_t__ sll_ifindex;
  int /*<<< orphan*/ ifr_flags;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ sll_family;
  int /*<<< orphan*/ ifr_name;
};
typedef struct sockaddr_ll uint8_t;
typedef int /*<<< orphan*/ time_t;
struct sockaddr {
  int dummy;
};
struct ifreq {
  scalar_t__ ifr_ifindex;
  scalar_t__ sll_ifindex;
  int /*<<< orphan*/ ifr_flags;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ sll_family;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ saddr_ll;
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IFF_PROMISC;
int IP_MAXPACKET;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_RAW;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct sockaddr_ll *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(struct sockaddr_ll **, void *, int);
int /*<<< orphan*/ memset(struct sockaddr_ll *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recv_t(int, struct sockaddr_ll *, struct sockaddr_ll *,
                          int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
scalar_t__ strnlen(char *, int);
uint8_t *fetch_lldp_packet(char *ifname, time_t timeout) {
  int sock = 0;
  uint8_t *packet = NULL;
  uint8_t mac_address[6];
  struct ifreq ifr;
  struct sockaddr_ll saddr_ll;
  memset(&ifr, 0, sizeof(ifr));
  memset(&saddr_ll, 0, sizeof(saddr_ll));
  packet = (uint8_t *)malloc(IP_MAXPACKET * sizeof(uint8_t));
  if (packet == NULL) {
    perror("Could not allocate memory for packet buffer");
    exit(EXIT_FAILURE);
  }
  memset(packet, 0, IP_MAXPACKET * sizeof(uint8_t));
  if ((sock = socket(AF_PACKET, SOCK_RAW, htons(0x0003))) < 0) {
    perror("socket() failed");
    exit(EXIT_FAILURE);
  }
  strncpy(ifr.ifr_name, ifname, strnlen(ifname, 20) + 1);
  ioctl(sock, SIOCGIFINDEX, &ifr);
  if (ifr.ifr_ifindex == 0) {
    fprintf(stderr, "Interface %s does not seem to exist\n", ifname);
    exit(EXIT_FAILURE);
  }
  saddr_ll.sll_ifindex = ifr.ifr_ifindex;
  saddr_ll.sll_family = AF_PACKET;
  ;
  if ((bind(sock, (struct sockaddr *)&saddr_ll, sizeof(saddr_ll))) < 0) {
    perror("Bind failed");
    exit(EXIT_FAILURE);
  }
  ioctl(sock, SIOCGIFHWADDR, &ifr);
  memcpy(&mac_address, (void *)ifr.ifr_hwaddr.sa_data, 6);
  ;
  ;
  ioctl(sock, SIOCGIFFLAGS, &ifr);
  ifr.ifr_flags |= IFF_PROMISC;
  ioctl(sock, SIOCSIFFLAGS, &ifr);
  recv_t(sock, packet, mac_address, timeout);
  ;
  ifr.ifr_flags ^= IFF_PROMISC;
  ioctl(sock, SIOCSIFFLAGS, &ifr);
  ;
  close(sock);
  return packet;
}


x86 assembly (clang, -O0):
<fetch_lldp_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x138(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2dc2(%rip),%rax
movslq (%rax),%rax
imul   $0x28,%rax,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1265 <fetch_lldp_packet+0x85>
lea    0xdae(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d80(%rip),%rax
movslq (%rax),%rax
imul   $0x28,%rax,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x168(%rbp)
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x164(%rbp)
mov    $0x3,%edi
call   1040 <htons@plt>
mov    -0x168(%rbp),%edi
mov    -0x164(%rbp),%esi
mov    %eax,%edx
call   1100 <socket@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    12e1 <fetch_lldp_packet+0x101>
lea    0xd5e(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x114(%rbp),%eax
mov    %eax,-0x174(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x14,%esi
call   1070 <strnlen@plt>
mov    -0x174(%rbp),%edi
mov    -0x170(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%edi
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
lea    -0x138(%rbp),%rdx
call   1060 <ioctl@plt>
cmpq   $0x0,-0x138(%rbp)
jne    136c <fetch_lldp_packet+0x18c>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xce3(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x138(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0x28,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    13c1 <fetch_lldp_packet+0x1e1>
lea    0xcb3(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%edi
mov    0x2bed(%rip),%rax
mov    (%rax),%esi
lea    -0x138(%rbp),%rdx
call   1060 <ioctl@plt>
lea    -0x110(%rbp),%rdi
mov    -0x120(%rbp),%rsi
mov    $0x6,%edx
call   10b0 <memcpy@plt>
mov    -0x10(%rbp),%edi
mov    0x2bd5(%rip),%rax
mov    (%rax),%esi
lea    -0x138(%rbp),%rdx
call   1060 <ioctl@plt>
mov    0x2b90(%rip),%rax
mov    (%rax),%eax
or     -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2bd0(%rip),%rax
mov    (%rax),%esi
lea    -0x138(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x110(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1090 <recv_t@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%eax
xor    -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2b8d(%rip),%rax
mov    (%rax),%esi
lea    -0x138(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%rax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch_lldp_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2dd0(%rip),%rbx
mov    (%rbx),%eax
shl    $0x3,%eax
lea    (%rax,%rax,4),%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1393 <fetch_lldp_packet+0x1b3>
mov    %rax,%r12
mov    (%rbx),%eax
shl    $0x3,%eax
lea    (%rax,%rax,4),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2d6e(%rip),%r13
mov    0x0(%r13),%ebx
mov    0x2d7b(%rip),%rax
mov    (%rax),%ebp
mov    $0x3,%edi
call   1040 <htons@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     139c <fetch_lldp_packet+0x1bc>
mov    %eax,%ebp
mov    0x34(%rsp),%ebx
mov    %r15,%rdi
mov    $0x14,%esi
call   1070 <strnlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <strncpy@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     13a5 <fetch_lldp_packet+0x1c5>
mov    %r14d,0xc(%rsp)
mov    %rax,0x40(%rsp)
mov    0x0(%r13),%eax
mov    %eax,0x58(%rsp)
lea    0x38(%rsp),%rsi
mov    %ebp,%edi
mov    $0x28,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     13bf <fetch_lldp_packet+0x1df>
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    0x28(%rsp),%rsi
lea    0x60(%rsp),%r15
mov    %r15,%rdi
mov    $0x6,%edx
call   10b0 <memcpy@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    0x2c6b(%rip),%r13
mov    0x0(%r13),%eax
or     %eax,0x20(%rsp)
mov    0x2cb4(%rip),%r14
mov    (%r14),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    0xc(%rsp),%ecx
call   1090 <recv_t@plt>
mov    0x0(%r13),%eax
xor    %eax,0x20(%rsp)
mov    (%r14),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r12,%rax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc66(%rip),%rdi
jmp    13c6 <fetch_lldp_packet+0x1e6>
lea    0xc89(%rip),%rdi
jmp    13c6 <fetch_lldp_packet+0x1e6>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
lea    0xc87(%rip),%rsi
mov    %r15,%rdx
call   10a0 <fprintf@plt>
jmp    13cb <fetch_lldp_packet+0x1eb>
lea    0xc9b(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i64, i64, i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.ifreq = type { i64, i64, i32, %struct.TYPE_2__, i32, i32 }
%struct.sockaddr = type { i32 }
@IP_MAXPACKET = global i32 0
@.str = [44 x i8] c"Could not allocate memory for packet buffer\00"
@EXIT_FAILURE = global i32 0
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@SIOCGIFINDEX = global i32 0
@stderr = global i32 0
@.str.2 = [37 x i8] c"Interface %s does not seem to exist\0A\00"
@.str.3 = [12 x i8] c"Bind failed\00"
@SIOCGIFHWADDR = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_PROMISC = global i32 0
@SIOCSIFFLAGS = global i32 0
define %struct.sockaddr_ll* @fetch_lldp_packet(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_ll*
%7 = alloca [6 x %struct.sockaddr_ll]
%8 = alloca %struct.ifreq
%9 = alloca %struct.sockaddr_ll
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store %struct.sockaddr_ll* null, %struct.sockaddr_ll** %6
%10 = bitcast %struct.ifreq* %8 to %struct.sockaddr_ll*
%11 = call i32 @memset(%struct.sockaddr_ll* %10, i32 0, i32 40)
%12 = call i32 @memset(%struct.sockaddr_ll* %9, i32 0, i32 40)
%13 = load i32, i32* @IP_MAXPACKET
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 40
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to %struct.sockaddr_ll*
store %struct.sockaddr_ll* %18, %struct.sockaddr_ll** %6
%19 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %6
%20 = icmp eq %struct.sockaddr_ll* %19, null
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %6
%27 = load i32, i32* @IP_MAXPACKET
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 40
%30 = trunc i64 %29 to i32
%31 = call i32 @memset(%struct.sockaddr_ll* %26, i32 0, i32 %30)
%32 = load i32, i32* @AF_PACKET
%33 = load i32, i32* @SOCK_RAW
%34 = call i32 @htons(i32 3)
%35 = call i32 @socket(i32 %32, i32 %33, i32 %34)
store i32 %35, i32* %5
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %25
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 5
%43 = load i32, i32* %42
%44 = load i8*, i8** %3
%45 = load i8*, i8** %3
%46 = call i64 @strnlen(i8* %45, i32 20)
%47 = add nsw i64 %46, 1
%48 = call i32 @strncpy(i32 %43, i8* %44, i64 %47)
%49 = load i32, i32* %5
%50 = load i32, i32* @SIOCGIFINDEX
%51 = bitcast %struct.ifreq* %8 to %struct.sockaddr_ll*
%52 = call i32 @ioctl(i32 %49, i32 %50, %struct.sockaddr_ll* %51)
%53 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%54 = load i64, i64* %53
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %41
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %3
%59 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %41
%63 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%64 = load i64, i64* %63
%65 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 1
store i64 %64, i64* %65
%66 = load i32, i32* @AF_PACKET
%67 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 4
store i32 %66, i32* %67
%68 = load i32, i32* %5
%69 = bitcast %struct.sockaddr_ll* %9 to %struct.sockaddr*
%70 = call i64 @bind(i32 %68, %struct.sockaddr* %69, i32 40)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %62
%73 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %62
%77 = load i32, i32* %5
%78 = load i32, i32* @SIOCGIFHWADDR
%79 = bitcast %struct.ifreq* %8 to %struct.sockaddr_ll*
%80 = call i32 @ioctl(i32 %77, i32 %78, %struct.sockaddr_ll* %79)
%81 = bitcast [6 x %struct.sockaddr_ll]* %7 to %struct.sockaddr_ll**
%82 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 3
%83 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %82, i32 0, i32 0
%84 = load i64, i64* %83
%85 = inttoptr i64 %84 to i8*
%86 = call i32 @memcpy(%struct.sockaddr_ll** %81, i8* %85, i32 6)
%87 = load i32, i32* %5
%88 = load i32, i32* @SIOCGIFFLAGS
%89 = bitcast %struct.ifreq* %8 to %struct.sockaddr_ll*
%90 = call i32 @ioctl(i32 %87, i32 %88, %struct.sockaddr_ll* %89)
%91 = load i32, i32* @IFF_PROMISC
%92 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 2
%93 = load i32, i32* %92
%94 = or i32 %93, %91
store i32 %94, i32* %92
%95 = load i32, i32* %5
%96 = load i32, i32* @SIOCSIFFLAGS
%97 = bitcast %struct.ifreq* %8 to %struct.sockaddr_ll*
%98 = call i32 @ioctl(i32 %95, i32 %96, %struct.sockaddr_ll* %97)
%99 = load i32, i32* %5
%100 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %6
%101 = getelementptr inbounds [6 x %struct.sockaddr_ll], [6 x %struct.sockaddr_ll]* %7, i64 0, i64 0
%102 = load i32, i32* %4
%103 = call i32 @recv_t(i32 %99, %struct.sockaddr_ll* %100, %struct.sockaddr_ll* %101, i32 %102)
%104 = load i32, i32* @IFF_PROMISC
%105 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 2
%106 = load i32, i32* %105
%107 = xor i32 %106, %104
store i32 %107, i32* %105
%108 = load i32, i32* %5
%109 = load i32, i32* @SIOCSIFFLAGS
%110 = bitcast %struct.ifreq* %8 to %struct.sockaddr_ll*
%111 = call i32 @ioctl(i32 %108, i32 %109, %struct.sockaddr_ll* %110)
%112 = load i32, i32* %5
%113 = call i32 @close(i32 %112)
%114 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %6
ret %struct.sockaddr_ll* %114
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i64, i64, i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.ifreq = type { i64, i64, i32, %struct.TYPE_2__, i32, i32 }
%struct.sockaddr = type { i32 }
@IP_MAXPACKET = global i32 0
@.str = [44 x i8] c"Could not allocate memory for packet buffer\00"
@EXIT_FAILURE = global i32 0
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@SIOCGIFINDEX = global i32 0
@stderr = global i32 0
@.str.2 = [37 x i8] c"Interface %s does not seem to exist\0A\00"
@.str.3 = [12 x i8] c"Bind failed\00"
@SIOCGIFHWADDR = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_PROMISC = global i32 0
@SIOCSIFFLAGS = global i32 0
define %struct.sockaddr_ll* @fetch_lldp_packet(i8* %0, i32 %1) {
%3 = alloca [6 x %struct.sockaddr_ll]
%4 = alloca %struct.ifreq
%5 = alloca %struct.sockaddr_ll
%6 = bitcast [6 x %struct.sockaddr_ll]* %3 to i8*
%7 = bitcast %struct.ifreq* %4 to i8*
%8 = bitcast %struct.sockaddr_ll* %5 to i8*
%9 = bitcast %struct.ifreq* %4 to %struct.sockaddr_ll*
%10 = call i32 @memset(%struct.sockaddr_ll* %9, i32 0, i32 40)
%11 = call i32 @memset(%struct.sockaddr_ll* %5, i32 0, i32 40)
%12 = load i32, i32* @IP_MAXPACKET
%13 = mul i32 %12, 40
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to %struct.sockaddr_ll*
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32, i32* @IP_MAXPACKET
%23 = mul i32 %22, 40
%24 = call i32 @memset(%struct.sockaddr_ll* %15, i32 0, i32 %23)
%25 = load i32, i32* @AF_PACKET
%26 = load i32, i32* @SOCK_RAW
%27 = call i32 @htons(i32 3)
%28 = call i32 @socket(i32 %25, i32 %26, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %21
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 5
%36 = load i32, i32* %35
%37 = call i64 @strnlen(i8* %0, i32 20)
%38 = add nsw i64 %37, 1
%39 = call i32 @strncpy(i32 %36, i8* %0, i64 %38)
%40 = load i32, i32* @SIOCGIFINDEX
%41 = call i32 @ioctl(i32 %28, i32 %40, %struct.sockaddr_ll* %9)
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
%43 = load i64, i64* %42
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %34
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %34
%51 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 1
store i64 %43, i64* %51
%52 = load i32, i32* @AF_PACKET
%53 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 4
store i32 %52, i32* %53
%54 = bitcast %struct.sockaddr_ll* %5 to %struct.sockaddr*
%55 = call i64 @bind(i32 %28, %struct.sockaddr* %54, i32 40)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %50
%62 = load i32, i32* @SIOCGIFHWADDR
%63 = call i32 @ioctl(i32 %28, i32 %62, %struct.sockaddr_ll* %9)
%64 = bitcast [6 x %struct.sockaddr_ll]* %3 to %struct.sockaddr_ll**
%65 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 3, i32 0
%66 = load i64, i64* %65
%67 = inttoptr i64 %66 to i8*
%68 = call i32 @memcpy(%struct.sockaddr_ll** %64, i8* %67, i32 6)
%69 = load i32, i32* @SIOCGIFFLAGS
%70 = call i32 @ioctl(i32 %28, i32 %69, %struct.sockaddr_ll* %9)
%71 = load i32, i32* @IFF_PROMISC
%72 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 2
%73 = load i32, i32* %72
%74 = or i32 %73, %71
store i32 %74, i32* %72
%75 = load i32, i32* @SIOCSIFFLAGS
%76 = call i32 @ioctl(i32 %28, i32 %75, %struct.sockaddr_ll* %9)
%77 = getelementptr inbounds [6 x %struct.sockaddr_ll], [6 x %struct.sockaddr_ll]* %3, i64 0, i64 0
%78 = call i32 @recv_t(i32 %28, %struct.sockaddr_ll* %15, %struct.sockaddr_ll* %77, i32 %1)
%79 = load i32, i32* @IFF_PROMISC
%80 = load i32, i32* %72
%81 = xor i32 %80, %79
store i32 %81, i32* %72
%82 = load i32, i32* @SIOCSIFFLAGS
%83 = call i32 @ioctl(i32 %28, i32 %82, %struct.sockaddr_ll* %9)
%84 = call i32 @close(i32 %28)
ret %struct.sockaddr_ll* %15
}