#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *, int *, int *,
           int *);
int hashmac(void) {
  FILE *file = fopen("/sys/class/net/eth0/address", "r");
  int mac[6], res = 0;
  if (!file)
    return 0;
  if (fscanf(file, "%02x:%02x:%02x:%02x:%02x:%02x", mac + 0, mac + 1, mac + 2,
             mac + 3, mac + 4, mac + 5) == 6) {
    res = mac[5];
    res ^= mac[4] << 4;
    res ^= mac[3] << 8;
    res ^= mac[2] << 16;
    res ^= mac[1] << 20;
    res ^= mac[0] << 24;
  }
  fclose(file);
  return res;
}


x86 assembly (clang, -O0):
<hashmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xec1(%rip),%rdi
lea    0xed6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <hashmac+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    120c <hashmac+0xdc>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x30(%rbp),%r10
add    $0x10,%r10
lea    -0x30(%rbp),%rax
add    $0x14,%rax
lea    0xe7a(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <fscanf@plt>
cmp    $0x6,%eax
jne    11fd <hashmac+0xcd>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x4,%eax
xor    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x8,%eax
xor    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x10,%eax
xor    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x14,%eax
xor    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x18,%eax
xor    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashmac>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xec3(%rip),%rdi
lea    0xed8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c1 <hashmac+0x91>
mov    %rax,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%rax
lea    0x14(%rsp),%rbp
lea    0xead(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
push   %rbp
push   %rax
call   1040 <fscanf@plt>
add    $0x10,%rsp
xor    %ebp,%ebp
cmp    $0x6,%eax
jne    11b7 <hashmac+0x87>
mov    0x10(%rsp),%eax
shl    $0x4,%eax
xor    0x14(%rsp),%eax
mov    0xc(%rsp),%ecx
shl    $0x8,%ecx
mov    0x8(%rsp),%edx
shl    $0x10,%edx
xor    %ecx,%edx
mov    (%rsp),%ebp
mov    0x4(%rsp),%ecx
shl    $0x14,%ecx
xor    %edx,%ecx
shl    $0x18,%ebp
xor    %ecx,%ebp
xor    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11c3 <hashmac+0x93>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"/sys/class/net/eth0/address\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i32 @hashmac() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [6 x i32]
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
store i32 0, i32* %4
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 0, i32* %1
br label %57
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%16 = getelementptr inbounds i32, i32* %15, i64 2
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%18 = getelementptr inbounds i32, i32* %17, i64 3
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%20 = getelementptr inbounds i32, i32* %19, i64 4
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%22 = getelementptr inbounds i32, i32* %21, i64 5
%23 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32* %12, i32* %14, i32* %16, i32* %18, i32* %20, i32* %22)
%24 = icmp eq i32 %23, 6
br i1 %24, label %25, label %53
25: ; preds = %9
%26 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%27 = load i32, i32* %26
store i32 %27, i32* %4
%28 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%29 = load i32, i32* %28
%30 = shl i32 %29, 4
%31 = load i32, i32* %4
%32 = xor i32 %31, %30
store i32 %32, i32* %4
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%34 = load i32, i32* %33
%35 = shl i32 %34, 8
%36 = load i32, i32* %4
%37 = xor i32 %36, %35
store i32 %37, i32* %4
%38 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%39 = load i32, i32* %38
%40 = shl i32 %39, 16
%41 = load i32, i32* %4
%42 = xor i32 %41, %40
store i32 %42, i32* %4
%43 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%44 = load i32, i32* %43
%45 = shl i32 %44, 20
%46 = load i32, i32* %4
%47 = xor i32 %46, %45
store i32 %47, i32* %4
%48 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%49 = load i32, i32* %48
%50 = shl i32 %49, 24
%51 = load i32, i32* %4
%52 = xor i32 %51, %50
store i32 %52, i32* %4
br label %53
53: ; preds = %25, %9
%54 = load i32*, i32** %2
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %4
store i32 %56, i32* %1
br label %57
57: ; preds = %53, %8
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [28 x i8] c"/sys/class/net/eth0/address\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i32 @hashmac() {
%1 = alloca [6 x i32]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast [6 x i32]* %1 to i8*
%4 = icmp eq i32* %2, null
br i1 %4, label %34, label %5
5: ; preds = %0
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 1
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 2
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 3
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 4
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 5
%12 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11)
%13 = icmp eq i32 %12, 6
br i1 %13, label %14, label %31
14: ; preds = %5
%15 = load i32, i32* %11
%16 = load i32, i32* %10
%17 = shl i32 %16, 4
%18 = xor i32 %17, %15
%19 = load i32, i32* %9
%20 = shl i32 %19, 8
%21 = xor i32 %18, %20
%22 = load i32, i32* %8
%23 = shl i32 %22, 16
%24 = xor i32 %21, %23
%25 = load i32, i32* %7
%26 = shl i32 %25, 20
%27 = xor i32 %24, %26
%28 = load i32, i32* %6
%29 = shl i32 %28, 24
%30 = xor i32 %27, %29
br label %31
31: ; preds = %14, %5
%32 = phi i32 [ %30, %14 ], [ 0, %5 ]
%33 = call i32 @fclose(i32* %2)
br label %34
34: ; preds = %0, %31
%35 = phi i32 [ %32, %31 ], [ 0, %0 ]
ret i32 %35
}