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

/* Variables and functions */
int EINVAL;
int ENOENT;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, char *, char *, char *,
           char *);
int read_mac(const char *filename, char *buf) {
  int ret;
  FILE *f = fopen(filename, "r");
  if (!f)
    return -ENOENT;
  ret = fscanf(f, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &buf[0], &buf[1], &buf[2],
               &buf[3], &buf[4], &buf[5]);
  fclose(f);
  if (ret != 6) {
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1172 <read_mac+0x42>
xor    %eax,%eax
mov    0x2e68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <read_mac+0xb7>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%r8
add    $0x2,%r8
mov    -0x18(%rbp),%r9
add    $0x3,%r9
mov    -0x18(%rbp),%r10
add    $0x4,%r10
mov    -0x18(%rbp),%rax
add    $0x5,%rax
lea    0xe59(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x6,-0x1c(%rbp)
je     11e0 <read_mac+0xb0>
xor    %eax,%eax
mov    0x2e0a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <read_mac+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_mac>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1192 <read_mac+0x62>
mov    %rax,%r14
lea    0x1(%rbx),%rcx
lea    0x2(%rbx),%r8
lea    0x3(%rbx),%r9
lea    0x4(%rbx),%r10
lea    0x5(%rbx),%rax
lea    0xe9c(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
push   %rax
push   %r10
call   1040 <fscanf@plt>
add    $0x10,%rsp
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmp    $0x6,%ebx
je     119d <read_mac+0x6d>
mov    0x2e50(%rip),%rcx
jmp    1199 <read_mac+0x69>
mov    0x2e37(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@ENOENT = global i32 0
@.str.1 = [30 x i8] c"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\00"
@EINVAL = global i32 0
define i32 @read_mac(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @ENOENT
%14 = sub nsw i32 0, %13
store i32 %14, i32* %3
br label %38
15: ; preds = %2
%16 = load i32*, i32** %7
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 3
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 4
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 5
%29 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %20, i8* %22, i8* %24, i8* %26, i8* %28)
store i32 %29, i32* %6
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 6
br i1 %33, label %34, label %37
34: ; preds = %15
%35 = load i32, i32* @EINVAL
%36 = sub nsw i32 0, %35
store i32 %36, i32* %3
br label %38
37: ; preds = %15
store i32 0, i32* %3
br label %38
38: ; preds = %37, %34, %12
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@ENOENT = global i32 0
@.str.1 = [30 x i8] c"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\00"
@EINVAL = global i32 0
define i32 @read_mac(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @ENOENT
%7 = sub nsw i32 0, %6
br label %20
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = getelementptr inbounds i8, i8* %1, i64 3
%12 = getelementptr inbounds i8, i8* %1, i64 4
%13 = getelementptr inbounds i8, i8* %1, i64 5
%14 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %9, i8* %10, i8* %11, i8* %12, i8* %13)
%15 = tail call i32 @fclose(i32* %3)
%16 = icmp eq i32 %14, 6
br i1 %16, label %20, label %17
17: ; preds = %8
%18 = load i32, i32* @EINVAL
%19 = sub nsw i32 0, %18
br label %20
20: ; preds = %8, %17, %5
%21 = phi i32 [ %19, %17 ], [ %7, %5 ], [ 0, %8 ]
ret i32 %21
}