#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 __u8;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_writeprotect_status(__u8 *ext_csd) {
  __u8 reg;
  __u8 ext_csd_rev = ext_csd[192];
  if (ext_csd_rev >= 5) {
    printf("Boot write protection status registers"
           " [BOOT_WP_STATUS]: 0x%02x\n",
           ext_csd[174]);
    reg = ext_csd[173];
    printf("Boot Area Write protection [BOOT_WP]: 0x%02x\n", reg);
    printf(" Power ro locking: %s possible\n", (reg & (0x40)) ? "not " : "");
    printf(" Permanent ro locking: %spossible\n", (reg & (0x10)) ? "not " : "");
    printf(" ro lock status: ");
    if (reg & (0x01))
      printf("locked until next power on\n");
    else if (reg & (0x04))
      printf("locked permanently\n");
    else
      printf("not locked\n");
  }
}


x86 assembly (clang, -O0):
<print_writeprotect_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x300(%rax),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jl     1225 <print_writeprotect_status+0x115>
mov    -0x8(%rbp),%rax
mov    0x2b8(%rax),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x2b4(%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
and    $0x40,%ecx
lea    0xf8e(%rip),%rsi
lea    0xf12(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
and    $0x10,%ecx
lea    0xf65(%rip),%rsi
lea    0xee9(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11eb <print_writeprotect_status+0xdb>
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1220 <print_writeprotect_status+0x110>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     120d <print_writeprotect_status+0xfd>
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121b <print_writeprotect_status+0x10b>
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1220 <print_writeprotect_status+0x110>
jmp    1225 <print_writeprotect_status+0x115>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_writeprotect_status>:
push   %rbp
push   %r14
push   %rbx
cmpl   $0x5,0x300(%rdi)
jl     11da <print_writeprotect_status+0xba>
mov    %rdi,%rbx
mov    0x2b8(%rdi),%esi
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2b4(%rbx),%ebp
lea    0xeec(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x40,%bpl
lea    0xf25(%rip),%r14
lea    0xf1f(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xef1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x10,%bpl
cmove  %r14,%rbx
lea    0xf00(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf12(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x4,%bpl
lea    0xf12(%rip),%rax
lea    0xf16(%rip),%rcx
cmove  %rax,%rcx
test   $0x1,%bpl
lea    0xf1a(%rip),%rdi
cmove  %rcx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"Boot write protection status registers [BOOT_WP_STATUS]: 0x%02x\0A\00"
@.str.1 = [46 x i8] c"Boot Area Write protection [BOOT_WP]: 0x%02x\0A\00"
@.str.2 = [32 x i8] c" Power ro locking: %s possible\0A\00"
@.str.3 = [5 x i8] c"not \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [35 x i8] c" Permanent ro locking: %spossible\0A\00"
@.str.6 = [18 x i8] c" ro lock status: \00"
@.str.7 = [28 x i8] c"locked until next power on\0A\00"
@.str.8 = [20 x i8] c"locked permanently\0A\00"
@.str.9 = [12 x i8] c"not locked\0A\00"
define void @print_writeprotect_status(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = getelementptr inbounds i32, i32* %5, i64 192
%7 = load i32, i32* %6
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 5
br i1 %9, label %10, label %48
10: ; preds = %1
%11 = load i32*, i32** %2
%12 = getelementptr inbounds i32, i32* %11, i64 174
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i64 173
%17 = load i32, i32* %16
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = and i32 %20, 64
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %3
%27 = and i32 %26, 16
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* %3
%34 = and i32 %33, 1
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %47
38: ; preds = %10
%39 = load i32, i32* %3
%40 = and i32 %39, 4
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %46
44: ; preds = %38
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
br label %47
47: ; preds = %46, %36
br label %48
48: ; preds = %47, %1
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"Boot write protection status registers [BOOT_WP_STATUS]: 0x%02x\0A\00"
@.str.1 = [46 x i8] c"Boot Area Write protection [BOOT_WP]: 0x%02x\0A\00"
@.str.2 = [32 x i8] c" Power ro locking: %s possible\0A\00"
@.str.3 = [5 x i8] c"not \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [35 x i8] c" Permanent ro locking: %spossible\0A\00"
@.str.6 = [18 x i8] c" ro lock status: \00"
@str = [11 x i8] c"not locked\00"
@str.10 = [19 x i8] c"locked permanently\00"
@str.11 = [27 x i8] c"locked until next power on\00"
define void @print_writeprotect_status(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 192
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 4
br i1 %4, label %5, label %28
5: ; preds = %1
%6 = getelementptr inbounds i32, i32* %0, i64 174
%7 = load i32, i32* %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds i32, i32* %0, i64 173
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = and i32 %10, 64
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = and i32 %10, 16
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%21 = and i32 %10, 1
%22 = icmp eq i32 %21, 0
%23 = and i32 %10, 4
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0)
%26 = select i1 %22, i8* %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0)
%27 = tail call i32 @puts(i8* dereferenceable(1) %26)
br label %28
28: ; preds = %5, %1
ret void
}