#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct TYPE_6__ {
  int /*<<< orphan*/ sa_family;
  int /*<<< orphan*/ *sa_data;
};
struct TYPE_5__ {
  int /*<<< orphan*/ sa_family;
};
struct arpreq {
  int /*<<< orphan*/ arp_flags;
  TYPE_3__ arp_ha;
  TYPE_2__ arp_pa;
};
typedef int /*<<< orphan*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ ATF_PERM;
int /*<<< orphan*/ SIOCSARP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct arpreq *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ inet_addr(char *);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
main(int argc, char *argv[]) {
  int ret, fd;
  struct arpreq arpreq;
  struct sockaddr_in *sin;
  bzero(&arpreq, sizeof(struct arpreq));
  sin = (struct sockaddr_in *)&arpreq.arp_pa;
  sin->sin_addr.s_addr = inet_addr("1.1.1.1");
  sscanf("aa:aa:aa:aa:aa:aa", "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
         &arpreq.arp_ha.sa_data[0], &arpreq.arp_ha.sa_data[1],
         &arpreq.arp_ha.sa_data[2], &arpreq.arp_ha.sa_data[3],
         &arpreq.arp_ha.sa_data[4], &arpreq.arp_ha.sa_data[5]);
  arpreq.arp_pa.sa_family = AF_INET;
  arpreq.arp_ha.sa_family = AF_UNIX;
  arpreq.arp_flags = ATF_PERM;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ret = ioctl(fd, SIOCSARP, (caddr_t)&arpreq);
  close(fd);
  if (ret != 0) {
    perror("ioctl");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x20,%esi
call   1080 <bzero@plt>
lea    -0x38(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x40(%rbp)
lea    0xe59(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    $0x4,%rcx
mov    -0x28(%rbp),%r8
add    $0x8,%r8
mov    -0x28(%rbp),%r9
add    $0xc,%r9
mov    -0x28(%rbp),%r10
add    $0x10,%r10
mov    -0x28(%rbp),%rax
add    $0x14,%rax
lea    0xe21(%rip),%rdi
lea    0xe2c(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <sscanf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rax
mov    %eax,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x14(%rbp)
je     1274 <main+0x104>
lea    0xdc9(%rip),%rdi
call   1070 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1080 <bzero@plt>
lea    0xe71(%rip),%rdi
call   1050 <inet_addr@plt>
mov    0x18(%rsp),%rdx
lea    0x4(%rdx),%rcx
lea    0x8(%rdx),%r8
lea    0xc(%rdx),%r9
lea    0x10(%rdx),%rax
lea    0x14(%rdx),%rbp
lea    0xe54(%rip),%rdi
lea    0xe5f(%rip),%rsi
push   %rbp
push   %rax
call   1060 <sscanf@plt>
add    $0x10,%rsp
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x20(%rsp)
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <ioctl@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
test   %ebx,%ebx
jne    1227 <main+0xb7>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe0a(%rip),%rdi
call   1070 <perror@plt>
jmp    121e <main+0xae>

LLVM IR (-O0):
%struct.arpreq = type { i32, %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_6__ = type { i32, i32* }
%struct.TYPE_5__ = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32 }
@.str = [8 x i8] c"1.1.1.1\00"
@.str.1 = [18 x i8] c"aa:aa:aa:aa:aa:aa\00"
@.str.2 = [30 x i8] c"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\00"
@AF_INET = global i32 0
@AF_UNIX = global i32 0
@ATF_PERM = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCSARP = global i32 0
@.str.3 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.arpreq
%9 = alloca %struct.sockaddr_in*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @bzero(%struct.arpreq* %8, i32 32)
%11 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 2
%12 = bitcast %struct.TYPE_5__* %11 to %struct.sockaddr_in*
store %struct.sockaddr_in* %12, %struct.sockaddr_in** %9
%13 = call i32 @inet_addr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
store i32 %13, i32* %16
%17 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %17, i32 0, i32 1
%19 = load i32*, i32** %18
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %21, i32 0, i32 1
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %25, i32 0, i32 1
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 2
%29 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %29, i32 0, i32 1
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 3
%33 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %33, i32 0, i32 1
%35 = load i32*, i32** %34
%36 = getelementptr inbounds i32, i32* %35, i64 4
%37 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %37, i32 0, i32 1
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 5
%41 = call i32 @sscanf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32* %20, i32* %24, i32* %28, i32* %32, i32* %36, i32* %40)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 2
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %43, i32 0, i32 0
store i32 %42, i32* %44
%45 = load i32, i32* @AF_UNIX
%46 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 1
%47 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %46, i32 0, i32 0
store i32 %45, i32* %47
%48 = load i32, i32* @ATF_PERM
%49 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %8, i32 0, i32 0
store i32 %48, i32* %49
%50 = load i32, i32* @AF_INET
%51 = load i32, i32* @SOCK_DGRAM
%52 = call i32 @socket(i32 %50, i32 %51, i32 0)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = load i32, i32* @SIOCSARP
%55 = ptrtoint %struct.arpreq* %8 to i32
%56 = call i32 @ioctl(i32 %53, i32 %54, i32 %55)
store i32 %56, i32* %6
%57 = load i32, i32* %7
%58 = call i32 @close(i32 %57)
%59 = load i32, i32* %6
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %2
%62 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %61, %2
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.arpreq = type { i32, %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_6__ = type { i32, i32* }
%struct.TYPE_5__ = type { i32 }
@.str = [8 x i8] c"1.1.1.1\00"
@.str.1 = [18 x i8] c"aa:aa:aa:aa:aa:aa\00"
@.str.2 = [30 x i8] c"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\00"
@AF_INET = global i32 0
@AF_UNIX = global i32 0
@ATF_PERM = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCSARP = global i32 0
@.str.3 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.arpreq
%4 = bitcast %struct.arpreq* %3 to i8*
%5 = call i32 @bzero(%struct.arpreq* %3, i32 32)
%6 = tail call i32 @inet_addr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %3, i64 0, i32 2, i32 0
%8 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %3, i64 0, i32 1, i32 1
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = getelementptr inbounds i32, i32* %9, i64 2
%12 = getelementptr inbounds i32, i32* %9, i64 3
%13 = getelementptr inbounds i32, i32* %9, i64 4
%14 = getelementptr inbounds i32, i32* %9, i64 5
%15 = tail call i32 @sscanf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14)
%16 = load i32, i32* @AF_INET
store i32 %16, i32* %7
%17 = load i32, i32* @AF_UNIX
%18 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %3, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @ATF_PERM
%20 = getelementptr inbounds %struct.arpreq, %struct.arpreq* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @SOCK_DGRAM
%22 = tail call i32 @socket(i32 %16, i32 %21, i32 0)
%23 = load i32, i32* @SIOCSARP
%24 = ptrtoint %struct.arpreq* %3 to i64
%25 = trunc i64 %24 to i32
%26 = call i32 @ioctl(i32 %22, i32 %23, i32 %25)
%27 = call i32 @close(i32 %22)
%28 = icmp eq i32 %26, 0
br i1 %28, label %31, label %29
29: ; preds = %2
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %2
ret i32 0
}