#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 */
int get_hwaddr(char *, char *, int);
char *nvram_safe_get(char *);
int /*<<< orphan*/ printf(char *);
int snprintf(char *, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int get_lan_mac(char *lanhwaddr) {
  char ifname[16] = {0};
  char device[16] = {0};
  char hwaddr[64] = {0};
  int ret = -1;
  strcpy(ifname, nvram_safe_get("lan0_ifname"));
  if (!strncmp(ifname, "ppp", 3)) {
    if (snprintf(device, 16, "lan0_device") >= 16) {
      return -1;
    }
    strcpy(ifname, nvram_safe_get(device));
  }
  ret = get_hwaddr(ifname, hwaddr, 64);
  if (-1 == ret) {
    printf("ERROR: Get LAN MAC Error\n");
    return -1;
  } else {
    strcpy(lanhwaddr, hwaddr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_lan_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
movl   $0xffffffff,-0x74(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    0xe3b(%rip),%rdi
call   1080 <nvram_safe_get@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x20(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1241 <get_lan_mac+0xd1>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
lea    0xe0c(%rip),%rdx
call   1060 <snprintf@plt>
cmp    $0x10,%eax
jl     121e <get_lan_mac+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <get_lan_mac+0x120>
lea    -0x20(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <nvram_safe_get@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x20(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1090 <get_hwaddr@plt>
mov    %eax,-0x74(%rbp)
mov    $0xffffffff,%eax
cmp    -0x74(%rbp),%eax
jne    127c <get_lan_mac+0x10c>
lea    0xdb1(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <get_lan_mac+0x120>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lan_mac>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xe6f(%rip),%rdi
call   1070 <nvram_safe_get@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11f3 <get_lan_mac+0x93>
lea    0xe4d(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1060 <snprintf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xf,%ecx
jg     122c <get_lan_mac+0xcc>
lea    0x10(%rsp),%rdi
call   1070 <nvram_safe_get@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rdi
lea    0x20(%rsp),%rsi
mov    $0x40,%edx
call   1080 <get_hwaddr@plt>
cmp    $0xffffffff,%eax
je     121b <get_lan_mac+0xbb>
lea    0x20(%rsp),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
jmp    122c <get_lan_mac+0xcc>
lea    0xdfa(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"lan0_ifname\00"
@.str.1 = [4 x i8] c"ppp\00"
@.str.2 = [12 x i8] c"lan0_device\00"
@.str.3 = [26 x i8] c"ERROR: Get LAN MAC Error\0A\00"
define i32 @get_lan_mac(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [64 x i8]
%7 = alloca i32
store i8* %0, i8** %3
%8 = bitcast [16 x i8]* %4 to i8*
%9 = bitcast [16 x i8]* %5 to i8*
%10 = bitcast [64 x i8]* %6 to i8*
store i32 -1, i32* %7
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%12 = call i8* @nvram_safe_get(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%15 = call i32 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = icmp ne i32 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %1
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%19 = call i32 @snprintf(i8* %18, i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp sge i32 %19, 16
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %2
br label %40
22: ; preds = %17
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%25 = call i8* @nvram_safe_get(i8* %24)
%26 = call i32 @strcpy(i8* %23, i8* %25)
br label %27
27: ; preds = %22, %1
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%30 = call i32 @get_hwaddr(i8* %28, i8* %29, i32 64)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp eq i32 -1, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %40
35: ; preds = %27
%36 = load i8*, i8** %3
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %39
39: ; preds = %35
store i32 0, i32* %2
br label %40
40: ; preds = %39, %33, %21
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [12 x i8] c"lan0_ifname\00"
@.str.1 = [4 x i8] c"ppp\00"
@.str.2 = [12 x i8] c"lan0_device\00"
@str = [25 x i8] c"ERROR: Get LAN MAC Error\00"
define i32 @get_lan_mac(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca [16 x i8]
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = tail call i8* @nvram_safe_get(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strcpy(i8* %5, i8* %8)
%10 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = call i32 @snprintf(i8* %6, i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp sgt i32 %13, 15
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = call i8* @nvram_safe_get(i8* %6)
%17 = call i32 @strcpy(i8* %5, i8* %16)
br label %18
18: ; preds = %15, %1
%19 = call i32 @get_hwaddr(i8* %5, i8* %7, i32 64)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %25
23: ; preds = %18
%24 = call i32 @strcpy(i8* %0, i8* %7)
br label %25
25: ; preds = %12, %23, %21
%26 = phi i32 [ -1, %21 ], [ 0, %23 ], [ -1, %12 ]
ret i32 %26
}