#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*/);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int dump_tune_vm(void) {
  char *sysctl_names[] = {"/proc/sys/vm/dirty_ratio",
                          "/proc/sys/vm/dirty_background_ratio",
                          "/proc/sys/vm/dirty_writeback_centisecs",
                          "/proc/sys/vm/dirty_expire_centisecs",
                          "/proc/sys/vm/vfs_cache_pressure",
                          "/proc/sys/vm/lowmem_reserve_ratio",
                          NULL};
  char *sysctl_values[] = {"2", "5", "50", "50", "500", "32", NULL};
  int fh = -1, i = 0, rc = 0;
  while (sysctl_names[i]) {
    fh = open(sysctl_names[i], O_RDWR);
    if (fh < 0) {
      rc = -1;
      goto out;
    }
    if (write(fh, sysctl_values[i], strlen(sysctl_values[i])) !=
        strlen(sysctl_values[i])) {
      rc = -1;
      goto out;
    }
    i++;
  }
out:
  if (fh >= 0)
    close(fh);
  return rc;
}


x86 assembly (clang, -O0):
<dump_tune_vm>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
lea    0xe8e(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xed1(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeea(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xeff(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
lea    0xf10(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xefb(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xef2(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xee7(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xedf(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xed8(%rip),%rax
mov    %rax,-0x58(%rbp)
movl   $0xffffffff,-0x84(%rbp)
ff ff ff
movl   $0x0,-0x88(%rbp)
movl   $0x0,-0x8c(%rbp)
movslq -0x88(%rbp),%rax
cmpq   $0x0,-0x40(%rbp,%rax,8)
je     12ff <dump_tune_vm+0x1af>
movslq -0x88(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    126c <dump_tune_vm+0x11c>
movl   $0xffffffff,-0x8c(%rbp)
ff ff ff
jmp    1304 <dump_tune_vm+0x1b4>
mov    -0x84(%rbp),%eax
mov    %eax,-0xa4(%rbp)
movslq -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rax
mov    %rax,-0xa0(%rbp)
movslq -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
call   1040 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x98(%rbp)
movslq -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
cmp    %rcx,%rax
je     12eb <dump_tune_vm+0x19b>
movl   $0xffffffff,-0x8c(%rbp)
ff ff ff
jmp    1304 <dump_tune_vm+0x1b4>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    121d <dump_tune_vm+0xcd>
jmp    1304 <dump_tune_vm+0x1b4>
cmpl   $0x0,-0x84(%rbp)
jl     131c <dump_tune_vm+0x1cc>
mov    -0x84(%rbp),%edi
call   1060 <close@plt>
mov    -0x8c(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_tune_vm>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
movq   $0x0,0x70(%rsp)
lea    0xea1(%rip),%rdi
mov    %rdi,0x40(%rsp)
lea    0xeae(%rip),%rax
mov    %rax,0x48(%rsp)
lea    0xec6(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xee1(%rip),%rax
mov    %rax,0x58(%rsp)
lea    0xef9(%rip),%rax
mov    %rax,0x60(%rsp)
lea    0xf0d(%rip),%rax
mov    %rax,0x68(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xf24(%rip),%rax
mov    %rax,(%rsp)
lea    0xf0f(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xf05(%rip),%rax
mov    %rax,0x10(%rsp)
mov    %rax,0x18(%rsp)
lea    0xef7(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xeef(%rip),%rax
mov    %rax,0x28(%rsp)
xor    %ebx,%ebx
mov    0x2df6(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%esi
call   1060 <open@plt>
test   %eax,%eax
js     124c <dump_tune_vm+0x10c>
mov    %eax,%r15d
mov    (%rsp,%rbx,1),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    %rax,%r14
jne    1253 <dump_tune_vm+0x113>
mov    0x48(%rsp,%rbx,1),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1200 <dump_tune_vm+0xc0>
xor    %ebp,%ebp
jmp    1258 <dump_tune_vm+0x118>
mov    $0xffffffff,%ebp
jmp    1260 <dump_tune_vm+0x120>
mov    $0xffffffff,%ebp
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/sys/vm/dirty_ratio\00"
@.str.1 = [36 x i8] c"/proc/sys/vm/dirty_background_ratio\00"
@.str.2 = [39 x i8] c"/proc/sys/vm/dirty_writeback_centisecs\00"
@.str.3 = [36 x i8] c"/proc/sys/vm/dirty_expire_centisecs\00"
@.str.4 = [32 x i8] c"/proc/sys/vm/vfs_cache_pressure\00"
@.str.5 = [34 x i8] c"/proc/sys/vm/lowmem_reserve_ratio\00"
@.str.6 = [2 x i8] c"2\00"
@.str.7 = [2 x i8] c"5\00"
@.str.8 = [3 x i8] c"50\00"
@.str.9 = [4 x i8] c"500\00"
@.str.10 = [3 x i8] c"32\00"
@O_RDWR = global i32 0
define i32 @dump_tune_vm() {
%1 = alloca [7 x i8*]
%2 = alloca [7 x i8*]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [7 x i8*]* %1 to i8*
%7 = bitcast i8* %6 to [7 x i8*]*
%8 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i32 0, i32 0
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i32 0, i32 1
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i32 0, i32 2
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i32 0, i32 3
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i32 0, i32 4
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i32 0, i32 5
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i32 0, i32 0), i8** %13
%14 = bitcast [7 x i8*]* %2 to i8*
%15 = bitcast i8* %14 to [7 x i8*]*
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %15, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* %15, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [7 x i8*], [7 x i8*]* %15, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [7 x i8*], [7 x i8*]* %15, i32 0, i32 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [7 x i8*], [7 x i8*]* %15, i32 0, i32 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8** %20
%21 = getelementptr inbounds [7 x i8*], [7 x i8*]* %15, i32 0, i32 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i32 0, i32 0), i8** %21
store i32 -1, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %22
22: ; preds = %57, %0
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %60
28: ; preds = %22
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDWR
%34 = call i32 @open(i8* %32, i32 %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %28
store i32 -1, i32* %5
br label %61
38: ; preds = %28
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = call i64 @strlen(i8* %47)
%49 = call i64 @write(i32 %39, i8* %43, i64 %48)
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %51
%53 = load i8*, i8** %52
%54 = call i64 @strlen(i8* %53)
%55 = icmp ne i64 %49, %54
br i1 %55, label %56, label %57
56: ; preds = %38
store i32 -1, i32* %5
br label %61
57: ; preds = %38
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %22
60: ; preds = %22
br label %61
61: ; preds = %60, %56, %37
%62 = load i32, i32* %3
%63 = icmp sge i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %3
%66 = call i32 @close(i32 %65)
br label %67
67: ; preds = %64, %61
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/sys/vm/dirty_ratio\00"
@.str.1 = [36 x i8] c"/proc/sys/vm/dirty_background_ratio\00"
@.str.2 = [39 x i8] c"/proc/sys/vm/dirty_writeback_centisecs\00"
@.str.3 = [36 x i8] c"/proc/sys/vm/dirty_expire_centisecs\00"
@.str.4 = [32 x i8] c"/proc/sys/vm/vfs_cache_pressure\00"
@.str.5 = [34 x i8] c"/proc/sys/vm/lowmem_reserve_ratio\00"
@.str.6 = [2 x i8] c"2\00"
@.str.7 = [2 x i8] c"5\00"
@.str.8 = [3 x i8] c"50\00"
@.str.9 = [4 x i8] c"500\00"
@.str.10 = [3 x i8] c"32\00"
@O_RDWR = global i32 0
define i32 @dump_tune_vm() {
%1 = alloca [7 x i8*]
%2 = alloca [7 x i8*]
%3 = bitcast [7 x i8*]* %1 to i8*
%4 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 6
%5 = bitcast i8** %4 to i64*
store i64 0, i64* %5
%6 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 4
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 5
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8** %11
%12 = bitcast [7 x i8*]* %2 to i8*
%13 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 6
%14 = bitcast i8** %13 to i64*
store i64 0, i64* %14
%15 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8** %20
br label %25
21: ; preds = %31
%22 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 %38
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %39, label %25
25: ; preds = %0, %21
%26 = phi i64 [ 0, %0 ], [ %38, %21 ]
%27 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %0 ], [ %23, %21 ]
%28 = load i32, i32* @O_RDWR
%29 = tail call i32 @open(i8* %27, i32 %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %42, label %31
31: ; preds = %25
%32 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %26
%33 = load i8*, i8** %32
%34 = tail call i64 @strlen(i8* dereferenceable(1) %33)
%35 = tail call i64 @write(i32 %29, i8* %33, i64 %34)
%36 = tail call i64 @strlen(i8* dereferenceable(1) %33)
%37 = icmp eq i64 %35, %36
%38 = add nuw i64 %26, 1
br i1 %37, label %21, label %39
39: ; preds = %31, %21
%40 = phi i32 [ 0, %21 ], [ -1, %31 ]
%41 = tail call i32 @close(i32 %29)
br label %42
42: ; preds = %25, %39
%43 = phi i32 [ %40, %39 ], [ -1, %25 ]
ret i32 %43
}