#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 lps331_read_reg(int, int);
int lps331_write_reg(int, int, int);
int enable_lps331(int fd) {
  int res, byte;
  byte = lps331_read_reg(fd, 0x20);
  if (byte < 0)
    return byte;
  if (byte == 0x90)
    return 1;
  res = lps331_write_reg(fd, 0x20, 0x90);
  if (res < 0)
    return res;
  return 1;
}


x86 assembly (clang, -O0):
<enable_lps331>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x20,%esi
call   1040 <lps331_read_reg@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1150 <enable_lps331+0x30>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <enable_lps331+0x7a>
cmpl   $0x90,-0x10(%rbp)
jne    1169 <enable_lps331+0x49>
movl   $0x1,-0x4(%rbp)
jmp    119a <enable_lps331+0x7a>
mov    -0x8(%rbp),%edi
mov    $0x20,%esi
mov    $0x90,%edx
call   1030 <lps331_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1193 <enable_lps331+0x73>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <enable_lps331+0x7a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_lps331>:
push   %rbx
mov    %edi,%ebx
mov    $0x20,%esi
call   1040 <lps331_read_reg@plt>
mov    %eax,%ecx
test   %eax,%eax
js     115f <enable_lps331+0x3f>
mov    $0x1,%eax
cmp    $0x90,%ecx
je     115d <enable_lps331+0x3d>
mov    %ebx,%edi
mov    $0x20,%esi
mov    $0x90,%edx
call   1030 <lps331_write_reg@plt>
mov    %eax,%ecx
test   %eax,%eax
mov    $0x1,%eax
cmovs  %ecx,%eax
pop    %rbx
ret
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @enable_lps331(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @lps331_read_reg(i32 %6, i32 32)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %5
store i32 %11, i32* %2
br label %24
12: ; preds = %1
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 144
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 1, i32* %2
br label %24
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i32 @lps331_write_reg(i32 %17, i32 32, i32 144)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %24
23: ; preds = %16
store i32 1, i32* %2
br label %24
24: ; preds = %23, %21, %15, %10
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @enable_lps331(i32 %0) {
%2 = tail call i32 @lps331_read_reg(i32 %0, i32 32)
%3 = icmp slt i32 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = icmp eq i32 %2, 144
br i1 %5, label %10, label %6
6: ; preds = %4
%7 = tail call i32 @lps331_write_reg(i32 %0, i32 32, i32 144)
%8 = icmp slt i32 %7, 0
%9 = select i1 %8, i32 %7, i32 1
br label %10
10: ; preds = %6, %4, %1
%11 = phi i32 [ %2, %1 ], [ 1, %4 ], [ %9, %6 ]
ret i32 %11
}