#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 */
scalar_t__ read_text(char *, char *, int);
char *strtok(char *, char const *);
int is_swap_enabled(void) {
  char buf[4096];
  const char delim[] = "\n";
  int cnt = 0;
  char *line;
  if (read_text("/proc/swaps", buf, sizeof(buf)) <= 0)
    return -1;
  for (line = strtok(buf, delim); line; line = strtok(NULL, delim))
    cnt++;
  return cnt > 1;
}


x86 assembly (clang, -O0):
<is_swap_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    0xece(%rip),%ax
mov    %ax,-0x1012(%rbp)
movl   $0x0,-0x1018(%rbp)
lea    -0x1010(%rbp),%rsi
lea    0xeb1(%rip),%rdi
mov    $0x1000,%edx
call   1030 <read_text@plt>
cmp    $0x0,%rax
jg     1171 <is_swap_enabled+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <is_swap_enabled+0xb6>
lea    -0x1010(%rbp),%rdi
lea    -0x1012(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
je     11c4 <is_swap_enabled+0xa4>
mov    -0x1018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1018(%rbp)
lea    -0x1012(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x1020(%rbp)
jmp    118b <is_swap_enabled+0x6b>
cmpl   $0x1,-0x1018(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_swap_enabled>:
push   %rbp
push   %rbx
sub    $0x1018,%rsp
movw   $0xa,0xe(%rsp)
lea    0xec9(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x1000,%edx
call   1030 <read_text@plt>
test   %rax,%rax
jle    118b <is_swap_enabled+0x6b>
lea    0x10(%rsp),%rdi
lea    0xe(%rsp),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1192 <is_swap_enabled+0x72>
mov    $0x1,%ebp
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <strtok@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1170 <is_swap_enabled+0x50>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
jmp    1194 <is_swap_enabled+0x74>
mov    $0xffffffff,%eax
jmp    1194 <is_swap_enabled+0x74>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.is_swap_enabled.delim = [2 x i8] c"\0A\00"
@.str = [12 x i8] c"/proc/swaps\00"
define i32 @is_swap_enabled() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast [2 x i8]* %3 to i8*
store i32 0, i32* %4
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%8 = call i64 @read_text(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %7, i32 4096)
%9 = icmp sle i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %28
11: ; preds = %0
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%14 = call i8* @strtok(i8* %12, i8* %13)
store i8* %14, i8** %5
br label %15
15: ; preds = %21, %11
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %18
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%23 = call i8* @strtok(i8* null, i8* %22)
store i8* %23, i8** %5
br label %15
24: ; preds = %15
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 1
%27 = zext i1 %26 to i32
store i32 %27, i32* %1
br label %28
28: ; preds = %24, %10
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [12 x i8] c"/proc/swaps\00"
define i32 @is_swap_enabled() {
%1 = alloca [4096 x i8]
%2 = alloca i16
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = bitcast i16* %2 to i8*
store i16 10, i16* %2
%5 = call i64 @read_text(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %3, i32 4096)
%6 = icmp slt i64 %5, 1
br i1 %6, label %18, label %7
7: ; preds = %0
%8 = call i8* @strtok(i8* %3, i8* %4)
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7, %10
%11 = phi i32 [ %12, %10 ], [ 0, %7 ]
%12 = add nuw nsw i32 %11, 1
%13 = call i8* @strtok(i8* null, i8* %4)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = icmp ne i32 %11, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %7, %15, %0
%19 = phi i32 [ -1, %0 ], [ 0, %7 ], [ %17, %15 ]
ret i32 %19
}