#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 */
scalar_t__ write_to_file(char *, char *);
int 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 i;
  i = 0;
  while (sysctl_names[i]) {
    if (write_to_file(sysctl_names[i], sysctl_values[i]))
      return -1;
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tune_vm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
lea    0xebe(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xecc(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xee5(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xf01(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xf1a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xf2f(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
lea    0xf40(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xf2b(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xf22(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xf17(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xf0f(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xf08(%rip),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rax
cmpq   $0x0,-0x40(%rbp,%rax,8)
je     1233 <tune_vm+0x113>
movslq -0x84(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rsi
call   1030 <write_to_file@plt>
cmp    $0x0,%rax
je     121f <tune_vm+0xff>
movl   $0xffffffff,-0x4(%rbp)
jmp    123a <tune_vm+0x11a>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11d9 <tune_vm+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tune_vm>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
movq   $0x0,0x70(%rsp)
lea    0xeda(%rip),%rdi
mov    %rdi,0x40(%rsp)
lea    0xee7(%rip),%rax
mov    %rax,0x48(%rsp)
lea    0xeff(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xf1a(%rip),%rax
mov    %rax,0x58(%rsp)
lea    0xf32(%rip),%rax
mov    %rax,0x60(%rsp)
lea    0xf46(%rip),%rax
mov    %rax,0x68(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xf5d(%rip),%rsi
mov    %rsi,(%rsp)
lea    0xf48(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xf3e(%rip),%rax
mov    %rax,0x10(%rsp)
mov    %rax,0x18(%rsp)
lea    0xf30(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xf28(%rip),%rax
mov    %rax,0x28(%rsp)
call   1030 <write_to_file@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11f0 <tune_vm+0xe0>
mov    $0x8,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x40(%rsp,%rbx,1),%rdi
test   %rdi,%rdi
je     11ee <tune_vm+0xde>
mov    (%rsp,%rbx,1),%rsi
call   1030 <write_to_file@plt>
add    $0x8,%rbx
test   %rax,%rax
je     11d0 <tune_vm+0xc0>
jmp    11f0 <tune_vm+0xe0>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
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"
define i32 @tune_vm() {
%1 = alloca i32
%2 = alloca [7 x i8*]
%3 = alloca [7 x i8*]
%4 = alloca i32
%5 = bitcast [7 x i8*]* %2 to i8*
%6 = bitcast i8* %5 to [7 x i8*]*
%7 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i32 0, i32 0
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i8** %7
%8 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i32 0, i32 1
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i32 0, i32 2
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i32 0, i32 3
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i32 0, i32 4
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i32 0, i32 5
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i32 0, i32 0), i8** %12
%13 = bitcast [7 x i8*]* %3 to i8*
%14 = bitcast i8* %13 to [7 x i8*]*
%15 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i32 0, i32 3
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*]* %14, i32 0, i32 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [7 x i8*], [7 x i8*]* %14, i32 0, i32 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i32 0, i32 0), i8** %20
store i32 0, i32* %4
br label %21
21: ; preds = %39, %0
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %42
27: ; preds = %21
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [7 x i8*], [7 x i8*]* %3, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = call i64 @write_to_file(i8* %31, i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %27
store i32 -1, i32* %1
br label %43
39: ; preds = %27
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %21
42: ; preds = %21
store i32 0, i32* %1
br label %43
43: ; preds = %42, %38
%44 = load i32, i32* %1
ret i32 %44
}

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"
define i32 @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
%21 = tail call i64 @write_to_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %0, %28
%24 = phi i64 [ %33, %28 ], [ 1, %0 ]
%25 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %34, label %28
28: ; preds = %23
%29 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %24
%30 = load i8*, i8** %29
%31 = tail call i64 @write_to_file(i8* %26, i8* %30)
%32 = icmp eq i64 %31, 0
%33 = add nuw i64 %24, 1
br i1 %32, label %23, label %34
34: ; preds = %23, %28, %0
%35 = phi i32 [ -1, %0 ], [ 0, %23 ], [ -1, %28 ]
ret i32 %35
}