#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 current_setting(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *);
int set_setting(char *path, int value) {
  int res;
  int previous = current_setting(path);
  FILE *f = fopen(path, "w");
  if (f == NULL) {
    printf("Error opening file! Do you have root powers and is this kernel "
           "mptcp capable?\n");
    return -1;
  }
  res = fprintf(f, "%d", value);
  fclose(f);
  return previous;
}


x86 assembly (clang, -O0):
<set_setting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <current_setting@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a2 <set_setting+0x52>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <set_setting+0x77>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xea1(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_setting>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1070 <current_setting@plt>
mov    %eax,%ebx
lea    0xe98(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1194 <set_setting+0x44>
mov    %rax,%rbp
lea    0xe83(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    11a5 <set_setting+0x55>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [79 x i8] c"Error opening file! Do you have root powers and is this kernel mptcp capable?\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @set_setting(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @current_setting(i8* %9)
store i32 %10, i32* %7
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
17: ; preds = %2
%18 = load i32*, i32** %8
%19 = load i32, i32* %5
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = load i32*, i32** %8
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %17, %15
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [78 x i8] c"Error opening file! Do you have root powers and is this kernel mptcp capable?\00"
define i32 @set_setting(i8* %0, i32 %1) {
%3 = tail call i32 @current_setting(i8* %0)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, 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 ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %2
%9 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%10 = tail call i32 @fclose(i32* %4)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ -1, %6 ], [ %3, %8 ]
ret i32 %12
}