#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 */
typedef int /*<<< orphan*/ uint8_t;
struct ifaddrs {
  char *ifa_name;
  int /*<<< orphan*/ *ifa_addr;
  struct ifaddrs *ifa_next;
};
typedef int /*<<< orphan*/ mac_addr_one;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeifaddrs(struct ifaddrs *);
int /*<<< orphan*/ get_mac_by_ifname(char *, int /*<<< orphan*/ *);
int getifaddrs(struct ifaddrs **);
scalar_t__ memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct ifaddrs *ifaddr, *ifa;
  int family, s, n;
  char host[NI_MAXHOST];
  uint8_t mac_addr_one[6];
  uint8_t mac_addr_two[6];
  if (argc < 2) {
    printf("    usage: mac2ifname MAC_ADDRESS\n");
    return -1;
  }
  n = sscanf(argv[1], "%x:%x:%x:%x:%x:%x", &mac_addr_one[0], &mac_addr_one[1],
             &mac_addr_one[2], &mac_addr_one[3], &mac_addr_one[4],
             &mac_addr_one[5]);
  if (n != 6) {
    printf("    invalid MAC address %s\n", argv[1]);
    return -1;
  }
  if (getifaddrs(&ifaddr) == -1) {
    perror("getifaddrs");
    exit(EXIT_FAILURE);
  }
  for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
    if (ifa->ifa_addr == NULL)
      continue;
    get_mac_by_ifname(ifa->ifa_name, mac_addr_two);
    if (memcmp(mac_addr_one, mac_addr_two, sizeof(mac_addr_one)) == 0) {
      printf("%s\n", ifa->ifa_name);
      freeifaddrs(ifaddr);
      return 0;
    }
  }
  freeifaddrs(ifaddr);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11db <main+0x5b>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    1358 <main+0x1d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x60(%rbp),%rcx
add    $0x4,%rcx
lea    -0x60(%rbp),%r8
add    $0x8,%r8
lea    -0x60(%rbp),%r9
add    $0xc,%r9
lea    -0x60(%rbp),%r10
add    $0x10,%r10
lea    -0x60(%rbp),%rax
add    $0x14,%rax
lea    0xe0d(%rip),%rsi
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,-0x2c(%rbp)
cmpl   $0x6,-0x2c(%rbp)
je     1265 <main+0xe5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    1358 <main+0x1d8>
lea    -0x18(%rbp),%rdi
call   1050 <getifaddrs@plt>
cmp    $0xffffffff,%eax
jne    1291 <main+0x111>
lea    0xdd3(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     133e <main+0x1be>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12bf <main+0x13f>
jmp    1324 <main+0x1a4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x80(%rbp),%rsi
call   10a0 <get_mac_by_ifname@plt>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x18,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    131f <main+0x19f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <freeifaddrs@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    1358 <main+0x1d8>
jmp    1324 <main+0x1a4>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a0 <main+0x120>
mov    -0x18(%rbp),%rdi
call   1070 <freeifaddrs@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsp,%r15
cmp    $0x1,%edi
jg     11b4 <main+0x24>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
jmp    1288 <main+0xf8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x20(%rsp),%r10
lea    0x24(%rsp),%rax
lea    0xe25(%rip),%rsi
lea    0x10(%rsp),%rdx
push   %rax
push   %r10
call   1070 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    1266 <main+0xd6>
lea    0x8(%rsp),%rdi
call   1060 <getifaddrs@plt>
cmp    $0xffffffff,%eax
je     129c <main+0x10c>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1281 <main+0xf1>
lea    0x30(%rsp),%r12
lea    0x10(%rsp),%r14
jmp    1229 <main+0x99>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     127a <main+0xea>
cmpq   $0x0,0x8(%rbx)
je     1220 <main+0x90>
mov    (%rbx),%rdi
mov    %r12,%rsi
call   10b0 <get_mac_by_ifname@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x18,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1220 <main+0x90>
mov    (%rbx),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1080 <freeifaddrs@plt>
xor    %eax,%eax
jmp    128d <main+0xfd>
mov    0x8(%rbx),%rsi
lea    0xda1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1288 <main+0xf8>
mov    0x8(%rsp),%rdi
jmp    1283 <main+0xf3>
xor    %edi,%edi
call   1080 <freeifaddrs@plt>
mov    $0xffffffff,%eax
mov    %r15,%rsp
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd8b(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.ifaddrs = type { i8*, i32*, %struct.ifaddrs* }
@NI_MAXHOST = global i32 0
@.str = [35 x i8] c" usage: mac2ifname MAC_ADDRESS\0A\00"
@.str.1 = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.2 = [28 x i8] c" invalid MAC address %s\0A\00"
@.str.3 = [11 x i8] c"getifaddrs\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ifaddrs*
%7 = alloca %struct.ifaddrs*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca [6 x i32]
%14 = alloca [6 x i32]
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @NI_MAXHOST
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %11
%19 = alloca i8, i64 %17
store i64 %17, i64* %12
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %15
br label %87
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 0
%29 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 1
%30 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 2
%31 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 3
%32 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 4
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 5
%34 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32* %28, i32* %29, i32* %30, i32* %31, i32* %32, i32* %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp ne i32 %35, 6
br i1 %36, label %37, label %42
37: ; preds = %24
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %40)
store i32 -1, i32* %3
store i32 1, i32* %15
br label %87
42: ; preds = %24
%43 = call i32 @getifaddrs(%struct.ifaddrs** %6)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
%50 = load %struct.ifaddrs*, %struct.ifaddrs** %6
store %struct.ifaddrs* %50, %struct.ifaddrs** %7
store i32 0, i32* %10
br label %51
51: ; preds = %78, %49
%52 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%53 = icmp ne %struct.ifaddrs* %52, null
br i1 %53, label %54, label %84
54: ; preds = %51
%55 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%56 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %55, i32 0, i32 1
%57 = load i32*, i32** %56
%58 = icmp eq i32* %57, null
br i1 %58, label %59, label %60
59: ; preds = %54
br label %78
60: ; preds = %54
%61 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%62 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %61, i32 0, i32 0
%63 = load i8*, i8** %62
%64 = getelementptr inbounds [6 x i32], [6 x i32]* %14, i64 0, i64 0
%65 = call i32 @get_mac_by_ifname(i8* %63, i32* %64)
%66 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 0
%67 = getelementptr inbounds [6 x i32], [6 x i32]* %14, i64 0, i64 0
%68 = call i64 @memcmp(i32* %66, i32* %67, i32 24)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %60
%71 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%72 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %71, i32 0, i32 0
%73 = load i8*, i8** %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %73)
%75 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%76 = call i32 @freeifaddrs(%struct.ifaddrs* %75)
store i32 0, i32* %3
store i32 1, i32* %15
br label %87
77: ; preds = %60
br label %78
78: ; preds = %77, %59
%79 = load %struct.ifaddrs*, %struct.ifaddrs** %7
%80 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %79, i32 0, i32 2
%81 = load %struct.ifaddrs*, %struct.ifaddrs** %80
store %struct.ifaddrs* %81, %struct.ifaddrs** %7
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
br label %51
84: ; preds = %51
%85 = load %struct.ifaddrs*, %struct.ifaddrs** %6
%86 = call i32 @freeifaddrs(%struct.ifaddrs* %85)
store i32 -1, i32* %3
store i32 1, i32* %15
br label %87
87: ; preds = %84, %70, %37, %22
%88 = load i8*, i8** %11
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, i32*, %struct.ifaddrs* }
@NI_MAXHOST = global i32 0
@.str.1 = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.2 = [28 x i8] c" invalid MAC address %s\0A\00"
@.str.3 = [11 x i8] c"getifaddrs\00"
@EXIT_FAILURE = global i32 0
@str = [34 x i8] c" usage: mac2ifname MAC_ADDRESS\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifaddrs*
%4 = alloca [6 x i32]
%5 = alloca [6 x i32]
%6 = bitcast %struct.ifaddrs** %3 to i8*
%7 = tail call i8* @llvm.stacksave()
%8 = bitcast [6 x i32]* %4 to i8*
%9 = bitcast [6 x i32]* %5 to i8*
%10 = icmp slt i32 %0, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %65
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%20 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%22 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32* %16, i32* %17, i32* %18, i32* %19, i32* %20, i32* %21)
%23 = icmp eq i32 %22, 6
br i1 %23, label %27, label %24
24: ; preds = %13
%25 = load i8*, i8** %14
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %65
27: ; preds = %13
%28 = call i32 @getifaddrs(%struct.ifaddrs** %3)
%29 = icmp eq i32 %28, -1
br i1 %29, label %35, label %30
30: ; preds = %27
%31 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%32 = icmp eq %struct.ifaddrs* %31, null
br i1 %32, label %62, label %33
33: ; preds = %30
%34 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
br label %39
35: ; preds = %27
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %33, %56
%40 = phi %struct.ifaddrs* [ %31, %33 ], [ %58, %56 ]
%41 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %40, i64 0, i32 1
%42 = load i32*, i32** %41
%43 = icmp eq i32* %42, null
br i1 %43, label %56, label %44
44: ; preds = %39
%45 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %40, i64 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @get_mac_by_ifname(i8* %46, i32* %34)
%48 = call i64 @memcmp(i32* %16, i32* %34, i32 24)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %44
%51 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %40, i64 0, i32 0
%52 = load i8*, i8** %51
%53 = call i32 @puts(i8* dereferenceable(1) %52)
%54 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%55 = call i32 @freeifaddrs(%struct.ifaddrs* %54)
br label %65
56: ; preds = %44, %39
%57 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %40, i64 0, i32 2
%58 = load %struct.ifaddrs*, %struct.ifaddrs** %57
%59 = icmp eq %struct.ifaddrs* %58, null
br i1 %59, label %60, label %39
60: ; preds = %56
%61 = load %struct.ifaddrs*, %struct.ifaddrs** %3
br label %62
62: ; preds = %60, %30
%63 = phi %struct.ifaddrs* [ %61, %60 ], [ null, %30 ]
%64 = call i32 @freeifaddrs(%struct.ifaddrs* %63)
br label %65
65: ; preds = %62, %50, %24, %11
%66 = phi i32 [ -1, %11 ], [ -1, %24 ], [ 0, %50 ], [ -1, %62 ]
ret i32 %66
}