#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*/ exit(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int read_wifi_mode() {
  int fd = -1;
  int i = 0;
  unsigned char wifimode;
  fd = open("/dev/mmcblk0", O_RDONLY);
  if (fd < 0) {
    printf("open %s failed.\n", "/dev/mmcblk0");
    exit(1);
  }
  lseek(fd, 0x40000, SEEK_SET);
  if (read(fd, &wifimode, 1) != 1) {
    printf("read %s failed.\n", "/dev/mmcblk0");
    close(fd);
  }
  printf("%x\n", wifimode);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<read_wifi_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11b7 <read_wifi_mode+0x57>
lea    0xe6e(%rip),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
mov    $0x40000,%esi
call   1040 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
je     1204 <read_wifi_mode+0xa4>
lea    0xe30(%rip),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
movzbl -0x9(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_wifi_mode>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11e9 <read_wifi_mode+0x89>
mov    %eax,%ebx
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x40000,%esi
call   1040 <lseek@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
je     11c7 <read_wifi_mode+0x67>
lea    0xe6c(%rip),%rdi
lea    0xe47(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
movzbl 0xf(%rsp),%esi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe1d(%rip),%rdi
lea    0xe09(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/mmcblk0\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"open %s failed.\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [17 x i8] c"read %s failed.\0A\00"
@.str.3 = [4 x i8] c"%x\0A\00"
define i32 @read_wifi_mode() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 -1, i32* %1
store i32 0, i32* %2
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %1
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %12, i32 262144, i32 %13)
%15 = load i32, i32* %1
%16 = call i32 @read(i32 %15, i8* %3, i32 1)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %18, %11
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %1
%27 = call i32 @close(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/mmcblk0\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"open %s failed.\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [17 x i8] c"read %s failed.\0A\00"
@.str.3 = [4 x i8] c"%x\0A\00"
define i32 @read_wifi_mode() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %3, i32 262144, i32 %9)
%11 = call i32 @read(i32 %3, i8* %1, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @close(i32 %3)
br label %16
16: ; preds = %13, %8
%17 = load i8, i8* %1
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = tail call i32 @close(i32 %3)
ret i32 0
}