#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 */

/* Variables and functions */
scalar_t__ get_tlv_item(int, unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int get_mac(unsigned char mac[6]) {
  unsigned char buf[128], len;
  memset(buf, 0, 128);
  if (get_tlv_item(0x43, &len, buf) < 0) {
    printf("Get mac address fail\n");
    return -1;
  }
  if (len != 6) {
    printf("Mac address in TLV error\n");
    return -1;
  }
  memcpy(mac, buf, 6);
  return 0;
}


x86 assembly (clang, -O0):
<get_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x90(%rbp),%rdx
mov    $0x43,%edi
lea    -0x91(%rbp),%rsi
call   1030 <get_tlv_item@plt>
cmp    $0x0,%rax
jge    119c <get_mac+0x5c>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <get_mac+0xa0>
movzbl -0x91(%rbp),%eax
cmp    $0x6,%eax
je     11c4 <get_mac+0x84>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <get_mac+0xa0>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x6,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mac>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xf(%rsp),%rsi
mov    $0x43,%edi
mov    %rbx,%rdx
call   1040 <get_tlv_item@plt>
test   %rax,%rax
js     1195 <get_mac+0x55>
cmpb   $0x6,0xf(%rsp)
jne    119e <get_mac+0x5e>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   1060 <memcpy@plt>
xor    %eax,%eax
jmp    11af <get_mac+0x6f>
lea    0xe7d(%rip),%rdi
jmp    11a5 <get_mac+0x65>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Get mac address fail\0A\00"
@.str.1 = [26 x i8] c"Mac address in TLV error\0A\00"
define i32 @get_mac(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i8
store i8* %0, i8** %3
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 128)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = call i64 @get_tlv_item(i32 67, i8* %5, i8* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
13: ; preds = %1
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = icmp ne i32 %15, 6
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
19: ; preds = %13
%20 = load i8*, i8** %3
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%22 = call i32 @memcpy(i8* %20, i8* %21, i32 6)
store i32 0, i32* %2
br label %23
23: ; preds = %19, %17, %11
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@str = [25 x i8] c"Mac address in TLV error\00"
@str.2 = [21 x i8] c"Get mac address fail\00"
define i32 @get_mac(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 128)
%6 = call i64 @get_tlv_item(i32 67, i8* %3, i8* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.2, i64 0, i64 0))
br label %17
10: ; preds = %1
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 6
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %17
15: ; preds = %10
%16 = call i32 @memcpy(i8* %0, i8* %4, i32 6)
br label %17
17: ; preds = %15, %13, %8
%18 = phi i32 [ -1, %8 ], [ -1, %13 ], [ 0, %15 ]
ret i32 %18
}