#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 /*<<< orphan*/ enter_sysfs();
int /*<<< orphan*/ exit_sysfs();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
void readahead_set_len(int size) {
  int i = 0;
  char ractl[100];
  enter_sysfs();
  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++;
  }
  exit_sysfs();
}


x86 assembly (clang, -O0):
<readahead_set_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <enter_sysfs@plt>
lea    -0x70(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <sprintf@plt>
cmpl   $0x3,-0x8(%rbp)
jg     11e7 <readahead_set_len+0x87>
lea    -0x70(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     11d1 <readahead_set_len+0x71>
mov    -0x78(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x6e(%rbp),%al
add    $0x1,%al
mov    %al,-0x6e(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118c <readahead_set_len+0x2c>
mov    $0x0,%al
call   1070 <exit_sysfs@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readahead_set_len>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <enter_sysfs@plt>
movabs $0x626b5f64616568,%rax
mov    %rax,0x10(%rsp)
movups 0xe8b(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a9 <readahead_set_len+0x59>
mov    %rax,%rbx
lea    0xe83(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movb   $0x62,0x2(%rsp)
lea    0xe63(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11de <readahead_set_len+0x8e>
mov    %rax,%rbx
lea    0xe4e(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movb   $0x63,0x2(%rsp)
lea    0xe2e(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1213 <readahead_set_len+0xc3>
mov    %rax,%rbx
lea    0xe19(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movb   $0x64,0x2(%rsp)
lea    0xdf9(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1248 <readahead_set_len+0xf8>
mov    %rax,%rbx
lea    0xde4(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <exit_sysfs@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"sda/queue/read_ahead_kb\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @readahead_set_len(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca i32*
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = call i32 (...) @enter_sysfs()
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %23, %1
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 3
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32*, i32** %5
%19 = load i32, i32* %2
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %5
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %17, %12
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 2
%25 = load i8, i8* %24
%26 = add i8 %25, 1
store i8 %26, i8* %24
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %9
29: ; preds = %9
%30 = call i32 (...) @exit_sysfs()
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"sda/queue/read_ahead_kb\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\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 (...) @enter_sysfs()
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%10 = tail call i32 @fclose(i32* %6)
br label %11
11: ; preds = %8, %1
store i8 98, i8* %5
%12 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%16 = tail call i32 @fclose(i32* %12)
br label %17
17: ; preds = %14, %11
store i8 99, i8* %5
%18 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%22 = tail call i32 @fclose(i32* %18)
br label %23
23: ; preds = %20, %17
store i8 100, i8* %5
%24 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = tail call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%28 = tail call i32 @fclose(i32* %24)
br label %29
29: ; preds = %26, %23
%30 = tail call i32 (...) @exit_sysfs()
ret void
}