#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int my_sysctl(char *path, char *value) {
  int fd;
  if ((fd = open(path, O_RDWR)) < 0)
    return -1;
  if (write(fd, value, strlen(value)) < 0)
    return -1;
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<my_sysctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    117a <my_sysctl+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <my_sysctl+0x84>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b5 <my_sysctl+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <my_sysctl+0x84>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sysctl>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1184 <my_sysctl+0x44>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1184 <my_sysctl+0x44>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
define i32 @my_sysctl(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %23
12: ; preds = %2
%13 = load i32, i32* %6
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = call i64 @write(i32 %13, i8* %14, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %3
br label %23
20: ; preds = %12
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
store i32 0, i32* %3
br label %23
23: ; preds = %20, %19, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@O_RDWR = global i32 0
define i32 @my_sysctl(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i64 @write(i32 %4, i8* %1, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @close(i32 %4)
br label %12
12: ; preds = %6, %2, %10
%13 = phi i32 [ 0, %10 ], [ -1, %2 ], [ -1, %6 ]
ret i32 %13
}