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

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ free(struct ifreq *);
scalar_t__ if_IOCTL(struct ifreq *, int /*<<< orphan*/, char *);
struct ifreq *malloc(int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int get_MAC_addr(char *MAC_addr, char *name) {
  int ret;
  struct ifreq *if_req;
  if_req = malloc(sizeof(struct ifreq));
  if (if_IOCTL(if_req, SIOCGIFHWADDR, name)) {
    return ret;
  }
  memcpy(MAC_addr, if_req->ifr_hwaddr.sa_data, 6);
  free(if_req);
  return 0;
}


x86 assembly (clang, -O0):
<get_MAC_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1060 <if_IOCTL@plt>
cmp    $0x0,%rax
je     1189 <get_MAC_addr+0x49>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <get_MAC_addr+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_MAC_addr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1060 <if_IOCTL@plt>
test   %rax,%rax
jne    1188 <get_MAC_addr+0x48>
mov    (%rbx),%esi
mov    %r14,%rdi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@SIOCGIFHWADDR = global i32 0
define i32 @get_MAC_addr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.ifreq*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call %struct.ifreq* @malloc(i32 4)
store %struct.ifreq* %8, %struct.ifreq** %7
%9 = load %struct.ifreq*, %struct.ifreq** %7
%10 = load i32, i32* @SIOCGIFHWADDR
%11 = load i8*, i8** %5
%12 = call i64 @if_IOCTL(%struct.ifreq* %9, i32 %10, i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %25
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load %struct.ifreq*, %struct.ifreq** %7
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %18, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @memcpy(i8* %17, i32 %21, i32 6)
%23 = load %struct.ifreq*, %struct.ifreq** %7
%24 = call i32 @free(%struct.ifreq* %23)
store i32 0, i32* %3
br label %25
25: ; preds = %16, %14
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@SIOCGIFHWADDR = global i32 0
define i32 @get_MAC_addr(i8* %0, i8* %1) {
%3 = tail call %struct.ifreq* @malloc(i32 4)
%4 = load i32, i32* @SIOCGIFHWADDR
%5 = tail call i64 @if_IOCTL(%struct.ifreq* %3, i32 %4, i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @memcpy(i8* %0, i32 %9, i32 6)
%11 = tail call i32 @free(%struct.ifreq* %3)
br label %12
12: ; preds = %2, %7
ret i32 0
}