#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__ {
  char *sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
char *safe_strdup(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char, char, char, char, char,
                            char);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *get_iface_mac(char *ifname) {
  int r, s;
  struct ifreq ifr;
  char *hwaddr, mac[13];
  strcpy(ifr.ifr_name, ifname);
  s = socket(PF_INET, SOCK_DGRAM, 0);
  if (-1 == s) {
    _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/sxpert/wifidog-ffw/refs/heads/master/src/"
           "util.c",
           193, LOG_ERR, "get_iface_mac socket: %s", strerror(errno));
    return NULL;
  }
  r = ioctl(s, SIOCGIFHWADDR, &ifr);
  if (r == -1) {
    _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/sxpert/wifidog-ffw/refs/heads/master/src/"
           "util.c",
           199, LOG_ERR, "get_iface_mac ioctl(SIOCGIFHWADDR): %s",
           strerror(errno));
    close(s);
    return NULL;
  }
  hwaddr = ifr.ifr_hwaddr.sa_data;
  snprintf(mac, 13, "%02X%02X%02X%02X%02X%02X", hwaddr[0] & 0xFF,
           hwaddr[1] & 0xFF, hwaddr[2] & 0xFF, hwaddr[3] & 0xFF,
           hwaddr[4] & 0xFF, hwaddr[5] & 0xFF);
  close(s);
  return safe_strdup(mac);
}


x86 assembly (clang, -O0):
<get_iface_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    1207 <get_iface_mac+0x87>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edx
mov    %eax,%r8d
lea    0xe17(%rip),%rdi
mov    $0xc1,%esi
lea    0xe95(%rip),%rcx
call   1070 <_debug@plt>
movq   $0x0,-0x8(%rbp)
jmp    1326 <get_iface_mac+0x1a6>
mov    -0x18(%rbp),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1276 <get_iface_mac+0xf6>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edx
mov    %eax,%r8d
lea    0xdb0(%rip),%rdi
mov    $0xc7,%esi
lea    0xe47(%rip),%rcx
call   1070 <_debug@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1326 <get_iface_mac+0x1a6>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x3d(%rbp),%rdi
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xff,%eax
mov    %al,%r8b
mov    -0x30(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xff,%eax
mov    %al,%r9b
mov    -0x30(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
mov    %al,%r11b
mov    -0x30(%rbp),%rax
movsbl 0x4(%rax),%eax
and    $0xff,%eax
mov    %al,%r10b
mov    -0x30(%rbp),%rax
movsbl 0x5(%rax),%eax
and    $0xff,%eax
mov    $0xd,%esi
lea    0xde1(%rip),%rdx
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl %r9b,%r9d
movsbl %r11b,%r11d
mov    %r11d,(%rsp)
movsbl %r10b,%r10d
mov    %r10d,0x8(%rsp)
movsbl %al,%eax
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    -0x3d(%rbp),%rdi
call   1080 <safe_strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_iface_mac>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rsi
call   1030 <strcpy@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1220 <get_iface_mac+0xa0>
mov    %eax,%ebx
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1256 <get_iface_mac+0xd6>
mov    (%rsp),%rax
movsbl (%rax),%ecx
movsbl 0x1(%rax),%r8d
movsbl 0x2(%rax),%r9d
movsbl 0x3(%rax),%r10d
movsbl 0x4(%rax),%ebp
movsbl 0x5(%rax),%eax
sub    $0x8,%rsp
lea    0xed5(%rip),%rdx
lea    0x1b(%rsp),%r14
mov    %r14,%rdi
mov    $0xd,%esi
push   %rax
push   %rbp
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14,%rdi
call   1080 <safe_strdup@plt>
jmp    1293 <get_iface_mac+0x113>
mov    0x2d91(%rip),%rax
mov    (%rax),%ebx
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdc2(%rip),%rdi
lea    0xe45(%rip),%rcx
mov    $0xc1,%esi
mov    %ebx,%edx
mov    %eax,%r8d
call   1070 <_debug@plt>
jmp    1291 <get_iface_mac+0x111>
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebp
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd8c(%rip),%rdi
lea    0xe28(%rip),%rcx
mov    $0xc7,%esi
mov    %ebp,%edx
mov    %eax,%r8d
call   1070 <_debug@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/sxpert/wifidog-ffw/refs/heads/master/src/util.c\00"
@LOG_ERR = global i32 0
@.str.1 = [25 x i8] c"get_iface_mac socket: %s\00"
@errno = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.2 = [39 x i8] c"get_iface_mac ioctl(SIOCGIFHWADDR): %s\00"
@.str.3 = [25 x i8] c"%02X%02X%02X%02X%02X%02X\00"
define i8* @get_iface_mac(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.ifreq
%7 = alloca i8*
%8 = alloca [13 x i8]
store i8* %0, i8** %3
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%10 = load i32, i32* %9
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i32 %10, i8* %11)
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %23
18: ; preds = %1
%19 = load i32, i32* @LOG_ERR
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 193, i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i8* null, i8** %2
br label %82
23: ; preds = %1
%24 = load i32, i32* %5
%25 = load i32, i32* @SIOCGIFHWADDR
%26 = call i32 @ioctl(i32 %24, i32 %25, %struct.ifreq* %6)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load i32, i32* @LOG_ERR
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 199, i32 %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %5
%35 = call i32 @close(i32 %34)
store i8* null, i8** %2
br label %82
36: ; preds = %23
%37 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
%39 = load i8*, i8** %38
store i8* %39, i8** %7
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = and i32 %44, 255
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i64 2
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = and i32 %56, 255
%58 = trunc i32 %57 to i8
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = and i32 %62, 255
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %7
%66 = getelementptr inbounds i8, i8* %65, i64 4
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = and i32 %68, 255
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %7
%72 = getelementptr inbounds i8, i8* %71, i64 5
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = and i32 %74, 255
%76 = trunc i32 %75 to i8
%77 = call i32 @snprintf(i8* %40, i32 13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8 signext %46, i8 signext %52, i8 signext %58, i8 signext %64, i8 signext %70, i8 signext %76)
%78 = load i32, i32* %5
%79 = call i32 @close(i32 %78)
%80 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%81 = call i8* @safe_strdup(i8* %80)
store i8* %81, i8** %2
br label %82
82: ; preds = %36, %29, %18
%83 = load i8*, i8** %2
ret i8* %83
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/sxpert/wifidog-ffw/refs/heads/master/src/util.c\00"
@LOG_ERR = global i32 0
@.str.1 = [25 x i8] c"get_iface_mac socket: %s\00"
@errno = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.2 = [39 x i8] c"get_iface_mac ioctl(SIOCGIFHWADDR): %s\00"
@.str.3 = [25 x i8] c"%02X%02X%02X%02X%02X%02X\00"
define i8* @get_iface_mac(i8* %0) {
%2 = alloca %struct.ifreq
%3 = alloca [13 x i8]
%4 = bitcast %struct.ifreq* %2 to i8*
%5 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @strcpy(i32 undef, i8* %0)
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @LOG_ERR
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 193, i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %43
16: ; preds = %1
%17 = load i32, i32* @SIOCGIFHWADDR
%18 = call i32 @ioctl(i32 %9, i32 %17, %struct.ifreq* %2)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* @LOG_ERR
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 199, i32 %21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @close(i32 %9)
br label %43
26: ; preds = %16
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %28, i64 1
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %28, i64 2
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %28, i64 3
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %28, i64 4
%37 = load i8, i8* %36
%38 = getelementptr inbounds i8, i8* %28, i64 5
%39 = load i8, i8* %38
%40 = call i32 @snprintf(i8* %5, i32 13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8 signext %29, i8 signext %31, i8 signext %33, i8 signext %35, i8 signext %37, i8 signext %39)
%41 = call i32 @close(i32 %9)
%42 = call i8* @safe_strdup(i8* %5)
br label %43
43: ; preds = %26, %20, %11
%44 = phi i8* [ null, %11 ], [ null, %20 ], [ %42, %26 ]
ret i8* %44
}