#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int get_Product_mac(unsigned char *mac) {
  char buffer[128];
  FILE *read_fp;
  int chars_read;
  int ret = -1;
  if (mac == NULL) {
    printf("mac NULL error \n");
    return -1;
  }
  memset(buffer, 0, sizeof(buffer));
  read_fp = popen("cfg get mac", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), sizeof(buffer) - 1, read_fp);
    if (chars_read > 0) {
      printf("%s", buffer);
      if ((buffer[0] == 'm') && (buffer[1] == 'a') && (buffer[2] == 'c') &&
          (buffer[3] == '=')) {
        memcpy(mac, &buffer[4], 12);
        ret = 0;
      } else {
        ret = -1;
      }
    } else {
      ret = -1;
    }
    pclose(read_fp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_Product_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0xa0(%rbp)
ff ff ff
cmpq   $0x0,-0x10(%rbp)
jne    119e <get_Product_mac+0x3e>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <get_Product_mac+0x154>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe59(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     12ab <get_Product_mac+0x14b>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7f,%edx
call   1030 <fread@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
jle    1295 <get_Product_mac+0x135>
lea    -0x90(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x90(%rbp),%eax
cmp    $0x6d,%eax
jne    1286 <get_Product_mac+0x126>
movsbl -0x8f(%rbp),%eax
cmp    $0x61,%eax
jne    1286 <get_Product_mac+0x126>
movsbl -0x8e(%rbp),%eax
cmp    $0x63,%eax
jne    1286 <get_Product_mac+0x126>
movsbl -0x8d(%rbp),%eax
cmp    $0x3d,%eax
jne    1286 <get_Product_mac+0x126>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
add    $0x4,%rsi
mov    $0xc,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0xa0(%rbp)
jmp    1290 <get_Product_mac+0x130>
movl   $0xffffffff,-0xa0(%rbp)
ff ff ff
jmp    129f <get_Product_mac+0x13f>
movl   $0xffffffff,-0xa0(%rbp)
ff ff ff
mov    -0x98(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0xa0(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_Product_mac>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
test   %rdi,%rdi
je     120e <get_Product_mac+0x9e>
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    0xe63(%rip),%rdi
lea    0xe68(%rip),%rsi
call   1090 <popen@plt>
test   %rax,%rax
je     121a <get_Product_mac+0xaa>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x7f,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jle    1204 <get_Product_mac+0x94>
lea    0xe38(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movdqa (%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x3d63616d,%eax
jne    1204 <get_Product_mac+0x94>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
mov    $0xc,%edx
call   1080 <memcpy@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1060 <pclose@plt>
jmp    121f <get_Product_mac+0xaf>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"mac NULL error \0A\00"
@.str.1 = [12 x i8] c"cfg get mac\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @get_Product_mac(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %7
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %58
12: ; preds = %1
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 128)
%15 = call i32* @popen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %56
18: ; preds = %12
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32 @fread(i8* %19, i32 1, i32 127, i32* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %52
24: ; preds = %18
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 109
br i1 %30, label %31, label %50
31: ; preds = %24
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 97
br i1 %35, label %36, label %50
36: ; preds = %31
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 99
br i1 %40, label %41, label %50
41: ; preds = %36
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 3
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 61
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i8*, i8** %3
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 4
%49 = call i32 @memcpy(i8* %47, i8* %48, i32 12)
store i32 0, i32* %7
br label %51
50: ; preds = %41, %36, %31, %24
store i32 -1, i32* %7
br label %51
51: ; preds = %50, %46
br label %53
52: ; preds = %18
store i32 -1, i32* %7
br label %53
53: ; preds = %52, %51
%54 = load i32*, i32** %5
%55 = call i32 @pclose(i32* %54)
br label %56
56: ; preds = %53, %12
%57 = load i32, i32* %7
store i32 %57, i32* %2
br label %58
58: ; preds = %56, %10
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"cfg get mac\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [16 x i8] c"mac NULL error \00"
define i32 @get_Product_mac(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %27
7: ; preds = %1
%8 = call i32 @memset(i8* %3, i32 0, i32 128)
%9 = call i32* @popen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %27, label %11
11: ; preds = %7
%12 = call i32 @fread(i8* %3, i32 1, i32 127, i32* %9)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%16 = bitcast [128 x i8]* %2 to <4 x i8>*
%17 = load <4 x i8>, <4 x i8>* %16
%18 = freeze <4 x i8> %17
%19 = bitcast <4 x i8> %18 to i32
%20 = icmp eq i32 %19, 1029923181
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 4
%23 = call i32 @memcpy(i8* %0, i8* %22, i32 12)
br label %24
24: ; preds = %11, %14, %21
%25 = phi i32 [ 0, %21 ], [ -1, %14 ], [ -1, %11 ]
%26 = call i32 @pclose(i32* %9)
br label %27
27: ; preds = %7, %24, %5
%28 = phi i32 [ -1, %5 ], [ %25, %24 ], [ -1, %7 ]
ret i32 %28
}