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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ *stderr;
int setsysctrl(const char *dev, const char *control, u_long value) {
  char buffer[256];
  FILE *fd;
  snprintf(buffer, sizeof(buffer), "/proc/sys/dev/%s/%s", dev, control);
  fd = fopen(buffer, "w");
  if (fd != NULL) {
    fprintf(fd, "%li", value);
    fclose(fd);
  } else
    fprintf(stderr, "Could not open %s for writing!\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<setsysctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xe8e(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     11c7 <setsysctrl+0x87>
mov    -0x128(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11e4 <setsysctrl+0xa4>
mov    0x2e12(%rip),%rax
mov    (%rax),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsysctrl>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0xea6(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <setsysctrl+0x5d>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11b6 <setsysctrl+0x76>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rdi
lea    0xe6c(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/proc/sys/dev/%s/%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%li\00"
@stderr = global i32* null
@.str.3 = [32 x i8] c"Could not open %s for writing!\0A\00"
define i32 @setsysctrl(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %8
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load i8*, i8** %6
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %8
%22 = call i32 @fclose(i32* %21)
br label %27
23: ; preds = %3
%24 = load i32*, i32** @stderr
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %17
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"/proc/sys/dev/%s/%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%li\00"
@stderr = global i32* null
@.str.3 = [32 x i8] c"Could not open %s for writing!\0A\00"
define i32 @setsysctrl(i8* %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = call i32 @fclose(i32* %7)
br label %15
12: ; preds = %3
%13 = load i32*, i32** @stderr
%14 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %15
15: ; preds = %12, %9
ret i32 0
}