#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ swapoff(char *);
void disableSwap(void) {
  int fd;
  char buf[4096];
  int i;
  char *start;
  char *chptr;
  if ((fd = open("/proc/swaps", O_RDONLY, 0)) < 0)
    return;
  i = read(fd, buf, sizeof(buf) - 1);
  close(fd);
  if (i < 0)
    return;
  buf[i] = '\0';
  start = buf;
  while (*start) {
    while (*start != '\n' && *start)
      start++;
    if (!*start)
      return;
    start++;
    if (*start != '/')
      return;
    chptr = start;
    while (*chptr && *chptr != ' ')
      chptr++;
    if (!(*chptr))
      return;
    *chptr = '\0';
    printf("\t%s", start);
    if (swapoff(start))
      printf(" failed (%d)", errno);
    printf("\n");
    start = chptr + 1;
  }
}


x86 assembly (clang, -O0):
<disableSwap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1183 <disableSwap+0x33>
jmp    1372 <disableSwap+0x222>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0xfff,%edx
call   1050 <read@plt>
mov    %eax,-0x1014(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x1014(%rbp)
jge    11b7 <disableSwap+0x67>
jmp    1372 <disableSwap+0x222>
movslq -0x1014(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rax
cmpb   $0x0,(%rax)
je     1372 <disableSwap+0x222>
jmp    11e9 <disableSwap+0x99>
mov    -0x1020(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1029(%rbp)
je     121a <disableSwap+0xca>
mov    -0x1020(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1029(%rbp)
mov    -0x1029(%rbp),%al
test   $0x1,%al
jne    122d <disableSwap+0xdd>
jmp    1244 <disableSwap+0xf4>
mov    -0x1020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1020(%rbp)
jmp    11e9 <disableSwap+0x99>
mov    -0x1020(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1259 <disableSwap+0x109>
jmp    1372 <disableSwap+0x222>
mov    -0x1020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1283 <disableSwap+0x133>
jmp    1372 <disableSwap+0x222>
mov    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x102a(%rbp)
je     12c2 <disableSwap+0x172>
mov    -0x1028(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x102a(%rbp)
mov    -0x102a(%rbp),%al
test   $0x1,%al
jne    12d5 <disableSwap+0x185>
jmp    12ec <disableSwap+0x19c>
mov    -0x1028(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
jmp    1291 <disableSwap+0x141>
mov    -0x1028(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1301 <disableSwap+0x1b1>
jmp    1372 <disableSwap+0x222>
mov    -0x1028(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1020(%rbp),%rsi
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1020(%rbp),%rdi
call   1070 <swapoff@plt>
cmp    $0x0,%rax
je     134d <disableSwap+0x1fd>
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
lea    0xcca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1028(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1020(%rbp)
jmp    11d4 <disableSwap+0x84>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disableSwap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
test   %eax,%eax
js     127f <disableSwap+0x11f>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xfff,%edx
call   1060 <read@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1050 <close@plt>
test   %r14d,%r14d
js     127f <disableSwap+0x11f>
mov    %r14d,%eax
movb   $0x0,(%rsp,%rax,1)
mov    (%rsp),%al
test   %al,%al
je     127f <disableSwap+0x11f>
lea    0xe3e(%rip),%r14
mov    0x2e03(%rip),%rbp
lea    0xe34(%rip),%r15
cmp    $0xa,%al
je     1200 <disableSwap+0xa0>
test   %al,%al
je     127f <disableSwap+0x11f>
mov    0x1(%rbx),%al
add    $0x1,%rbx
jmp    11dc <disableSwap+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,0x1(%rbx)
jne    127f <disableSwap+0x11f>
lea    0x1(%rbx),%r12
add    $0x2,%rbx
mov    $0x2f,%al
test   %al,%al
je     127f <disableSwap+0x11f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x20,%al
je     1240 <disableSwap+0xe0>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1220 <disableSwap+0xc0>
jmp    127f <disableSwap+0x11f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,-0x1(%rbx)
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1080 <swapoff@plt>
test   %rax,%rax
je     126b <disableSwap+0x10b>
mov    0x0(%rbp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rbx),%al
test   %al,%al
jne    11dc <disableSwap+0x7c>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/proc/swaps\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"\09%s\00"
@.str.2 = [13 x i8] c" failed (%d)\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
define void @disableSwap() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
store i32 %7, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
br label %93
10: ; preds = %0
%11 = load i32, i32* %1
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 4095)
store i32 %13, i32* %3
%14 = load i32, i32* %1
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
br label %93
19: ; preds = %10
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
store i8* %23, i8** %4
br label %24
24: ; preds = %89, %19
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %93
28: ; preds = %24
br label %29
29: ; preds = %41, %28
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %34, %29
%40 = phi i1 [ false, %29 ], [ %38, %34 ]
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
br label %29
44: ; preds = %39
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %44
br label %93
49: ; preds = %44
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
%52 = load i8*, i8** %4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 47
br i1 %55, label %56, label %57
56: ; preds = %49
br label %93
57: ; preds = %49
%58 = load i8*, i8** %4
store i8* %58, i8** %5
br label %59
59: ; preds = %71, %57
%60 = load i8*, i8** %5
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load i8*, i8** %5
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %67, 32
br label %69
69: ; preds = %64, %59
%70 = phi i1 [ false, %59 ], [ %68, %64 ]
br i1 %70, label %71, label %74
71: ; preds = %69
%72 = load i8*, i8** %5
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %5
br label %59
74: ; preds = %69
%75 = load i8*, i8** %5
%76 = load i8, i8* %75
%77 = icmp ne i8 %76, 0
br i1 %77, label %79, label %78
78: ; preds = %74
br label %93
79: ; preds = %74
%80 = load i8*, i8** %5
store i8 0, i8* %80
%81 = load i8*, i8** %4
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %81)
%83 = load i8*, i8** %4
%84 = call i64 @swapoff(i8* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %79
%87 = load i32, i32* @errno
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %86, %79
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%91 = load i8*, i8** %5
%92 = getelementptr inbounds i8, i8* %91, i64 1
store i8* %92, i8** %4
br label %24
93: ; preds = %9, %18, %48, %56, %78, %24
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"/proc/swaps\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"\09%s\00"
@.str.2 = [13 x i8] c" failed (%d)\00"
@errno = global i32 0
define void @disableSwap() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %46, label %6
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 4095)
%8 = tail call i32 @close(i32 %4)
%9 = icmp slt i32 %7, 0
br i1 %9, label %46, label %10
10: ; preds = %6
%11 = zext i32 %7 to i64
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 0
br i1 %14, label %46, label %15
15: ; preds = %10, %21
%16 = phi i8 [ %22, %21 ], [ %13, %10 ]
%17 = phi i8* [ %23, %21 ], [ %2, %10 ]
switch i8 %16, label %18 [
i8 0, label %46
i8 10, label %24
]
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = load i8, i8* %19
br label %21
21: ; preds = %18, %41
%22 = phi i8 [ %20, %18 ], [ %44, %41 ]
%23 = phi i8* [ %19, %18 ], [ %43, %41 ]
br label %15
24: ; preds = %15
%25 = getelementptr inbounds i8, i8* %17, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 47
br i1 %27, label %28, label %46
28: ; preds = %24, %31
%29 = phi i8 [ %33, %31 ], [ 47, %24 ]
%30 = phi i8* [ %32, %31 ], [ %25, %24 ]
switch i8 %29, label %31 [
i8 0, label %46
i8 32, label %34
]
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %30, i64 1
%33 = load i8, i8* %32
br label %28
34: ; preds = %28
store i8 0, i8* %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%36 = call i64 @swapoff(i8* %25)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = load i32, i32* @errno
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %34
%42 = call i32 @putchar(i32 10)
%43 = getelementptr inbounds i8, i8* %30, i64 1
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
br i1 %45, label %46, label %21
46: ; preds = %24, %41, %15, %28, %10, %6, %0
ret void
}