#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 /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int jent_fips_enabled(void) {
  char buf[2] = "0";
  int fd = 0;
  if ((fd = open("/proc/sys/crypto/fips_enabled", O_RDONLY)) >= 0) {
    while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR)
      ;
    close(fd);
  }
  if (buf[0] == '1')
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<jent_fips_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xec1(%rip),%ax
mov    %ax,-0x6(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     11ca <jent_fips_enabled+0x9a>
jmp    1170 <jent_fips_enabled+0x40>
mov    -0xc(%rbp),%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
jge    11ad <jent_fips_enabled+0x7d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11bd <jent_fips_enabled+0x8d>
jmp    11c2 <jent_fips_enabled+0x92>
jmp    1170 <jent_fips_enabled+0x40>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
movsbl -0x6(%rbp),%eax
cmp    $0x31,%eax
jne    11e3 <jent_fips_enabled+0xb3>
movl   $0x1,-0x4(%rbp)
jmp    11ea <jent_fips_enabled+0xba>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jent_fips_enabled>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movw   $0x30,0x6(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11a0 <jent_fips_enabled+0x70>
mov    %eax,%ebx
lea    0x6(%rsp),%r14
mov    0x2e72(%rip),%r15
mov    0x2e63(%rip),%r12
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <read@plt>
test   %rax,%rax
jns    118d <jent_fips_enabled+0x5d>
mov    (%r12),%rax
cmp    %rax,(%r15)
je     1170 <jent_fips_enabled+0x40>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
cmpb   $0x31,0x6(%rsp)
sete   %al
jmp    11a2 <jent_fips_enabled+0x72>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.jent_fips_enabled.buf = [2 x i8] c"0\00"
@.str = [30 x i8] c"/proc/sys/crypto/fips_enabled\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @jent_fips_enabled() {
%1 = alloca i32
%2 = alloca [2 x i8]
%3 = alloca i32
%4 = bitcast [2 x i8]* %2 to i8*
store i32 0, i32* %3
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %0
br label %9
9: ; preds = %20, %8
%10 = load i32, i32* %3
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%12 = call i64 @read(i32 %10, i8* %11, i32 2)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br label %18
18: ; preds = %14, %9
%19 = phi i1 [ false, %9 ], [ %17, %14 ]
br i1 %19, label %20, label %21
20: ; preds = %18
br label %9
21: ; preds = %18
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
br label %24
24: ; preds = %21, %0
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 49
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %1
br label %31
30: ; preds = %24
store i32 0, i32* %1
br label %31
31: ; preds = %30, %29
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [30 x i8] c"/proc/sys/crypto/fips_enabled\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @jent_fips_enabled() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
store i16 48, i16* %1
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %18
6: ; preds = %0, %6
%7 = call i64 @read(i32 %4, i8* %2, i32 2)
%8 = icmp slt i64 %7, 0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
%12 = select i1 %8, i1 %11, i1 false
br i1 %12, label %6, label %13
13: ; preds = %6
%14 = tail call i32 @close(i32 %4)
%15 = load i8, i8* %2
%16 = icmp eq i8 %15, 49
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %13, %0
%19 = phi i32 [ %17, %13 ], [ 0, %0 ]
ret i32 %19
}