#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 ether_addr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ *ether_aton_r(char const *, struct ether_addr *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, struct ether_addr *, int);
unsigned char *_link_aton(const char *ascaddr, int *maclen) {
  struct ether_addr addr;
  if (ether_aton_r(ascaddr, &addr) == NULL)
    return NULL;
  unsigned char *retaddr = malloc(sizeof(addr));
  if (!retaddr)
    return NULL;
  memcpy(retaddr, &addr, sizeof(addr));
  if (maclen)
    *maclen = sizeof(addr);
  return retaddr;
}


x86 assembly (clang, -O0):
<_link_aton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <ether_aton_r@plt>
cmp    $0x0,%rax
jne    1164 <_link_aton+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <_link_aton+0x89>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118a <_link_aton+0x5a>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <_link_aton+0x89>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     11b1 <_link_aton+0x81>
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_link_aton>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rsp,%rsi
call   1050 <ether_aton_r@plt>
test   %rax,%rax
je     1174 <_link_aton+0x44>
mov    $0x4,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1174 <_link_aton+0x44>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
test   %r14,%r14
je     1176 <_link_aton+0x46>
movl   $0x4,(%r14)
jmp    1176 <_link_aton+0x46>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ether_addr = type { i32 }
define i8* @_link_aton(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.ether_addr
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32* @ether_aton_r(i8* %8, %struct.ether_addr* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* null, i8** %3
br label %26
12: ; preds = %2
%13 = call i8* @malloc(i32 4)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %12
store i8* null, i8** %3
br label %26
17: ; preds = %12
%18 = load i8*, i8** %7
%19 = call i32 @memcpy(i8* %18, %struct.ether_addr* %6, i32 4)
%20 = load i32*, i32** %5
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i32*, i32** %5
store i32 4, i32* %23
br label %24
24: ; preds = %22, %17
%25 = load i8*, i8** %7
store i8* %25, i8** %3
br label %26
26: ; preds = %24, %16, %11
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
%struct.ether_addr = type { i32 }
define i8* @_link_aton(i8* %0, i32* writeonly %1) {
%3 = alloca %struct.ether_addr
%4 = bitcast %struct.ether_addr* %3 to i8*
%5 = call i32* @ether_aton_r(i8* %0, %struct.ether_addr* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = call dereferenceable_or_null(4) i8* @malloc(i32 4)
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = call i32 @memcpy(i8* %8, %struct.ether_addr* %3, i32 4)
%12 = icmp eq i32* %1, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i32 4, i32* %1
br label %14
14: ; preds = %7, %13, %10, %2
%15 = phi i8* [ null, %2 ], [ null, %7 ], [ %8, %13 ], [ %8, %10 ]
ret i8* %15
}