#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 chdir(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ mount(char *, char *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ umount(char *);
void readahead_set_len(int size) {
  int unmount;
  int i = 0;
  char ractl[100];
  unmount = chdir("/sys/block");
  if (unmount != 0) {
    if (mount("sysfs", "/sys", "sysfs", 0, NULL) != 0) {
      perror("Unable to mount sysfs\n");
      return;
    }
    chdir("/sys/block");
  }
  sprintf(ractl, "sda/queue/read_ahead_kb");
  while (i <= 3) {
    FILE *file = fopen(ractl, "w");
    if (file) {
      fprintf(file, "%d", size);
      fclose(file);
    }
    ractl[2]++;
    i++;
  }
  chdir("/");
  if (unmount != 0)
    umount("/sys");
}


x86 assembly (clang, -O0):
<readahead_set_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe64(%rip),%rdi
call   1060 <chdir@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11f2 <readahead_set_len+0x72>
lea    0xe56(%rip),%rdx
lea    0xe55(%rip),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1050 <mount@plt>
cmp    $0x0,%rax
je     11e6 <readahead_set_len+0x66>
lea    0xe3a(%rip),%rdi
call   1090 <perror@plt>
jmp    127f <readahead_set_len+0xff>
lea    0xe13(%rip),%rdi
call   1060 <chdir@plt>
lea    -0x70(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <sprintf@plt>
cmpl   $0x3,-0xc(%rbp)
jg     125d <readahead_set_len+0xdd>
lea    -0x70(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1247 <readahead_set_len+0xc7>
mov    -0x78(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe0e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x6e(%rbp),%al
add    $0x1,%al
mov    %al,-0x6e(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1202 <readahead_set_len+0x82>
lea    0xde6(%rip),%rdi
call   1060 <chdir@plt>
cmpl   $0x0,-0x8(%rbp)
je     127f <readahead_set_len+0xff>
lea    0xd97(%rip),%rdi
call   1030 <umount@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readahead_set_len>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebp
lea    0xe7f(%rip),%rdi
call   1060 <chdir@plt>
mov    %eax,%r14d
test   %eax,%eax
je     11bd <readahead_set_len+0x4d>
lea    0xe7d(%rip),%rsi
lea    0xe70(%rip),%rdi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %rax,%rax
jne    12d4 <readahead_set_len+0x164>
lea    0xe48(%rip),%rdi
call   1060 <chdir@plt>
movups 0xe69(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x626b5f64616568,%rax
mov    %rax,0x10(%rsp)
lea    0xe67(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1207 <readahead_set_len+0x97>
mov    %rax,%rbx
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x62,0x2(%rsp)
lea    0xe32(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     123c <readahead_set_len+0xcc>
mov    %rax,%rbx
lea    0xe1d(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x63,0x2(%rsp)
lea    0xdfd(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1271 <readahead_set_len+0x101>
mov    %rax,%rbx
lea    0xde8(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x64,0x2(%rsp)
lea    0xdc8(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a6 <readahead_set_len+0x136>
mov    %rax,%rbx
lea    0xdb3(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd9d(%rip),%rdi
call   1060 <chdir@plt>
test   %r14d,%r14d
je     12cb <readahead_set_len+0x15b>
lea    0xd53(%rip),%rdi
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <umount@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd3b(%rip),%rdi
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <perror@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/sys/block\00"
@.str.1 = [6 x i8] c"sysfs\00"
@.str.2 = [5 x i8] c"/sys\00"
@.str.3 = [23 x i8] c"Unable to mount sysfs\0A\00"
@.str.4 = [24 x i8] c"sda/queue/read_ahead_kb\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [2 x i8] c"/\00"
define void @readahead_set_len(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32*
store i32 %0, i32* %2
store i32 0, i32* %4
%7 = call i32 @chdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = call i64 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 0, i32* null)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %46
15: ; preds = %10
%16 = call i32 @chdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%19 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %34, %17
%21 = load i32, i32* %4
%22 = icmp sle i32 %21, 3
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32*, i32** %6
%30 = load i32, i32* %2
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %28, %23
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 2
%36 = load i8, i8* %35
%37 = add i8 %36, 1
store i8 %37, i8* %35
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %20
40: ; preds = %20
%41 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%42 = load i32, i32* %3
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @umount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %13, %44, %40
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/sys/block\00"
@.str.1 = [6 x i8] c"sysfs\00"
@.str.2 = [5 x i8] c"/sys\00"
@.str.3 = [23 x i8] c"Unable to mount sysfs\0A\00"
@.str.4 = [24 x i8] c"sda/queue/read_ahead_kb\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [2 x i8] c"/\00"
define void @readahead_set_len(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @chdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = tail call i64 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 0, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %42
11: ; preds = %6
%12 = tail call i32 @chdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%15 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %0)
%19 = tail call i32 @fclose(i32* %15)
br label %20
20: ; preds = %17, %13
store i8 98, i8* %14
%21 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %0)
%25 = tail call i32 @fclose(i32* %21)
br label %26
26: ; preds = %23, %20
store i8 99, i8* %14
%27 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = tail call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %0)
%31 = tail call i32 @fclose(i32* %27)
br label %32
32: ; preds = %29, %26
store i8 100, i8* %14
%33 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = tail call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %0)
%37 = tail call i32 @fclose(i32* %33)
br label %38
38: ; preds = %35, %32
%39 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br i1 %5, label %42, label %40
40: ; preds = %38
%41 = tail call i32 @umount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %38, %40, %9
ret void
}