#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*/ c;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  char c;
  fp = fopen("/proc/sys/crypto/fips_enabled", "r");
  if (fp == NULL) {
    printf("The OS doesn't support kernel crypto module!\n");
    return 1;
  }
  if (fread(&c, sizeof(c), 1, fp) <= 0) {
    printf("failed to read from: %s\n", "/proc/sys/crypto/fips_enabled");
    fclose(fp);
    return 1;
  }
  printf("FIPS_MODE: %c\n", c);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <main+0x52>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <main+0xbc>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jg     11da <main+0x9a>
lea    0xe97(%rip),%rdi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <main+0xbc>
movsbl -0x19(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a6 <main+0x56>
mov    %rax,%rbx
lea    0x7(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    11b9 <main+0x69>
movsbl 0x7(%rsp),%esi
lea    0xe9e(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11ce <main+0x7e>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    11d6 <main+0x86>
lea    0xe60(%rip),%rdi
lea    0xe39(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/proc/sys/crypto/fips_enabled\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [46 x i8] c"The OS doesn't support kernel crypto module!\0A\00"
@.str.3 = [25 x i8] c"failed to read from: %s\0A\00"
@.str.4 = [15 x i8] c"FIPS_MODE: %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %27
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = call i64 @fread(i8* %7, i32 1, i32 1, i32* %14)
%16 = icmp sle i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
store i32 1, i32* %3
br label %27
21: ; preds = %13
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
store i32 0, i32* %3
br label %27
27: ; preds = %21, %17, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [30 x i8] c"/proc/sys/crypto/fips_enabled\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"failed to read from: %s\0A\00"
@.str.4 = [15 x i8] c"FIPS_MODE: %c\0A\00"
@str = [45 x i8] c"The OS doesn't support kernel crypto module!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %19
8: ; preds = %2
%9 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %4)
%10 = icmp slt i64 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @fclose(i32* %4)
br label %19
14: ; preds = %8
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @fclose(i32* %4)
br label %19
19: ; preds = %14, %11, %6
%20 = phi i32 [ 1, %6 ], [ 1, %11 ], [ 0, %14 ]
ret i32 %20
}