#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 */
typedef int /*<<< orphan*/ uint8_t;
struct TYPE_2__ {
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  TYPE_1__ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ ETHER_ADDR_LEN;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(scalar_t__);
ssize_t mac_get_from_dev(char *dev_name, uint8_t *mac) {
  struct ifreq ifr;
  int sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
  if (!(sd != -1)) {
    fprintf(stderr,
            "[ERROR] (%s:%d: errno: %s) "
            "socket() failed"
            "\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/anryko/daft-dhcp-client/refs/heads/"
            "master/daft-dhcp-client.c",
            115, (errno == 0 ? "None" : strerror(errno)));
    errno = 0;
    goto error;
  };
  strcpy(ifr.ifr_name, dev_name);
  ssize_t rc = ioctl(sd, SIOCGIFHWADDR, &ifr);
  close(sd);
  if (!(rc == 0)) {
    fprintf(stderr,
            "[ERROR] (%s:%d: errno: %s) "
            "ioctl(SIOCGIFHWADDR) failed"
            "\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/anryko/daft-dhcp-client/refs/heads/"
            "master/daft-dhcp-client.c",
            120, (errno == 0 ? "None" : strerror(errno)));
    errno = 0;
    goto error;
  };
  memcpy(mac, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN);
  return 0;
error:
  return -1;
}


x86 assembly (clang, -O0):
<mac_get_from_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    121f <mac_get_from_dev+0xaf>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2df8(%rip),%rax
cmpq   $0x0,(%rax)
jne    11da <mac_get_from_dev+0x6a>
lea    0xef2(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11ed <mac_get_from_dev+0x7d>
mov    0x2dd7(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x40(%rbp),%r8
lea    0xe05(%rip),%rsi
lea    0xe2a(%rip),%rdx
mov    $0x73,%ecx
call   1060 <fprintf@plt>
mov    0x2da5(%rip),%rax
movq   $0x0,(%rax)
jmp    12eb <mac_get_from_dev+0x17b>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
cmpq   $0x0,-0x30(%rbp)
je     12c9 <mac_get_from_dev+0x159>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d4e(%rip),%rax
cmpq   $0x0,(%rax)
jne    1284 <mac_get_from_dev+0x114>
lea    0xe48(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1297 <mac_get_from_dev+0x127>
mov    0x2d2d(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x50(%rbp),%r8
lea    0xe23(%rip),%rsi
lea    0xd80(%rip),%rdx
mov    $0x78,%ecx
call   1060 <fprintf@plt>
mov    0x2cfb(%rip),%rax
movq   $0x0,(%rax)
jmp    12eb <mac_get_from_dev+0x17b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
call   1070 <memcpy@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f3 <mac_get_from_dev+0x183>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mac_get_from_dev>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11f3 <mac_get_from_dev+0x83>
mov    %eax,%ebp
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <close@plt>
test   %rbx,%rbx
je     1215 <mac_get_from_dev+0xa5>
mov    0x2de8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     122e <mac_get_from_dev+0xbe>
call   1080 <strerror@plt>
mov    %rax,%r8
jmp    1235 <mac_get_from_dev+0xc5>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ebx
mov    0x2db5(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     124c <mac_get_from_dev+0xdc>
call   1080 <strerror@plt>
mov    %rax,%r8
jmp    1253 <mac_get_from_dev+0xe3>
mov    0x8(%rsp),%esi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1070 <memcpy@plt>
xor    %eax,%eax
jmp    1282 <mac_get_from_dev+0x112>
lea    0xe8e(%rip),%r8
lea    0xe8c(%rip),%rsi
lea    0xde9(%rip),%rdx
mov    %ebx,%edi
mov    $0x78,%ecx
jmp    1268 <mac_get_from_dev+0xf8>
lea    0xe70(%rip),%r8
lea    0xda6(%rip),%rsi
lea    0xdcb(%rip),%rdx
mov    %ebx,%edi
mov    $0x73,%ecx
call   1060 <fprintf@plt>
mov    0x2d44(%rip),%rax
movq   $0x0,(%rax)
mov    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"[ERROR] (%s:%d: errno: %s) socket() failed\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/anryko/daft-dhcp-client/refs/heads/master/daft-dhcp-client.c\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"None\00"
@SIOCGIFHWADDR = global i32 0
@.str.3 = [56 x i8] c"[ERROR] (%s:%d: errno: %s) ioctl(SIOCGIFHWADDR) failed\0A\00"
@ETHER_ADDR_LEN = global i32 0
define i64 @mac_get_from_dev(i8* %0, i32* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.ifreq
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_IP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %26, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %23
20: ; preds = %15
%21 = load i64, i64* @errno
%22 = call i8* @strerror(i64 %21)
br label %23
23: ; preds = %20, %19
%24 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %19 ], [ %22, %20 ]
%25 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 115, i8* %24)
store i64 0, i64* @errno
br label %56
26: ; preds = %2
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%28 = load i32, i32* %27
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i32 %28, i8* %29)
%31 = load i32, i32* %7
%32 = load i32, i32* @SIOCGIFHWADDR
%33 = call i64 @ioctl(i32 %31, i32 %32, %struct.ifreq* %6)
store i64 %33, i64* %8
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
%36 = load i64, i64* %8
%37 = icmp eq i64 %36, 0
br i1 %37, label %49, label %38
38: ; preds = %26
%39 = load i32, i32* @stderr
%40 = load i64, i64* @errno
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
br label %46
43: ; preds = %38
%44 = load i64, i64* @errno
%45 = call i8* @strerror(i64 %44)
br label %46
46: ; preds = %43, %42
%47 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %42 ], [ %45, %43 ]
%48 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 120, i8* %47)
store i64 0, i64* @errno
br label %56
49: ; preds = %26
%50 = load i32*, i32** %5
%51 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = load i32, i32* @ETHER_ADDR_LEN
%55 = call i32 @memcpy(i32* %50, i32 %53, i32 %54)
store i64 0, i64* %3
br label %57
56: ; preds = %46, %23
store i64 -1, i64* %3
br label %57
57: ; preds = %56, %49
%58 = load i64, i64* %3
ret i64 %58
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"[ERROR] (%s:%d: errno: %s) socket() failed\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/anryko/daft-dhcp-client/refs/heads/master/daft-dhcp-client.c\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"None\00"
@SIOCGIFHWADDR = global i32 0
@.str.3 = [56 x i8] c"[ERROR] (%s:%d: errno: %s) ioctl(SIOCGIFHWADDR) failed\0A\00"
@ETHER_ADDR_LEN = global i32 0
define i64 @mac_get_from_dev(i8* %0, i32* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @PF_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 %19
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i8* @strerror(i64 %12)
br label %16
16: ; preds = %10, %14
%17 = phi i8* [ %15, %14 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %10 ]
%18 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 115, i8* %17)
br label %39
19: ; preds = %2
%20 = tail call i32 @strcpy(i32 undef, i8* %0)
%21 = load i32, i32* @SIOCGIFHWADDR
%22 = call i64 @ioctl(i32 %8, i32 %21, %struct.ifreq* %3)
%23 = call i32 @close(i32 %8)
%24 = icmp eq i64 %22, 0
br i1 %24, label %34, label %25
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i64, i64* @errno
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i8* @strerror(i64 %27)
br label %31
31: ; preds = %25, %29
%32 = phi i8* [ %30, %29 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %25 ]
%33 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 120, i8* %32)
br label %39
34: ; preds = %19
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i32, i32* @ETHER_ADDR_LEN
%38 = call i32 @memcpy(i32* %1, i32 %36, i32 %37)
br label %40
39: ; preds = %31, %16
store i64 0, i64* @errno
br label %40
40: ; preds = %39, %34
%41 = phi i64 [ 0, %34 ], [ -1, %39 ]
ret i64 %41
}