#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int mtd_open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int flash_read_NicConf(char *buf) {
  int fd, ret;
  if (!buf)
    return -1;
  fd = mtd_open("Factory", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Could not open mtd device\n");
    return -1;
  }
  lseek(fd, 0x34, SEEK_SET);
  ret = read(fd, buf, 6);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<flash_read_NicConf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <flash_read_NicConf+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <flash_read_NicConf+0x9e>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1060 <mtd_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b6 <flash_read_NicConf+0x66>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <flash_read_NicConf+0x9e>
mov    -0x14(%rbp),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    $0x34,%esi
call   1030 <lseek@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_read_NicConf>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     11bc <flash_read_NicConf+0x6c>
mov    %rdi,%rbx
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1060 <mtd_open@plt>
test   %eax,%eax
js     11a7 <flash_read_NicConf+0x57>
mov    %eax,%ebp
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x34,%esi
call   1030 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1050 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
jmp    11c1 <flash_read_NicConf+0x71>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Factory\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not open mtd device\0A\00"
@SEEK_SET = global i32 0
define i32 @flash_read_NicConf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %2
br label %27
9: ; preds = %1
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @mtd_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %27
17: ; preds = %9
%18 = load i32, i32* %4
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @lseek(i32 %18, i32 52, i32 %19)
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = call i32 @read(i32 %21, i8* %22, i32 6)
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %5
store i32 %26, i32* %2
br label %27
27: ; preds = %17, %14, %8
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [8 x i8] c"Factory\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not open mtd device\0A\00"
@SEEK_SET = global i32 0
define i32 @flash_read_NicConf(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @mtd_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %15
10: ; preds = %3
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %5, i32 52, i32 %11)
%13 = tail call i32 @read(i32 %5, i8* %0, i32 6)
%14 = tail call i32 @close(i32 %5)
br label %15
15: ; preds = %1, %10, %7
%16 = phi i32 [ -1, %7 ], [ %13, %10 ], [ -1, %1 ]
ret i32 %16
}