#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 O_RDWR;
int O_SYNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, unsigned char *, int);
void get_stamac(unsigned char *mac) {
  int fd = 0;
  if (!mac)
    return;
  fd = open("/dev/mtd/5", O_RDWR | O_SYNC);
  if (0 > fd) {
    printf("potval: open mtd POT error!\n");
    memset(mac, 0xff, 6);
  } else {
    lseek(fd, (2048 + 4), SEEK_SET);
    read(fd, mac, 6);
    close(fd);
  }
}


x86 assembly (clang, -O0):
<get_stamac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1183 <get_stamac+0x23>
jmp    1202 <get_stamac+0xa2>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
lea    0xe64(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jle    11d3 <get_stamac+0x73>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0xff,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
jmp    1202 <get_stamac+0xa2>
mov    -0xc(%rbp),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
mov    $0x804,%esi
call   1040 <lseek@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x6,%edx
call   1070 <read@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_stamac>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     11c0 <get_stamac+0x60>
mov    %rdi,%rbx
mov    0x2e76(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11c7 <get_stamac+0x67>
mov    %eax,%ebp
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x804,%esi
call   1040 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1070 <read@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x6,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <memset@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/mtd/5\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.1 = [29 x i8] c"potval: open mtd POT error!\0A\00"
@SEEK_SET = global i32 0
define void @get_stamac(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
br label %27
7: ; preds = %1
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sgt i32 0, %12
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = call i32 @memset(i8* %16, i32 255, i32 6)
br label %27
18: ; preds = %7
%19 = load i32, i32* %3
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %19, i32 2052, i32 %20)
%22 = load i32, i32* %3
%23 = load i8*, i8** %2
%24 = call i32 @read(i32 %22, i8* %23, i32 6)
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %6, %18, %14
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/mtd/5\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@SEEK_SET = global i32 0
@str = [28 x i8] c"potval: open mtd POT error!\00"
define void @get_stamac(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_SYNC
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @memset(i8* %0, i32 255, i32 6)
br label %17
12: ; preds = %3
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @lseek(i32 %7, i32 2052, i32 %13)
%15 = tail call i32 @read(i32 %7, i8* %0, i32 6)
%16 = tail call i32 @close(i32 %7)
br label %17
17: ; preds = %9, %12, %1
ret void
}