#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int strlen(char *);
int write(int, char *, int);
int set_int_option(char *conf_path, char *name, int val) {
  int fd;
  int len, cnt;
  char fname[512];
  char buf[256];
  ;
  snprintf(fname, 512, "%s/%s", conf_path, name);
  if ((fd = open(fname, O_WRONLY)) < 0) {
    ;
    return -1;
  }
  snprintf(buf, 256, "%d", val);
  len = strlen(buf);
  cnt = write(fd, buf, len);
  ;
  close(fd);
  if (cnt != len)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<set_int_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x200,%esi
lea    0xe7f(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11b5 <set_int_option+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <set_int_option+0xcd>
lea    -0x330(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x100,%esi
lea    0xe3b(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x330(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x330(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1216 <set_int_option+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <set_int_option+0xcd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_int_option>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x308,%rsp
mov    %edx,%r14d
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0xe93(%rip),%rdx
lea    0x100(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11e3 <set_int_option+0x93>
mov    %eax,%ebp
lea    0xe64(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
cmp    %ebx,%r14d
setne  %al
neg    %eax
jmp    11e8 <set_int_option+0x98>
mov    $0xffffffff,%eax
add    $0x308,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @set_int_option(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [512 x i8]
%12 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 -1, i32* %4
br label %39
22: ; preds = %3
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%24 = load i32, i32* %7
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %23, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %8
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%30 = load i32, i32* %9
%31 = call i32 @write(i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %10
%32 = load i32, i32* %8
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %10
%35 = load i32, i32* %9
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %22
store i32 -1, i32* %4
br label %39
38: ; preds = %22
store i32 0, i32* %4
br label %39
39: ; preds = %38, %37, %21
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @set_int_option(i8* %0, i8* %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* %6, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %3
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%14 = call i32 @strlen(i8* %7)
%15 = call i32 @write(i32 %10, i8* %7, i32 %14)
%16 = call i32 @close(i32 %10)
%17 = icmp ne i32 %15, %14
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %12, %3
%20 = phi i32 [ -1, %3 ], [ %18, %12 ]
ret i32 %20
}