#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_NDELAY;
int O_RDWR;
int /*<<< orphan*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int dev_fd, status, ret = 0;
  dev_fd = open("/dev/mmcblk0", O_RDWR | O_NDELAY);
  if (dev_fd == -1) {
    printf("[%s] cannot open %s.\n", "/dev/mmcblk0");
  }
  ret = ioctl(dev_fd, _IO(179, 2), &status);
  if (ret)
    printf("IOCTL_MMC_READ_STATUS: fail\n");
  if (status & (1 << 19)) {
    printf("########MMC Write protect status: %08x###########\n", status);
    ret = -1;
  } else {
    printf("------emmc status ok status=%08x--------\n", status);
    ret = 0;
  }
  close(dev_fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a6 <main+0x56>
lea    0xe75(%rip),%rdi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0xb3,%edi
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
lea    -0xc(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11e4 <main+0x94>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
and    $0x80000,%eax
cmp    $0x0,%eax
je     1212 <main+0xc2>
mov    -0xc(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x10(%rbp)
jmp    122a <main+0xda>
mov    -0xc(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e7e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe84(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    119d <main+0x3d>
lea    0xe7e(%rip),%rdi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xb3,%edi
mov    $0x2,%esi
call   1050 <_IO@plt>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
test   %eax,%eax
je     11ca <main+0x6a>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
mov    %esi,%eax
and    $0x80000,%eax
mov    %eax,%ebp
shr    $0x13,%ebp
test   %eax,%eax
lea    0xe73(%rip),%rax
lea    0xe39(%rip),%rdi
cmove  %rax,%rdi
neg    %ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/mmcblk0\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [22 x i8] c"[%s] cannot open %s.\0A\00"
@.str.2 = [29 x i8] c"IOCTL_MMC_READ_STATUS: fail\0A\00"
@.str.3 = [51 x i8] c"########MMC Write protect status: %08x###########\0A\00"
@.str.4 = [42 x i8] c"------emmc status ok status=%08x--------\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = load i32, i32* %2
%15 = call i32 @_IO(i32 179, i32 2)
%16 = call i32 @ioctl(i32 %14, i32 %15, i32* %3)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i32, i32* %3
%23 = and i32 %22, 524288
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %26)
store i32 -1, i32* %4
br label %31
28: ; preds = %21
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %29)
store i32 0, i32* %4
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/mmcblk0\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [22 x i8] c"[%s] cannot open %s.\0A\00"
@.str.3 = [51 x i8] c"########MMC Write protect status: %08x###########\0A\00"
@.str.4 = [42 x i8] c"------emmc status ok status=%08x--------\0A\00"
@str = [28 x i8] c"IOCTL_MMC_READ_STATUS: fail\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NDELAY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = tail call i32 @_IO(i32 179, i32 2)
%12 = call i32 @ioctl(i32 %6, i32 %11, i32* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* %1
%18 = and i32 %17, 524288
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0)
%21 = xor i1 %19, true
%22 = sext i1 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %20, i32 %17)
%24 = call i32 @close(i32 %6)
ret i32 %22
}