#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct TYPE_2__ {
  scalar_t__ *sa_data;
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  TYPE_1__ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ethMAC;
typedef int /*<<< orphan*/ ethIP;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ PLATFORM_SleepMSec(int);
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ printf(char *);
int send_arp_request(char *, char *, char *, char *, int);
int send_arp_request_2(char *, char *, char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
int isARPReply(char *ipaddr) {
  int res = -1;
  char *pLanIpAddr = NULL;
  char *pLanMACAddr = NULL;
  char ethIP[16] = "";
  char ethMAC[18] = "";
  int fd;
  int i;
  struct ifreq ifr;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, "br0", IFNAMSIZ - 1);
  ioctl(fd, SIOCGIFADDR, &ifr);
  snprintf(ethIP, sizeof(ethIP), "%s",
           inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
  snprintf(ethMAC, sizeof(ethMAC), "%02X:%02X:%02X:%02X:%02X:%02X",
           (unsigned char)ifr.ifr_addr.sa_data[0],
           (unsigned char)ifr.ifr_addr.sa_data[1],
           (unsigned char)ifr.ifr_addr.sa_data[2],
           (unsigned char)ifr.ifr_addr.sa_data[3],
           (unsigned char)ifr.ifr_addr.sa_data[4],
           (unsigned char)ifr.ifr_addr.sa_data[5]);
  close(fd);
  res = send_arp_request(ethIP, ethMAC, ipaddr, "FF:FF:FF:FF:FF:FF", 1);
  if (!res) {
    printf("resent ARP request -> %s\n");
    PLATFORM_SleepMSec(500);
    res = send_arp_request_2(ethIP, ethMAC, ipaddr, "FF:FF:FF:FF:FF:FF", 1);
  }
  return res;
}


x86 assembly (clang, -O0):
<isARPReply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x12,%edx
call   1090 <memset@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x54(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x60(%rbp),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
lea    0xdca(%rip),%rsi
call   1040 <strncpy@plt>
mov    -0x54(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdx
call   10a0 <ioctl@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,%rcx
mov    $0x10,%esi
lea    0xd91(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x70(%rbp),%rax
mov    (%rax),%rax
movzbl %al,%ecx
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%rax
movzbl %al,%r8d
mov    -0x70(%rbp),%rax
mov    0x10(%rax),%rax
movzbl %al,%r9d
mov    -0x70(%rbp),%rax
mov    0x18(%rax),%rax
movzbl %al,%r11d
mov    -0x70(%rbp),%rax
mov    0x20(%rax),%rax
movzbl %al,%r10d
mov    -0x70(%rbp),%rax
mov    0x28(%rax),%rax
movzbl %al,%eax
mov    $0x12,%esi
lea    0xd38(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0x54(%rbp),%edi
call   10b0 <close@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xd27(%rip),%rcx
mov    $0x1,%r8d
call   1030 <send_arp_request@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    134d <isARPReply+0x19d>
lea    0xd1a(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1f4,%edi
call   10c0 <PLATFORM_SleepMSec@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xce6(%rip),%rcx
mov    $0x1,%r8d
call   1070 <send_arp_request_2@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isARPReply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x10(%rsp)
mov    0x2e15(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0x38(%rsp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
lea    0xe05(%rip),%rsi
call   1040 <strncpy@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    0x30(%rsp),%rdx
mov    %r13d,%edi
call   1090 <ioctl@plt>
mov    0x30(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xdde(%rip),%rdx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    0x30(%rsp),%rax
movzbl (%rax),%ecx
movzbl 0x8(%rax),%r8d
movzbl 0x10(%rax),%r9d
movzbl 0x18(%rax),%r10d
movzbl 0x20(%rax),%ebp
movzbl 0x28(%rax),%ebx
sub    $0x8,%rsp
lea    0xda0(%rip),%rdx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
mov    $0x12,%esi
xor    %eax,%eax
push   %rbx
push   %rbp
push   %r10
call   1080 <snprintf@plt>
add    $0x20,%rsp
mov    %r13d,%edi
call   10a0 <close@plt>
lea    0xd93(%rip),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    $0x1,%r8d
call   1030 <send_arp_request@plt>
test   %eax,%eax
jne    12dd <isARPReply+0x13d>
lea    0xd86(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1f4,%edi
call   10b0 <PLATFORM_SleepMSec@plt>
lea    0xd5e(%rip),%rcx
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
mov    $0x1,%r8d
call   1070 <send_arp_request_2@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64*, i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [4 x i8] c"br0\00"
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [30 x i8] c"%02X:%02X:%02X:%02X:%02X:%02X\00"
@.str.3 = [18 x i8] c"FF:FF:FF:FF:FF:FF\00"
@.str.4 = [26 x i8] c"resent ARP request -> %s\0A\00"
define i32 @isARPReply(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [16 x i8]
%7 = alloca [18 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.ifreq
store i8* %0, i8** %2
store i32 -1, i32* %3
store i8* null, i8** %4
store i8* null, i8** %5
%11 = bitcast [16 x i8]* %6 to i8*
%12 = bitcast [18 x i8]* %7 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %8
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 1
store i32 %16, i32* %18
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load i64, i64* @IFNAMSIZ
%22 = sub nsw i64 %21, 1
%23 = call i32 @strncpy(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %22)
%24 = load i32, i32* %8
%25 = load i32, i32* @SIOCGIFADDR
%26 = call i32 @ioctl(i32 %24, i32 %25, %struct.ifreq* %10)
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%29 = bitcast %struct.TYPE_2__* %28 to %struct.sockaddr_in*
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i8* @inet_ntoa(i32 %31)
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %27, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
%37 = load i64*, i64** %36
%38 = getelementptr inbounds i64, i64* %37, i64 0
%39 = load i64, i64* %38
%40 = trunc i64 %39 to i8
%41 = zext i8 %40 to i32
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
%44 = load i64*, i64** %43
%45 = getelementptr inbounds i64, i64* %44, i64 1
%46 = load i64, i64* %45
%47 = trunc i64 %46 to i8
%48 = zext i8 %47 to i32
%49 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
%51 = load i64*, i64** %50
%52 = getelementptr inbounds i64, i64* %51, i64 2
%53 = load i64, i64* %52
%54 = trunc i64 %53 to i8
%55 = zext i8 %54 to i32
%56 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
%58 = load i64*, i64** %57
%59 = getelementptr inbounds i64, i64* %58, i64 3
%60 = load i64, i64* %59
%61 = trunc i64 %60 to i8
%62 = zext i8 %61 to i32
%63 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%64 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i32 0, i32 0
%65 = load i64*, i64** %64
%66 = getelementptr inbounds i64, i64* %65, i64 4
%67 = load i64, i64* %66
%68 = trunc i64 %67 to i8
%69 = zext i8 %68 to i32
%70 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%71 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %70, i32 0, i32 0
%72 = load i64*, i64** %71
%73 = getelementptr inbounds i64, i64* %72, i64 5
%74 = load i64, i64* %73
%75 = trunc i64 %74 to i8
%76 = zext i8 %75 to i32
%77 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %34, i32 18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %48, i32 %55, i32 %62, i32 %69, i32 %76)
%78 = load i32, i32* %8
%79 = call i32 @close(i32 %78)
%80 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%81 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%82 = load i8*, i8** %2
%83 = call i32 @send_arp_request(i8* %80, i8* %81, i8* %82, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %83, i32* %3
%84 = load i32, i32* %3
%85 = icmp ne i32 %84, 0
br i1 %85, label %93, label %86
86: ; preds = %1
%87 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%88 = call i32 @PLATFORM_SleepMSec(i32 500)
%89 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%90 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%91 = load i8*, i8** %2
%92 = call i32 @send_arp_request_2(i8* %89, i8* %90, i8* %91, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %92, i32* %3
br label %93
93: ; preds = %86, %1
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [4 x i8] c"br0\00"
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [30 x i8] c"%02X:%02X:%02X:%02X:%02X:%02X\00"
@.str.3 = [18 x i8] c"FF:FF:FF:FF:FF:FF\00"
@.str.4 = [26 x i8] c"resent ARP request -> %s\0A\00"
define i32 @isARPReply(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca [18 x i8]
%4 = alloca %struct.ifreq
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.ifreq* %4 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i64, i64* @IFNAMSIZ
%14 = add nsw i64 %13, -1
%15 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = load i32, i32* @SIOCGIFADDR
%17 = call i32 @ioctl(i32 %10, i32 %16, %struct.ifreq* %4)
%18 = bitcast %struct.ifreq* %4 to i32*
%19 = load i32, i32* %18
%20 = call i8* @inet_ntoa(i32 %19)
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0, i32 0
%23 = load i64*, i64** %22
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = and i32 %25, 255
%27 = getelementptr inbounds i64, i64* %23, i64 1
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = and i32 %29, 255
%31 = getelementptr inbounds i64, i64* %23, i64 2
%32 = load i64, i64* %31
%33 = trunc i64 %32 to i32
%34 = and i32 %33, 255
%35 = getelementptr inbounds i64, i64* %23, i64 3
%36 = load i64, i64* %35
%37 = trunc i64 %36 to i32
%38 = and i32 %37, 255
%39 = getelementptr inbounds i64, i64* %23, i64 4
%40 = load i64, i64* %39
%41 = trunc i64 %40 to i32
%42 = and i32 %41, 255
%43 = getelementptr inbounds i64, i64* %23, i64 5
%44 = load i64, i64* %43
%45 = trunc i64 %44 to i32
%46 = and i32 %45, 255
%47 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %30, i32 %34, i32 %38, i32 %42, i32 %46)
%48 = call i32 @close(i32 %10)
%49 = call i32 @send_arp_request(i8* %5, i8* %6, i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 1)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %1
%52 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @PLATFORM_SleepMSec(i32 500)
%54 = call i32 @send_arp_request_2(i8* %5, i8* %6, i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %55
55: ; preds = %51, %1
%56 = phi i32 [ %49, %1 ], [ %54, %51 ]
ret i32 %56
}