#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 /*<<< orphan*/ free(char *);
char *read_sysfs_state_file(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write_sysfs_file(char *, char *);
void check_thp_state(void) {
  char *enabled =
      read_sysfs_state_file("/sys/kernel/mm/transparent_hugepage/enabled");
  char *defrag =
      read_sysfs_state_file("/sys/kernel/mm/transparent_hugepage/defrag");
  if (strcmp(enabled, "[always]") && strcmp(enabled, "[madvise]")) {
    write_sysfs_file("/sys/kernel/mm/transparent_hugepage/enabled", "madvise");
  }
  if (strcmp(defrag, "[always]") && strcmp(defrag, "[defer+madvise]") &&
      strcmp(defrag, "[madvise]")) {
    write_sysfs_file("/sys/kernel/mm/transparent_hugepage/defrag", "madvise");
  }
  free(enabled);
  free(defrag);
}


x86 assembly (clang, -O0):
<check_thp_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <read_sysfs_state_file@plt>
mov    %rax,-0x8(%rbp)
lea    0xecd(%rip),%rdi
call   1040 <read_sysfs_state_file@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xee4(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11af <check_thp_state+0x6f>
mov    -0x8(%rbp),%rdi
lea    0xed3(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11af <check_thp_state+0x6f>
lea    0xe5d(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <write_sysfs_file@plt>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1210 <check_thp_state+0xd0>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1210 <check_thp_state+0xd0>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1210 <check_thp_state+0xd0>
lea    0xe28(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <write_sysfs_file@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_thp_state>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1040 <read_sysfs_state_file@plt>
mov    %rax,%r14
lea    0xed2(%rip),%rdi
call   1040 <read_sysfs_state_file@plt>
mov    %rax,%rbx
lea    0xeee(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     119d <check_thp_state+0x5d>
lea    0xee3(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     119d <check_thp_state+0x5d>
lea    0xe6f(%rip),%rdi
lea    0xed2(%rip),%rsi
call   1050 <write_sysfs_file@plt>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ec <check_thp_state+0xac>
lea    0xeba(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ec <check_thp_state+0xac>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ec <check_thp_state+0xac>
lea    0xe4c(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1050 <write_sysfs_file@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"/sys/kernel/mm/transparent_hugepage/enabled\00"
@.str.1 = [43 x i8] c"/sys/kernel/mm/transparent_hugepage/defrag\00"
@.str.2 = [9 x i8] c"[always]\00"
@.str.3 = [10 x i8] c"[madvise]\00"
@.str.4 = [8 x i8] c"madvise\00"
@.str.5 = [16 x i8] c"[defer+madvise]\00"
define void @check_thp_state() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @read_sysfs_state_file(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = call i8* @read_sysfs_state_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %1
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i8*, i8** %1
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @write_sysfs_file(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %14
14: ; preds = %12, %8, %0
%15 = load i8*, i8** %2
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @write_sysfs_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %22, %18, %14
%29 = load i8*, i8** %1
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"/sys/kernel/mm/transparent_hugepage/enabled\00"
@.str.1 = [43 x i8] c"/sys/kernel/mm/transparent_hugepage/defrag\00"
@.str.2 = [9 x i8] c"[always]\00"
@.str.3 = [10 x i8] c"[madvise]\00"
@.str.4 = [8 x i8] c"madvise\00"
@.str.5 = [16 x i8] c"[defer+madvise]\00"
define void @check_thp_state() {
%1 = tail call i8* @read_sysfs_state_file(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @read_sysfs_state_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @write_sysfs_file(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %10
10: ; preds = %8, %5, %0
%11 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %10
%14 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @write_sysfs_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %16, %13, %10
%22 = tail call i32 @free(i8* %1)
%23 = tail call i32 @free(i8* %2)
ret void
}