#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void set_value_to(const char value) {
  FILE *f;
  if (0 != setuid(0)) {
    fprintf(stderr, "Error changing user id: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  f = fopen("/sys/module/hid_apple/parameters/fnmode", "r+");
  if (NULL == f) {
    fprintf(stderr, "Error opening fnmode file.\n");
    exit(EXIT_FAILURE);
  }
  if (0 >= fprintf(f, "%c", value)) {
    fprintf(stderr, "Failed to write fnmode value.\n");
    exit(EXIT_FAILURE);
  }
  if (0 != fclose(f)) {
    fprintf(stderr, "Error closing fnmode file: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<set_value_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
xor    %edi,%edi
call   1070 <setuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11bf <set_value_to+0x5f>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe56(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1207 <set_value_to+0xa7>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
movsbl -0x1(%rbp),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jl     1252 <set_value_to+0xf2>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12a5 <set_value_to+0x145>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_value_to>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
call   1070 <setuid@plt>
test   %rax,%rax
jne    11b9 <set_value_to+0x59>
lea    0xea4(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11d9 <set_value_to+0x79>
mov    %rax,%rbx
movsbl %bpl,%edx
lea    0xecc(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %rax,%rax
jle    11eb <set_value_to+0x8b>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    1204 <set_value_to+0xa4>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e20(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe29(%rip),%rsi
jmp    1222 <set_value_to+0xc2>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
jmp    11fb <set_value_to+0x9b>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    122e <set_value_to+0xce>
mov    0x2dd5(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe63(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error changing user id: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [40 x i8] c"/sys/module/hid_apple/parameters/fnmode\00"
@.str.2 = [3 x i8] c"r+\00"
@.str.3 = [28 x i8] c"Error opening fnmode file.\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [31 x i8] c"Failed to write fnmode value.\0A\00"
@.str.6 = [31 x i8] c"Error closing fnmode file: %s\0A\00"
define void @set_value_to(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32*
store i8 %0, i8* %2
%4 = call i64 @setuid(i32 0)
%5 = icmp ne i64 0, %4
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i64 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = icmp eq i32* null, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i64 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = load i32*, i32** %3
%24 = ptrtoint i32* %23 to i32
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = call i64 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = icmp sge i64 0, %27
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = call i64 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = load i32*, i32** %3
%36 = call i64 @fclose(i32* %35)
%37 = icmp ne i64 0, %36
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i64 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error changing user id: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [40 x i8] c"/sys/module/hid_apple/parameters/fnmode\00"
@.str.2 = [3 x i8] c"r+\00"
@.str.3 = [28 x i8] c"Error opening fnmode file.\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [31 x i8] c"Failed to write fnmode value.\0A\00"
@.str.6 = [31 x i8] c"Error closing fnmode file: %s\0A\00"
define void @set_value_to(i8 signext %0) {
%2 = tail call i64 @setuid(i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i64 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i64 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
%20 = ptrtoint i32* %12 to i64
%21 = trunc i64 %20 to i32
%22 = sext i8 %0 to i32
%23 = tail call i64 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = icmp slt i64 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = tail call i64 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = tail call i64 @fclose(i32* %12)
%32 = icmp eq i64 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i64 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
ret void
}