#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 ifreq {
  int ifc_len;
  char *ifc_buf;
  char *ifr_name;
  TYPE_1__ ifr_hwaddr;
  struct ifreq *ifc_req;
};
struct ifconf {
  int ifc_len;
  char *ifc_buf;
  char *ifr_name;
  TYPE_1__ ifr_hwaddr;
  struct ifconf *ifc_req;
};
struct ether_addr {
  int /*<<< orphan*/ *ether_addr_octet;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
char *ether_ntoa(struct ether_addr *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(void) {
  int sck;
  char buf[1024];
  struct ifconf ifc;
  struct ifreq *ifr;
  int nInterfaces;
  int i;
  sck = socket(AF_INET, SOCK_DGRAM, 0);
  if (sck < 0) {
    perror("socket");
    return 1;
  }
  ifc.ifc_len = sizeof(buf);
  ifc.ifc_buf = buf;
  if (ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
    perror("ioctl(SIOCGIFCONF)");
    return 1;
  }
  ifr = ifc.ifc_req;
  nInterfaces = ifc.ifc_len / sizeof(struct ifreq);
  for (i = 0; i < nInterfaces; i++) {
    struct ifreq *item = &ifr[i];
    struct ether_addr *mac;
    char macbuf[255];
    if (ioctl(sck, SIOCGIFHWADDR, item) < 0) {
      perror("ioctl(SIOCGIFHWADDR)");
      return 1;
    }
    sprintf(macbuf, "%s",
            ether_ntoa((struct ether_addr *)item->ifr_hwaddr.sa_data));
    mac = (struct ether_addr *)item->ifr_hwaddr.sa_data;
    printf("\n dev = %s MAC = %s %02lx:%02lx:%02lx:%02lx:%02lx:%02lx\n\n",
           item->ifr_name, macbuf, mac->ether_addr_octet[0],
           mac->ether_addr_octet[1], mac->ether_addr_octet[2],
           mac->ether_addr_octet[3], mac->ether_addr_octet[4],
           mac->ether_addr_octet[5]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x580,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11b0 <main+0x50>
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1376 <main+0x216>
movl   $0x400,-0x438(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
lea    -0x438(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1202 <main+0xa2>
lea    0xe16(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1376 <main+0x216>
mov    -0x418(%rbp),%rax
mov    %rax,-0x440(%rbp)
movslq -0x438(%rbp),%rax
mov    $0x28,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x444(%rbp)
movl   $0x0,-0x448(%rbp)
mov    -0x448(%rbp),%eax
cmp    -0x444(%rbp),%eax
jge    136f <main+0x20f>
mov    -0x440(%rbp),%rax
movslq -0x448(%rbp),%rcx
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x450(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    -0x450(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1299 <main+0x139>
lea    0xd92(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1376 <main+0x216>
lea    -0x560(%rbp),%rax
mov    %rax,-0x568(%rbp)
mov    -0x450(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <ether_ntoa@plt>
mov    -0x568(%rbp),%rdi
mov    %rax,%rdx
lea    0xd67(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x450(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x458(%rbp)
mov    -0x450(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x560(%rbp),%rdx
mov    -0x458(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x458(%rbp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%r8d
mov    -0x458(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%r9d
mov    -0x458(%rbp),%rax
mov    (%rax),%rax
mov    0xc(%rax),%r11d
mov    -0x458(%rbp),%rax
mov    (%rax),%rax
mov    0x10(%rax),%r10d
mov    -0x458(%rbp),%rax
mov    (%rax),%rax
mov    0x14(%rax),%eax
lea    0xce9(%rip),%rdi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <printf@plt>
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
jmp    1231 <main+0xd1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x580,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x538,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     127d <main+0x11d>
mov    %eax,%r15d
movl   $0x400,0x8(%rsp)
lea    0x130(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
js     1286 <main+0x126>
movslq 0x8(%rsp),%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
shr    $0x5,%rdx
xor    %eax,%eax
test   %edx,%edx
jle    12a0 <main+0x140>
mov    0x28(%rsp),%rbp
mov    %edx,%ebx
mov    0x2dd9(%rip),%r14
lea    0x30(%rsp),%r13
lea    0xe2c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%esi
mov    %r15d,%edi
mov    %rbp,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
js     128f <main+0x12f>
mov    0x18(%rbp),%rdi
call   1040 <ether_ntoa@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%r11d
mov    0x14(%rax),%eax
sub    $0x8,%rsp
mov    %r12,%rdi
mov    %r13,%rdx
push   %rax
push   %r11
push   %r10
call   1050 <printf@plt>
add    $0x20,%rsp
add    $0x28,%rbp
add    $0xffffffffffffffff,%rbx
jne    1210 <main+0xb0>
xor    %eax,%eax
jmp    12a0 <main+0x140>
lea    0xd7c(%rip),%rdi
jmp    1296 <main+0x136>
lea    0xd7a(%rip),%rdi
jmp    1296 <main+0x136>
lea    0xd84(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
add    $0x538,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifconf = type { i32, i8*, i8*, %struct.TYPE_2__, %struct.ifconf* }
%struct.TYPE_2__ = type { i64 }
%struct.ifreq = type { i32, i8*, i8*, %struct.TYPE_2__, %struct.ifreq* }
%struct.ether_addr = type { i32* }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.1 = [19 x i8] c"ioctl(SIOCGIFCONF)\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [21 x i8] c"ioctl(SIOCGIFHWADDR)\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [58 x i8] c"\0A dev = %s MAC = %s %02lx:%02lx:%02lx:%02lx:%02lx:%02lx\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca %struct.ifconf
%5 = alloca %struct.ifreq*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ifreq*
%9 = alloca %struct.ether_addr*
%10 = alloca [255 x i8]
store i32 0, i32* %1
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %107
18: ; preds = %0
%19 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
store i32 1024, i32* %19
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 1
store i8* %20, i8** %21
%22 = load i32, i32* %2
%23 = load i32, i32* @SIOCGIFCONF
%24 = bitcast %struct.ifconf* %4 to %struct.ifreq*
%25 = call i64 @ioctl(i32 %22, i32 %23, %struct.ifreq* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %107
29: ; preds = %18
%30 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 4
%31 = load %struct.ifconf*, %struct.ifconf** %30
%32 = bitcast %struct.ifconf* %31 to %struct.ifreq*
store %struct.ifreq* %32, %struct.ifreq** %5
%33 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %4, i32 0, i32 0
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = udiv i64 %35, 40
%37 = trunc i64 %36 to i32
store i32 %37, i32* %6
store i32 0, i32* %7
br label %38
38: ; preds = %103, %29
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %106
42: ; preds = %38
%43 = load %struct.ifreq*, %struct.ifreq** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %43, i64 %45
store %struct.ifreq* %46, %struct.ifreq** %8
%47 = load i32, i32* %2
%48 = load i32, i32* @SIOCGIFHWADDR
%49 = load %struct.ifreq*, %struct.ifreq** %8
%50 = call i64 @ioctl(i32 %47, i32 %48, %struct.ifreq* %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %42
%53 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %107
54: ; preds = %42
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%56 = load %struct.ifreq*, %struct.ifreq** %8
%57 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %56, i32 0, i32 3
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = inttoptr i64 %59 to %struct.ether_addr*
%61 = call i8* @ether_ntoa(%struct.ether_addr* %60)
%62 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%63 = load %struct.ifreq*, %struct.ifreq** %8
%64 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %63, i32 0, i32 3
%65 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %64, i32 0, i32 0
%66 = load i64, i64* %65
%67 = inttoptr i64 %66 to %struct.ether_addr*
store %struct.ether_addr* %67, %struct.ether_addr** %9
%68 = load %struct.ifreq*, %struct.ifreq** %8
%69 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %68, i32 0, i32 2
%70 = load i8*, i8** %69
%71 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%72 = load %struct.ether_addr*, %struct.ether_addr** %9
%73 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %72, i32 0, i32 0
%74 = load i32*, i32** %73
%75 = getelementptr inbounds i32, i32* %74, i64 0
%76 = load i32, i32* %75
%77 = load %struct.ether_addr*, %struct.ether_addr** %9
%78 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %77, i32 0, i32 0
%79 = load i32*, i32** %78
%80 = getelementptr inbounds i32, i32* %79, i64 1
%81 = load i32, i32* %80
%82 = load %struct.ether_addr*, %struct.ether_addr** %9
%83 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %82, i32 0, i32 0
%84 = load i32*, i32** %83
%85 = getelementptr inbounds i32, i32* %84, i64 2
%86 = load i32, i32* %85
%87 = load %struct.ether_addr*, %struct.ether_addr** %9
%88 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %87, i32 0, i32 0
%89 = load i32*, i32** %88
%90 = getelementptr inbounds i32, i32* %89, i64 3
%91 = load i32, i32* %90
%92 = load %struct.ether_addr*, %struct.ether_addr** %9
%93 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %92, i32 0, i32 0
%94 = load i32*, i32** %93
%95 = getelementptr inbounds i32, i32* %94, i64 4
%96 = load i32, i32* %95
%97 = load %struct.ether_addr*, %struct.ether_addr** %9
%98 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %97, i32 0, i32 0
%99 = load i32*, i32** %98
%100 = getelementptr inbounds i32, i32* %99, i64 5
%101 = load i32, i32* %100
%102 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i8* %70, i8* %71, i32 %76, i32 %81, i32 %86, i32 %91, i32 %96, i32 %101)
br label %103
103: ; preds = %54
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %38
106: ; preds = %38
store i32 0, i32* %1
br label %107
107: ; preds = %106, %52, %27, %16
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8*, i8*, %struct.TYPE_2__, %struct.ifconf* }
%struct.TYPE_2__ = type { i64 }
%struct.ifreq = type { i32, i8*, i8*, %struct.TYPE_2__, %struct.ifreq* }
%struct.ether_addr = type { i32* }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCGIFCONF = global i32 0
@.str.1 = [19 x i8] c"ioctl(SIOCGIFCONF)\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [21 x i8] c"ioctl(SIOCGIFHWADDR)\00"
@.str.4 = [58 x i8] c"\0A dev = %s MAC = %s %02lx:%02lx:%02lx:%02lx:%02lx:%02lx\0A\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.ifconf
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.ifconf* %2 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %67
12: ; preds = %0
%13 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 0
store i32 1024, i32* %13
%14 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 1
store i8* %4, i8** %14
%15 = load i32, i32* @SIOCGIFCONF
%16 = bitcast %struct.ifconf* %2 to %struct.ifreq*
%17 = call i64 @ioctl(i32 %8, i32 %15, %struct.ifreq* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %67
21: ; preds = %12
%22 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %2, i64 0, i32 4
%23 = bitcast %struct.ifconf** %22 to %struct.ifreq**
%24 = load %struct.ifreq*, %struct.ifreq** %23
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = udiv i64 %26, 40
%28 = trunc i64 %27 to i32
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %67
30: ; preds = %21
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%32 = and i64 %27, 4294967295
br label %33
33: ; preds = %30, %41
%34 = phi i64 [ 0, %30 ], [ %65, %41 ]
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %24, i64 %34
%36 = load i32, i32* @SIOCGIFHWADDR
%37 = call i64 @ioctl(i32 %8, i32 %36, %struct.ifreq* %35)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %67
41: ; preds = %33
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %24, i64 %34, i32 3, i32 0
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to %struct.ether_addr*
%45 = call i8* @ether_ntoa(%struct.ether_addr* %44)
%46 = call i8* @strcpy(i8* %31, i8* dereferenceable(1) %45)
%47 = load i64, i64* %42
%48 = inttoptr i64 %47 to %struct.ether_addr*
%49 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %24, i64 %34, i32 2
%50 = load i8*, i8** %49
%51 = getelementptr inbounds %struct.ether_addr, %struct.ether_addr* %48, i64 0, i32 0
%52 = load i32*, i32** %51
%53 = load i32, i32* %52
%54 = getelementptr inbounds i32, i32* %52, i64 1
%55 = load i32, i32* %54
%56 = getelementptr inbounds i32, i32* %52, i64 2
%57 = load i32, i32* %56
%58 = getelementptr inbounds i32, i32* %52, i64 3
%59 = load i32, i32* %58
%60 = getelementptr inbounds i32, i32* %52, i64 4
%61 = load i32, i32* %60
%62 = getelementptr inbounds i32, i32* %52, i64 5
%63 = load i32, i32* %62
%64 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* %31, i32 %53, i32 %55, i32 %57, i32 %59, i32 %61, i32 %63)
%65 = add nuw nsw i64 %34, 1
%66 = icmp eq i64 %65, %32
br i1 %66, label %67, label %33
67: ; preds = %41, %21, %39, %19, %10
%68 = phi i32 [ 1, %10 ], [ 1, %19 ], [ 1, %39 ], [ 0, %21 ], [ 0, %41 ]
ret i32 %68
}