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

/* Variables and functions */
int EACCES;
int errno;
int /*<<< orphan*/ swap_path(char *, int);
scalar_t__ swapon(char *, int /*<<< orphan*/);
int swap_switch_on(void) {
  char path[256];
  if (!swap_path(path, sizeof(path)))
    return EACCES;
  return (swapon(path, 0) ? errno : 0);
}


x86 assembly (clang, -O0):
<swap_switch_on>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1030 <swap_path@plt>
cmp    $0x0,%eax
jne    1156 <swap_switch_on+0x36>
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <swap_switch_on+0x78>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
call   1040 <swapon@plt>
cmp    $0x0,%rax
je     1182 <swap_switch_on+0x62>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
jmp    118f <swap_switch_on+0x6f>
xor    %eax,%eax
mov    %eax,-0x114(%rbp)
jmp    118f <swap_switch_on+0x6f>
mov    -0x114(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_switch_on>:
push   %rbx
sub    $0x100,%rsp
mov    %rsp,%rdi
mov    $0x100,%esi
call   1030 <swap_path@plt>
test   %eax,%eax
je     1153 <swap_switch_on+0x33>
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <swapon@plt>
test   %rax,%rax
je     115c <swap_switch_on+0x3c>
mov    0x2e87(%rip),%rax
jmp    115a <swap_switch_on+0x3a>
mov    0x2e8e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@EACCES = global i32 0
@errno = global i32 0
define i32 @swap_switch_on() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @swap_path(i8* %3, i32 256)
%5 = icmp ne i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = load i32, i32* @EACCES
store i32 %7, i32* %1
br label %17
8: ; preds = %0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%10 = call i64 @swapon(i8* %9, i32 0)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i32, i32* @errno
br label %15
14: ; preds = %8
br label %15
15: ; preds = %14, %12
%16 = phi i32 [ %13, %12 ], [ 0, %14 ]
store i32 %16, i32* %1
br label %17
17: ; preds = %15, %6
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@EACCES = global i32 0
@errno = global i32 0
define i32 @swap_switch_on() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @swap_path(i8* %2, i32 256)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i32, i32* @EACCES
br label %12
7: ; preds = %0
%8 = call i64 @swapon(i8* %2, i32 0)
%9 = icmp eq i64 %8, 0
%10 = load i32, i32* @errno
%11 = select i1 %9, i32 0, i32 %10
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ %11, %7 ], [ %6, %5 ]
ret i32 %13
}