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

/* Variables and functions */
int FIPS_mode();
int /*<<< orphan*/ FIPS_mode_set(int);
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int mode;
  FILE *fp;
  fp = fopen("/proc/sys/crypto/fips_enabled", "r");
  if (fp == NULL) {
    printf("The OS doesn't support kernel crypto module!\n");
    return 1;
  }
  if (argc != 2) {
    printf("Usage: %s [mode: 0, 1]\n", argv[0]);
    return 1;
  }
  mode = atoi(argv[1]);
  printf("Current FIPS mode: %d\n", FIPS_mode());
  FIPS_mode_set(mode);
  mode = FIPS_mode();
  printf("After setting, current FIPS mode is: %d\n", mode);
  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    0xe83(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <main+0x52>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xd7>
cmpl   $0x2,-0x8(%rbp)
je     11dd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <FIPS_mode@plt>
mov    %eax,%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <FIPS_mode_set@plt>
mov    $0x0,%al
call   1060 <FIPS_mode@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe80(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e5 <main+0x75>
cmp    $0x2,%ebx
jne    11f3 <main+0x83>
mov    %rax,%r14
mov    0x8(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <FIPS_mode@plt>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <FIPS_mode_set@plt>
xor    %eax,%eax
call   1070 <FIPS_mode@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    120a <main+0x9a>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
jmp    1205 <main+0x95>
mov    0x0(%rbp),%rsi
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
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 = [24 x i8] c"Usage: %s [mode: 0, 1]\0A\00"
@.str.4 = [23 x i8] c"Current FIPS mode: %d\0A\00"
@.str.5 = [41 x i8] c"After setting, current FIPS mode is: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
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** %7
%9 = load i32*, i32** %7
%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 %35
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %35
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = call i32 (...) @FIPS_mode()
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @FIPS_mode_set(i32 %28)
%30 = call i32 (...) @FIPS_mode()
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %21, %16, %11
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [30 x i8] c"/proc/sys/crypto/fips_enabled\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [24 x i8] c"Usage: %s [mode: 0, 1]\0A\00"
@.str.4 = [23 x i8] c"Current FIPS mode: %d\0A\00"
@.str.5 = [41 x i8] c"After setting, current FIPS mode is: %d\0A\00"
@str = [45 x i8] c"The OS doesn't support kernel crypto module!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %22
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %22
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 (...) @FIPS_mode()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @FIPS_mode_set(i32 %15)
%19 = tail call i32 (...) @FIPS_mode()
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = tail call i32 @fclose(i32* %3)
br label %22
22: ; preds = %12, %9, %5
%23 = phi i32 [ 1, %5 ], [ 1, %9 ], [ 0, %12 ]
ret i32 %23
}