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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
char *strtok(char *, char *);
int get_mac_address(char *mac, int mac_len) {
  char tmp[64] = {0}, *tmp_str;
  char target[] = ":";
  FILE *file;
  if ((file = fopen("/proc/ezp_machine_id", "r"))) {
    fgets(tmp, sizeof(tmp), file);
    tmp[17] = '\0';
    tmp_str = strtok(tmp, target);
    sprintf(mac, "%s", tmp_str);
    while (tmp_str != NULL) {
      tmp_str = strtok(NULL, target);
      if (tmp_str != NULL)
        sprintf(mac, "%s%s", mac, tmp_str);
    }
    return 0;
  } else {
    return (-300 - 2);
  }
}


x86 assembly (clang, -O0):
<get_mac_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
mov    0xe87(%rip),%ax
mov    %ax,-0x6a(%rbp)
lea    0xe7e(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     122d <get_mac_address+0xdd>
lea    -0x60(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x40,%esi
call   1040 <fgets@plt>
movb   $0x0,-0x4f(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x6a(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x68(%rbp),%rdx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
cmpq   $0x0,-0x68(%rbp)
je     1221 <get_mac_address+0xd1>
lea    -0x6a(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     121c <get_mac_address+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x68(%rbp),%rcx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    11db <get_mac_address+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    1234 <get_mac_address+0xe4>
movl   $0xfffffed2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mac_address>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x3a,0xe(%rsp)
lea    0xe7d(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1226 <get_mac_address+0xd6>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
movb   $0x0,0x21(%rsp)
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
test   %rbx,%rbx
je     122d <get_mac_address+0xdd>
xor    %ebx,%ebx
lea    0xe(%rsp),%rsi
xor    %edi,%edi
call   1060 <strtok@plt>
test   %rax,%rax
je     122f <get_mac_address+0xdf>
lea    0xe2b(%rip),%r15
lea    0xe(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1200 <get_mac_address+0xb0>
jmp    122f <get_mac_address+0xdf>
mov    $0xfffffed2,%ebx
jmp    122f <get_mac_address+0xdf>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.get_mac_address.target = [2 x i8] c":\00"
@.str = [21 x i8] c"/proc/ezp_machine_id\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"%s%s\00"
define i32 @get_mac_address(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i8*
%8 = alloca [2 x i8]
%9 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = bitcast [64 x i8]* %6 to i8*
%11 = bitcast [2 x i8]* %8 to i8*
%12 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %9
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %40
14: ; preds = %2
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %9
%17 = call i32 @fgets(i8* %15, i32 64, i32* %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 17
store i8 0, i8* %18
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%21 = call i8* @strtok(i8* %19, i8* %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %4
%23 = load i8*, i8** %7
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %38, %14
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%30 = call i8* @strtok(i8* null, i8* %29)
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = load i8*, i8** %4
%36 = load i8*, i8** %7
%37 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36)
br label %38
38: ; preds = %33, %28
br label %25
39: ; preds = %25
store i32 0, i32* %3
br label %41
40: ; preds = %2
store i32 -302, i32* %3
br label %41
41: ; preds = %40, %39
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [21 x i8] c"/proc/ezp_machine_id\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"%s%s\00"
define i32 @get_mac_address(i8* %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = bitcast i16* %4 to i8*
store i16 58, i16* %4
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %23, label %9
9: ; preds = %2
%10 = call i32 @fgets(i8* %5, i32 64, i32* %7)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 17
store i8 0, i8* %11
%12 = call i8* @strtok(i8* %5, i8* %6)
%13 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* dereferenceable(1) %12)
%14 = icmp eq i8* %12, null
br i1 %14, label %23, label %15
15: ; preds = %9
%16 = call i8* @strtok(i8* null, i8* %6)
%17 = icmp eq i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %15, %18
%19 = phi i8* [ %21, %18 ], [ %16, %15 ]
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %19)
%21 = call i8* @strtok(i8* null, i8* %6)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %18
23: ; preds = %18, %15, %9, %2
%24 = phi i32 [ -302, %2 ], [ 0, %9 ], [ 0, %15 ], [ 0, %18 ]
ret i32 %24
}