#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifreq {
  char *ifr_name;
  int /*<<< orphan*/ ifr_addr;
};
struct ifconf {
  int ifc_len;
  char *ifc_buf;
  struct ifreq *ifc_req;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ get_all_interfaces(struct ifconf *);
scalar_t__ get_mac_address_by_if(char *, char *, int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char **argv) {
  char mac[18];
  char buf[1024];
  struct ifconf ifc;
  struct ifreq *ifr;
  int nInterfaces;
  int i;
  ifc.ifc_len = sizeof(buf);
  ifc.ifc_buf = buf;
  if (!get_all_interfaces(&ifc)) {
    return -1;
  }
  ifr = ifc.ifc_req;
  nInterfaces = ifc.ifc_len / sizeof(struct ifreq);
  for (i = 0; i < nInterfaces; i++) {
    struct ifreq *item = &ifr[i];
    printf("%s: IP %s", item->ifr_name,
           inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr));
    if (get_mac_address_by_if(item->ifr_name, mac, 18)) {
      printf(", MAC %s\n", mac);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x400,-0x448(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x448(%rbp),%rdi
call   1060 <get_all_interfaces@plt>
cmp    $0x0,%eax
jne    1192 <main+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <main+0x135>
mov    -0x438(%rbp),%rax
mov    %rax,-0x450(%rbp)
movslq -0x448(%rbp),%rax
shr    $0x4,%rax
mov    %eax,-0x454(%rbp)
movl   $0x0,-0x458(%rbp)
mov    -0x458(%rbp),%eax
cmp    -0x454(%rbp),%eax
jge    126e <main+0x12e>
mov    -0x450(%rbp),%rax
movslq -0x458(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x460(%rbp)
mov    -0x460(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x468(%rbp)
mov    -0x460(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x468(%rbp),%rsi
mov    %rax,%rdx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x460(%rbp),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x12,%edx
call   1050 <get_mac_address_by_if@plt>
cmp    $0x0,%rax
je     1255 <main+0x115>
lea    -0x30(%rbp),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125a <main+0x11a>
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    11bb <main+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
movl   $0x400,0x8(%rsp)
lea    0x40(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <get_all_interfaces@plt>
test   %eax,%eax
je     11f2 <main+0xb2>
mov    0x8(%rsp),%r13d
xor    %eax,%eax
cmp    $0x10,%r13d
jl     11fb <main+0xbb>
mov    0x18(%rsp),%rbp
and    $0xfffffff0,%r13d
lea    0xe6e(%rip),%r14
lea    0x20(%rsp),%r12
xor    %r15d,%r15d
jmp    11a9 <main+0x69>
nopl   0x0(%rax)
add    $0x10,%r15
cmp    %r15,%r13
je     11f9 <main+0xb9>
mov    0x0(%rbp,%r15,1),%rbx
mov    0x8(%rbp,%r15,1),%edi
call   1030 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp,%r15,1),%rdi
mov    %r12,%rsi
mov    $0x12,%edx
call   1050 <get_mac_address_by_if@plt>
test   %rax,%rax
je     11a0 <main+0x60>
lea    0xe24(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <main+0x60>
mov    $0xffffffff,%eax
jmp    11fb <main+0xbb>
xor    %eax,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifconf = type { i32, i8*, %struct.ifreq* }
%struct.ifreq = type { i8*, i32 }
%struct.sockaddr_in = type { i32 }
@.str = [10 x i8] c"%s: IP %s\00"
@.str.1 = [10 x i8] c", MAC %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [18 x i8]
%7 = alloca [1024 x i8]
%8 = alloca %struct.ifconf
%9 = alloca %struct.ifreq*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.ifreq*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %8, i32 0, i32 0
store i32 1024, i32* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %8, i32 0, i32 1
store i8* %14, i8** %15
%16 = call i32 @get_all_interfaces(%struct.ifconf* %8)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %2
store i32 -1, i32* %3
br label %60
19: ; preds = %2
%20 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %8, i32 0, i32 2
%21 = load %struct.ifreq*, %struct.ifreq** %20
store %struct.ifreq* %21, %struct.ifreq** %9
%22 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %8, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = udiv i64 %24, 16
%26 = trunc i64 %25 to i32
store i32 %26, i32* %10
store i32 0, i32* %11
br label %27
27: ; preds = %56, %19
%28 = load i32, i32* %11
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %59
31: ; preds = %27
%32 = load %struct.ifreq*, %struct.ifreq** %9
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %32, i64 %34
store %struct.ifreq* %35, %struct.ifreq** %12
%36 = load %struct.ifreq*, %struct.ifreq** %12
%37 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = load %struct.ifreq*, %struct.ifreq** %12
%40 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %39, i32 0, i32 1
%41 = bitcast i32* %40 to %struct.sockaddr_in*
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i8* @inet_ntoa(i32 %43)
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %44)
%46 = load %struct.ifreq*, %struct.ifreq** %12
%47 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%50 = call i64 @get_mac_address_by_if(i8* %48, i8* %49, i32 18)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %31
%53 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %31
br label %56
56: ; preds = %55
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %27
59: ; preds = %27
store i32 0, i32* %3
br label %60
60: ; preds = %59, %18
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
%struct.ifconf = type { i32, i8*, %struct.ifreq* }
%struct.ifreq = type { i8*, i32 }
@.str = [10 x i8] c"%s: IP %s\00"
@.str.1 = [10 x i8] c", MAC %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [18 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.ifconf
%6 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.ifconf* %5 to i8*
%9 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i64 0, i32 0
store i32 1024, i32* %9
%10 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i64 0, i32 1
store i8* %7, i8** %10
%11 = call i32 @get_all_interfaces(%struct.ifconf* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %37, label %13
13: ; preds = %2
%14 = getelementptr inbounds %struct.ifconf, %struct.ifconf* %5, i64 0, i32 2
%15 = load %struct.ifreq*, %struct.ifreq** %14
%16 = load i32, i32* %9
%17 = icmp sgt i32 %16, 15
br i1 %17, label %18, label %37
18: ; preds = %13
%19 = lshr i32 %16, 4
%20 = zext i32 %19 to i64
br label %21
21: ; preds = %18, %34
%22 = phi i64 [ 0, %18 ], [ %35, %34 ]
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %15, i64 %22, i32 0
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %15, i64 %22, i32 1
%26 = load i32, i32* %25
%27 = call i8* @inet_ntoa(i32 %26)
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %27)
%29 = load i8*, i8** %23
%30 = call i64 @get_mac_address_by_if(i8* %29, i8* %6, i32 18)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %21
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %34
34: ; preds = %32, %21
%35 = add nuw nsw i64 %22, 1
%36 = icmp eq i64 %35, %20
br i1 %36, label %37, label %21
37: ; preds = %34, %13, %2
%38 = phi i32 [ -1, %2 ], [ 0, %13 ], [ 0, %34 ]
ret i32 %38
}