#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef unsigned int uint32_t;
struct sockaddr_ll {
  int sll_halen;
  int **sll_addr;
  void *sll_protocol;
  int /*<<< orphan*/ sll_ifindex;
  int /*<<< orphan*/ sll_family;
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
struct TYPE_4__ {
  scalar_t__ sa_data;
};
struct TYPE_3__ {
  scalar_t__ sa_data;
};
struct ifreq {
  TYPE_2__ ifr_addr;
  TYPE_1__ ifr_hwaddr;
};
struct ether_arp {
  int arp_hln;
  int arp_pln;
  int *arp_tpa;
  int *arp_sha;
  int *arp_spa;
  int /*<<< orphan*/ arp_tha;
  void *arp_op;
  void *arp_pro;
  void *arp_hrd;
};
typedef int /*<<< orphan*/ in_addr_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ARPHRD_ETHER;
int /*<<< orphan*/ ARPOP_REQUEST;
int ETHER_ADDR_LEN;
int /*<<< orphan*/ ETH_P_ARP;
int /*<<< orphan*/ ETH_P_IP;
int /*<<< orphan*/ die(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ get_ifr_addr(int, struct ifreq *);
int /*<<< orphan*/ get_ifr_hwaddr(int, struct ifreq *);
int /*<<< orphan*/ get_ifr_ifindex(int, struct ifreq *);
void *htons(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int **, ...);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int recv(int, struct ether_arp *, int, int /*<<< orphan*/);
int sendto(int, struct ether_arp *, int, int /*<<< orphan*/, struct sockaddr *,
           int);
int /*<<< orphan*/ set_ifr_name(struct ifreq *, char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void request_mac(int fd, const char *if_name, struct ether_arp *req,
                 uint32_t ip_addr) {
  const unsigned char ether_broadcast_addr[] = {0xff, 0xff, 0xff,
                                                0xff, 0xff, 0xff};
  struct ifreq ifr;
  set_ifr_name(&ifr, if_name);
  struct sockaddr_ll addr = {0};
  addr.sll_family = AF_PACKET;
  addr.sll_ifindex = get_ifr_ifindex(fd, &ifr);
  addr.sll_halen = ETHER_ADDR_LEN;
  addr.sll_protocol = htons(ETH_P_ARP);
  memcpy(addr.sll_addr, ether_broadcast_addr, ETHER_ADDR_LEN);
  req->arp_hrd = htons(ARPHRD_ETHER);
  req->arp_pro = htons(ETH_P_IP);
  req->arp_hln = ETHER_ADDR_LEN;
  req->arp_pln = sizeof(in_addr_t);
  req->arp_op = htons(ARPOP_REQUEST);
  memset(&req->arp_tha, 0, sizeof(req->arp_tha));
  memcpy(&req->arp_tpa, &ip_addr, sizeof(req->arp_tpa));
  get_ifr_hwaddr(fd, &ifr);
  memcpy(&req->arp_sha, (unsigned char *)ifr.ifr_hwaddr.sa_data,
         sizeof(req->arp_sha));
  get_ifr_addr(fd, &ifr);
  memcpy(&req->arp_spa, (unsigned char *)ifr.ifr_addr.sa_data + 2,
         sizeof(req->arp_spa));
  if (sendto(fd, req, sizeof(struct ether_arp), 0, (struct sockaddr *)&addr,
             sizeof(addr)) == -1) {
    die(strerror(errno));
  }
  while (1) {
    int len = recv(fd, req, sizeof(struct ether_arp), 0);
    if (len == -1) {
      die(strerror(errno));
    }
    if (len == 0) {
      continue;
    }
    unsigned int from_addr = (req->arp_spa[3] << 24) | (req->arp_spa[2] << 16) |
                             (req->arp_spa[1] << 8) | (req->arp_spa[0] << 0);
    if (from_addr != ip_addr) {
      continue;
    }
    break;
  }
}


x86 assembly (clang, -O0):
<request_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0xe34(%rip),%eax
mov    %eax,-0x22(%rbp)
mov    0xe2e(%rip),%ax
mov    %ax,-0x1e(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1090 <set_ifr_name@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10c0 <get_ifr_ifindex@plt>
mov    %eax,-0x48(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%rdi
lea    -0x22(%rbp),%rsi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   10a0 <memcpy@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x38(%rax)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    0x2d6f(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x18(%rbp),%rdi
add    $0x20,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
xor    %eax,%eax
lea    -0x1c(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <get_ifr_hwaddr@plt>
mov    -0x18(%rbp),%rdi
add    $0x10,%rdi
mov    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    $0x8,%edx
call   10a0 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1040 <get_ifr_addr@plt>
mov    -0x18(%rbp),%rdi
add    $0x18,%rdi
mov    -0x38(%rbp),%rsi
add    $0x2,%rsi
xor    %eax,%eax
mov    $0x8,%edx
call   10a0 <memcpy@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x40,%edx
xor    %ecx,%ecx
mov    $0x28,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1360 <request_mac+0x1b0>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10b0 <die@plt>
jmp    1365 <request_mac+0x1b5>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    139a <request_mac+0x1ea>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10b0 <die@plt>
cmpl   $0x0,-0x64(%rbp)
jne    13a9 <request_mac+0x1f9>
jmp    1365 <request_mac+0x1b5>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    0xc(%rax),%eax
shl    $0x18,%eax
mov    -0x18(%rbp),%rcx
mov    0x18(%rcx),%rcx
mov    0x8(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    0x18(%rcx),%rcx
mov    0x4(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    0x18(%rcx),%rcx
mov    (%rcx),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     13fa <request_mac+0x24a>
jmp    1365 <request_mac+0x1b5>
jmp    13ff <request_mac+0x24f>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_mac>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%rbx
mov    %edi,%r15d
mov    %ecx,0x4(%rsp)
movw   $0xffff,0xc(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
lea    0x38(%rsp),%r14
mov    %r14,%rdi
call   1090 <set_ifr_name@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
call   10c0 <get_ifr_ifindex@plt>
mov    %eax,0x28(%rsp)
mov    0x2dd7(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,0x20(%rsp)
mov    0x0(%rbp),%edx
lea    0x8(%rsp),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   10a0 <memcpy@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,0x38(%rbx)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,0x30(%rbx)
mov    0x0(%rbp),%eax
mov    %eax,(%rbx)
movl   $0x4,0x4(%rbx)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,0x28(%rbx)
lea    0x20(%rbx),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0x8(%rbx),%rdi
lea    0x4(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   10a0 <memcpy@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1050 <get_ifr_hwaddr@plt>
lea    0x10(%rbx),%rdi
mov    0x40(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   10a0 <memcpy@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1040 <get_ifr_addr@plt>
lea    0x18(%rbx),%rbp
mov    0x38(%rsp),%rsi
add    $0x2,%rsi
mov    $0x8,%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   10a0 <memcpy@plt>
lea    0x10(%rsp),%r8
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
mov    $0x28,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1329 <request_mac+0x179>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10b0 <die@plt>
mov    0x2c90(%rip),%r14
jmp    1362 <request_mac+0x1b2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp),%rax
mov    0xc(%rax),%ecx
shl    $0x18,%ecx
mov    0x4(%rax),%edx
mov    0x8(%rax),%esi
shl    $0x10,%esi
or     %ecx,%esi
shl    $0x8,%edx
or     %esi,%edx
or     (%rax),%edx
cmp    0x4(%rsp),%edx
je     138e <request_mac+0x1de>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1362 <request_mac+0x1b2>
cmp    $0xffffffff,%eax
jne    1340 <request_mac+0x190>
mov    (%r14),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10b0 <die@plt>
jmp    1340 <request_mac+0x190>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ether_arp = type { i32, i32, i32*, i32*, i32*, i32, i8*, i8*, i8* }
%struct.ifreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i64 }
%struct.sockaddr_ll = type { i32, i32**, i8*, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.request_mac.ether_broadcast_addr = [6 x i8] c"\FF\FF\FF\FF\FF\FF"
@AF_PACKET = global i32 0
@ETHER_ADDR_LEN = global i32 0
@ETH_P_ARP = global i32 0
@ARPHRD_ETHER = global i32 0
@ETH_P_IP = global i32 0
@ARPOP_REQUEST = global i32 0
@errno = global i32 0
define void @request_mac(i32 %0, i8* %1, %struct.ether_arp* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.ether_arp*
%8 = alloca i32
%9 = alloca [6 x i8]
%10 = alloca %struct.ifreq
%11 = alloca %struct.sockaddr_ll
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.ether_arp* %2, %struct.ether_arp** %7
store i32 %3, i32* %8
%14 = bitcast [6 x i8]* %9 to i8*
%15 = load i8*, i8** %6
%16 = call i32 @set_ifr_name(%struct.ifreq* %10, i8* %15)
%17 = bitcast %struct.sockaddr_ll* %11 to i8*
%18 = load i32, i32* @AF_PACKET
%19 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %11, i32 0, i32 4
store i32 %18, i32* %19
%20 = load i32, i32* %5
%21 = call i32 @get_ifr_ifindex(i32 %20, %struct.ifreq* %10)
%22 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %11, i32 0, i32 3
store i32 %21, i32* %22
%23 = load i32, i32* @ETHER_ADDR_LEN
%24 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %11, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @ETH_P_ARP
%26 = call i8* @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %11, i32 0, i32 2
store i8* %26, i8** %27
%28 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %11, i32 0, i32 1
%29 = load i32**, i32*** %28
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %9, i64 0, i64 0
%31 = load i32, i32* @ETHER_ADDR_LEN
%32 = call i32 (i32**, ...) @memcpy(i32** %29, i8* %30, i32 %31)
%33 = load i32, i32* @ARPHRD_ETHER
%34 = call i8* @htons(i32 %33)
%35 = load %struct.ether_arp*, %struct.ether_arp** %7
%36 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %35, i32 0, i32 8
store i8* %34, i8** %36
%37 = load i32, i32* @ETH_P_IP
%38 = call i8* @htons(i32 %37)
%39 = load %struct.ether_arp*, %struct.ether_arp** %7
%40 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %39, i32 0, i32 7
store i8* %38, i8** %40
%41 = load i32, i32* @ETHER_ADDR_LEN
%42 = load %struct.ether_arp*, %struct.ether_arp** %7
%43 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load %struct.ether_arp*, %struct.ether_arp** %7
%45 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %44, i32 0, i32 1
store i32 4, i32* %45
%46 = load i32, i32* @ARPOP_REQUEST
%47 = call i8* @htons(i32 %46)
%48 = load %struct.ether_arp*, %struct.ether_arp** %7
%49 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %48, i32 0, i32 6
store i8* %47, i8** %49
%50 = load %struct.ether_arp*, %struct.ether_arp** %7
%51 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %50, i32 0, i32 5
%52 = call i32 @memset(i32* %51, i32 0, i32 4)
%53 = load %struct.ether_arp*, %struct.ether_arp** %7
%54 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %53, i32 0, i32 2
%55 = call i32 (i32**, ...) @memcpy(i32** %54, i32* %8, i64 8)
%56 = load i32, i32* %5
%57 = call i32 @get_ifr_hwaddr(i32 %56, %struct.ifreq* %10)
%58 = load %struct.ether_arp*, %struct.ether_arp** %7
%59 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %58, i32 0, i32 3
%60 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %60, i32 0, i32 0
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to i8*
%64 = call i32 (i32**, ...) @memcpy(i32** %59, i8* %63, i64 8)
%65 = load i32, i32* %5
%66 = call i32 @get_ifr_addr(i32 %65, %struct.ifreq* %10)
%67 = load %struct.ether_arp*, %struct.ether_arp** %7
%68 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %67, i32 0, i32 4
%69 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %69, i32 0, i32 0
%71 = load i64, i64* %70
%72 = inttoptr i64 %71 to i8*
%73 = getelementptr inbounds i8, i8* %72, i64 2
%74 = call i32 (i32**, ...) @memcpy(i32** %68, i8* %73, i64 8)
%75 = load i32, i32* %5
%76 = load %struct.ether_arp*, %struct.ether_arp** %7
%77 = bitcast %struct.sockaddr_ll* %11 to %struct.sockaddr*
%78 = call i32 @sendto(i32 %75, %struct.ether_arp* %76, i32 64, i32 0, %struct.sockaddr* %77, i32 40)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %84
80: ; preds = %4
%81 = load i32, i32* @errno
%82 = call i32 @strerror(i32 %81)
%83 = call i32 @die(i32 %82)
br label %84
84: ; preds = %80, %4
br label %85
85: ; preds = %84, %98, %130
%86 = load i32, i32* %5
%87 = load %struct.ether_arp*, %struct.ether_arp** %7
%88 = call i32 @recv(i32 %86, %struct.ether_arp* %87, i32 64, i32 0)
store i32 %88, i32* %12
%89 = load i32, i32* %12
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %95
91: ; preds = %85
%92 = load i32, i32* @errno
%93 = call i32 @strerror(i32 %92)
%94 = call i32 @die(i32 %93)
br label %95
95: ; preds = %91, %85
%96 = load i32, i32* %12
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %95
br label %85
99: ; preds = %95
%100 = load %struct.ether_arp*, %struct.ether_arp** %7
%101 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %100, i32 0, i32 4
%102 = load i32*, i32** %101
%103 = getelementptr inbounds i32, i32* %102, i64 3
%104 = load i32, i32* %103
%105 = shl i32 %104, 24
%106 = load %struct.ether_arp*, %struct.ether_arp** %7
%107 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %106, i32 0, i32 4
%108 = load i32*, i32** %107
%109 = getelementptr inbounds i32, i32* %108, i64 2
%110 = load i32, i32* %109
%111 = shl i32 %110, 16
%112 = or i32 %105, %111
%113 = load %struct.ether_arp*, %struct.ether_arp** %7
%114 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %113, i32 0, i32 4
%115 = load i32*, i32** %114
%116 = getelementptr inbounds i32, i32* %115, i64 1
%117 = load i32, i32* %116
%118 = shl i32 %117, 8
%119 = or i32 %112, %118
%120 = load %struct.ether_arp*, %struct.ether_arp** %7
%121 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %120, i32 0, i32 4
%122 = load i32*, i32** %121
%123 = getelementptr inbounds i32, i32* %122, i64 0
%124 = load i32, i32* %123
%125 = shl i32 %124, 0
%126 = or i32 %119, %125
store i32 %126, i32* %13
%127 = load i32, i32* %13
%128 = load i32, i32* %8
%129 = icmp ne i32 %127, %128
br i1 %129, label %130, label %131
130: ; preds = %99
br label %85
131: ; preds = %99
br label %132
132: ; preds = %131
ret void
}

LLVM IR (-O2):
%struct.ether_arp = type { i32, i32, i32*, i32*, i32*, i32, i8*, i8*, i8* }
%struct.ifreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i64 }
%struct.sockaddr_ll = type { i32, i32**, i8*, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_PACKET = global i32 0
@ETHER_ADDR_LEN = global i32 0
@ETH_P_ARP = global i32 0
@ARPHRD_ETHER = global i32 0
@ETH_P_IP = global i32 0
@ARPOP_REQUEST = global i32 0
@errno = global i32 0
define void @request_mac(i32 %0, i8* %1, %struct.ether_arp* %2, i32 %3) {
%5 = alloca i32
%6 = alloca [6 x i8]
%7 = alloca %struct.ifreq
%8 = alloca %struct.sockaddr_ll
store i32 %3, i32* %5
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%10 = bitcast %struct.ifreq* %7 to i8*
%11 = call i32 @set_ifr_name(%struct.ifreq* %7, i8* %1)
%12 = bitcast %struct.sockaddr_ll* %8 to i8*
%13 = load i32, i32* @AF_PACKET
%14 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %8, i64 0, i32 4
store i32 %13, i32* %14
%15 = call i32 @get_ifr_ifindex(i32 %0, %struct.ifreq* %7)
%16 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %8, i64 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* @ETHER_ADDR_LEN
%18 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %8, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @ETH_P_ARP
%20 = call i8* @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %8, i64 0, i32 2
store i8* %20, i8** %21
%22 = load i32, i32* @ETHER_ADDR_LEN
%23 = call i32 (i32**, ...) @memcpy(i32** null, i8* %9, i32 %22)
%24 = load i32, i32* @ARPHRD_ETHER
%25 = call i8* @htons(i32 %24)
%26 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 8
store i8* %25, i8** %26
%27 = load i32, i32* @ETH_P_IP
%28 = call i8* @htons(i32 %27)
%29 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 7
store i8* %28, i8** %29
%30 = load i32, i32* @ETHER_ADDR_LEN
%31 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 0
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 1
store i32 4, i32* %32
%33 = load i32, i32* @ARPOP_REQUEST
%34 = call i8* @htons(i32 %33)
%35 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 6
store i8* %34, i8** %35
%36 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 5
%37 = call i32 @memset(i32* %36, i32 0, i32 4)
%38 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 2
%39 = call i32 (i32**, ...) @memcpy(i32** %38, i32* %5, i64 8)
%40 = call i32 @get_ifr_hwaddr(i32 %0, %struct.ifreq* %7)
%41 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 3
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i64 0, i32 1, i32 0
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to i8*
%45 = call i32 (i32**, ...) @memcpy(i32** %41, i8* %44, i64 8)
%46 = call i32 @get_ifr_addr(i32 %0, %struct.ifreq* %7)
%47 = getelementptr inbounds %struct.ether_arp, %struct.ether_arp* %2, i64 0, i32 4
%48 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i64 0, i32 0, i32 0
%49 = load i64, i64* %48
%50 = inttoptr i64 %49 to i8*
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = call i32 (i32**, ...) @memcpy(i32** %47, i8* %51, i64 8)
%53 = bitcast %struct.sockaddr_ll* %8 to %struct.sockaddr*
%54 = call i32 @sendto(i32 %0, %struct.ether_arp* %2, i32 64, i32 0, %struct.sockaddr* %53, i32 40)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %4
%57 = load i32, i32* @errno
%58 = call i32 @strerror(i32 %57)
%59 = call i32 @die(i32 %58)
br label %60
60: ; preds = %56, %4
br label %61
61: ; preds = %84, %60
%62 = call i32 @recv(i32 %0, %struct.ether_arp* %2, i32 64, i32 0)
switch i32 %62, label %67 [
i32 -1, label %63
i32 0, label %84
]
63: ; preds = %61
%64 = load i32, i32* @errno
%65 = call i32 @strerror(i32 %64)
%66 = call i32 @die(i32 %65)
br label %67
67: ; preds = %63, %61
%68 = load i32*, i32** %47
%69 = getelementptr inbounds i32, i32* %68, i64 3
%70 = load i32, i32* %69
%71 = shl i32 %70, 24
%72 = getelementptr inbounds i32, i32* %68, i64 2
%73 = load i32, i32* %72
%74 = shl i32 %73, 16
%75 = or i32 %74, %71
%76 = getelementptr inbounds i32, i32* %68, i64 1
%77 = load i32, i32* %76
%78 = shl i32 %77, 8
%79 = or i32 %75, %78
%80 = load i32, i32* %68
%81 = or i32 %79, %80
%82 = load i32, i32* %5
%83 = icmp eq i32 %81, %82
br i1 %83, label %85, label %84
84: ; preds = %67, %61
br label %61
85: ; preds = %67
ret void
}