#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*/ LOG_INFO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
void vyatta_if_write_sysctl_value(const char *outpath, int value) {
  int rc = 0;
  FILE *fp;
  fp = fopen(outpath, "w");
  if (!fp) {
    syslog(LOG_INFO, "couldn't open sysctl path: %s\n", outpath);
    return;
  }
  rc = fprintf(fp, "%d\n", value);
  if (rc < 0)
    syslog(LOG_INFO, "couldn't write to sysctl path: %s\n", outpath);
  fclose(fp);
}


x86 assembly (clang, -O0):
<vyatta_if_write_sysctl_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1193 <vyatta_if_write_sysctl_value+0x53>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1050 <syslog@plt>
jmp    11d5 <vyatta_if_write_sysctl_value+0x95>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11cc <vyatta_if_write_sysctl_value+0x8c>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1050 <syslog@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vyatta_if_write_sysctl_value>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1196 <vyatta_if_write_sysctl_value+0x56>
mov    %rax,%rbx
lea    0xebd(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
test   %eax,%eax
jns    118a <vyatta_if_write_sysctl_value+0x4a>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    %r14,%rdx
call   1050 <syslog@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <syslog@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@LOG_INFO = global i32 0
@.str.1 = [31 x i8] c"couldn't open sysctl path: %s\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [35 x i8] c"couldn't write to sysctl path: %s\0A\00"
define void @vyatta_if_write_sysctl_value(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @LOG_INFO
%13 = load i8*, i8** %3
%14 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %28
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i32, i32* %4
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* @LOG_INFO
%23 = load i8*, i8** %3
%24 = call i32 @syslog(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %15
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@LOG_INFO = global i32 0
@.str.1 = [31 x i8] c"couldn't open sysctl path: %s\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [35 x i8] c"couldn't write to sysctl path: %s\0A\00"
define void @vyatta_if_write_sysctl_value(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @LOG_INFO
%7 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
8: ; preds = %2
%9 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @LOG_INFO
%13 = tail call i32 @syslog(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %11, %8
%15 = tail call i32 @fclose(i32* %3)
br label %16
16: ; preds = %14, %5
ret void
}