#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 uint8_t;
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read_fsr();
int /*<<< orphan*/ spi_transfer(int *, int);
int /*<<< orphan*/ stderr;
void enable_wen() {
  uint8_t fsr = read_fsr();
  uint8_t cmd[1];
  if (!(fsr & (1 << 5))) {
    cmd[0] = 0x06;
    spi_transfer(cmd, sizeof(cmd));
    fsr = read_fsr();
    if (!(fsr & (1 << 5))) {
      fprintf(stderr, "failed to set WEN bit on FSR\n");
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<enable_wen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <read_fsr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    11b7 <enable_wen+0x77>
movl   $0x6,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1050 <spi_transfer@plt>
mov    $0x0,%al
call   1040 <read_fsr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    11b2 <enable_wen+0x72>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    11b7 <enable_wen+0x77>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_wen>:
push   %rax
xor    %eax,%eax
call   1040 <read_fsr@plt>
test   $0x20,%al
jne    116e <enable_wen+0x2e>
movl   $0x6,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
call   1050 <spi_transfer@plt>
xor    %eax,%eax
call   1040 <read_fsr@plt>
test   $0x20,%al
je     1170 <enable_wen+0x30>
pop    %rax
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"failed to set WEN bit on FSR\0A\00"
@EXIT_FAILURE = global i32 0
define void @enable_wen() {
%1 = alloca i32
%2 = alloca [1 x i32]
%3 = call i32 (...) @read_fsr()
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = and i32 %4, 32
%6 = icmp ne i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %0
%8 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
store i32 6, i32* %8
%9 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%10 = call i32 @spi_transfer(i32* %9, i32 4)
%11 = call i32 (...) @read_fsr()
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = and i32 %12, 32
%14 = icmp ne i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %7
br label %21
21: ; preds = %20, %0
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"failed to set WEN bit on FSR\0A\00"
@EXIT_FAILURE = global i32 0
define void @enable_wen() {
%1 = alloca [1 x i32]
%2 = tail call i32 (...) @read_fsr()
%3 = bitcast [1 x i32]* %1 to i8*
%4 = and i32 %2, 32
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %0
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
store i32 6, i32* %7
%8 = call i32 @spi_transfer(i32* %7, i32 4)
%9 = call i32 (...) @read_fsr()
%10 = and i32 %9, 32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %6, %0
ret void
}