#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 */
struct TYPE_3__ {
  int /*<<< orphan*/ *sa_data;
};
struct TYPE_4__ {
  TYPE_1__ ifru_hwaddr;
};
typedef struct ifreq {
  int ifc_len;
  char *ifc_buf;
  char *ifr_name;
  int ifr_flags;
  TYPE_2__ ifr_ifru;
  struct ifreq const *ifc_req;
} const ifreq;
typedef struct ifconf {
  int ifc_len;
  char *ifc_buf;
  char *ifr_name;
  int ifr_flags;
  TYPE_2__ ifr_ifru;
  struct ifconf const *ifc_req;
} const ifconf;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int IFF_LOOPBACK;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ SIOCGIFCONF;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int ioctl(int, int /*<<< orphan*/, struct ifreq const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char, unsigned char,
                            unsigned char, unsigned char, unsigned char,
                            unsigned char);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  struct ifreq ifr;
  struct ifconf ifc;
  char buf[2048];
  int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
  if (sock == -1) {
    printf("socket error\n");
    return -1;
  }
  ifc.ifc_len = sizeof(buf);
  ifc.ifc_buf = buf;
  if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) {
    printf("ioctl error\n");
    return -1;
  }
  struct ifreq *it = ifc.ifc_req;
  const struct ifreq *const end = it + (ifc.ifc_len / sizeof(struct ifreq));
  char szMac[64];
  int count = 0;
  for (; it != end; ++it) {
    strcpy(ifr.ifr_name, it->ifr_name);
    if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
      if (!(ifr.ifr_flags & IFF_LOOPBACK)) {
        if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
          count++;
          unsigned char *ptr;
          ptr = (unsigned char *)&ifr.ifr_ifru.ifru_hwaddr.sa_data[0];
          snprintf(szMac, 64, "%02X:%02X:%02X:%02X:%02X:%02X", *ptr, *(ptr + 1),
                   *(ptr + 2), *(ptr + 3), *(ptr + 4), *(ptr + 5));
          printf("%d,Interface name : %s , Mac address : %s \n", count,
                 ifr.ifr_name, szMac);
        }
      }
    } else {
      printf("get mac info error\n");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x900,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x874(%rbp)
cmpl   $0xffffffff,-0x874(%rbp)
jne    11af <main+0x5f>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bc <main+0x26c>
movl   $0x800,-0x68(%rbp)
lea    -0x870(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x874(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11fc <main+0xac>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bc <main+0x26c>
mov    -0x40(%rbp),%rax
mov    %rax,-0x880(%rbp)
mov    -0x880(%rbp),%rax
mov    %rax,-0x8e8(%rbp)
movslq -0x68(%rbp),%rax
mov    $0x30,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x8e8(%rbp),%rax
imul   $0x30,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x888(%rbp)
movl   $0x0,-0x8d4(%rbp)
mov    -0x880(%rbp),%rax
cmp    -0x888(%rbp),%rax
je     13b5 <main+0x265>
mov    -0x28(%rbp),%rdi
mov    -0x880(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x874(%rbp),%edi
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%eax
jne    137f <main+0x22f>
mov    -0x20(%rbp),%eax
mov    0x2d60(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    137a <main+0x22a>
mov    -0x874(%rbp),%edi
mov    0x2d08(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%eax
jne    1375 <main+0x225>
mov    -0x8d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8d4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8e0(%rbp)
lea    -0x8d0(%rbp),%rdi
mov    -0x8e0(%rbp),%rax
mov    (%rax),%cl
mov    -0x8e0(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x8e0(%rbp),%rax
mov    0x2(%rax),%r9b
mov    -0x8e0(%rbp),%rax
mov    0x3(%rax),%r11b
mov    -0x8e0(%rbp),%rax
mov    0x4(%rax),%r10b
mov    -0x8e0(%rbp),%rax
mov    $0x40,%esi
lea    0xcee(%rip),%rdx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r11b,%r11d
mov    %r11d,(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x8(%rsp)
movzbl 0x5(%rax),%eax
mov    %eax,0x10(%rsp)
call   1050 <snprintf@plt>
mov    -0x8d4(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    -0x8d0(%rbp),%rcx
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    137a <main+0x22a>
jmp    1399 <main+0x249>
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bc <main+0x26c>
jmp    139e <main+0x24e>
mov    -0x880(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x880(%rbp)
jmp    1245 <main+0xf5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x900,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x838,%rsp
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
cmp    $0xffffffff,%eax
je     1191 <main+0x61>
movl   $0x800,(%rsp)
lea    0x30(%rsp),%rcx
mov    %rcx,0x8(%rsp)
mov    0x2e54(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1040 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     119a <main+0x6a>
add    $0x838,%rsp
ret
lea    0xe74(%rip),%rdi
jmp    11a1 <main+0x71>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x838,%rsp
ret

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

LLVM IR (-O2):
%struct.ifconf = type { i32, i8*, i8*, i32, %struct.TYPE_4__, %struct.ifconf* }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32* }
%struct.ifreq = type { i32, i8*, i8*, i32, %struct.TYPE_4__, %struct.ifreq* }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@SIOCGIFCONF = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_LOOPBACK = global i32 0
@SIOCGIFHWADDR = global i32 0
@str.5 = [12 x i8] c"ioctl error\00"
@str.6 = [13 x i8] c"socket error\00"
define i32 @main() {
%1 = alloca %struct.ifconf
%2 = alloca [2048 x i8]
%3 = bitcast %struct.ifconf* %1 to i8*
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = load i32, i32* @IPPROTO_IP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %24
12: ; preds = %0
%13 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %1, i64 0, i32 0
store i32 2048, i32* %13
%14 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %1, i64 0, i32 1
store i8* %4, i8** %14
%15 = load i32, i32* @SIOCGIFCONF
%16 = bitcast %struct.ifconf* %1 to %struct.ifreq*
%17 = call i32 @ioctl(i32 %8, i32 %15, %struct.ifreq* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %24
21: ; preds = %12
%22 = load i32, i32* %13
%23 = icmp ult i32 %22, 48
br label %24
24: ; preds = %21, %19, %10
%25 = phi i32 [ -1, %10 ], [ -1, %19 ], [ 0, %21 ]
ret i32 %25
}