#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ ksft_exit_fail_msg(char *, int /*<<< orphan*/);
int /*<<< orphan*/ ksft_exit_skip(char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strerror(scalar_t__);
void sync_api_supported(void) {
  struct stat sbuf;
  int ret;
  ret = stat("/sys/kernel/debug/sync/sw_sync", &sbuf);
  if (!ret)
    return;
  if (errno == ENOENT)
    ksft_exit_skip("Sync framework not supported by kernel\n");
  if (errno == EACCES)
    ksft_exit_skip("Run Sync test as root.\n");
  ksft_exit_fail_msg("stat failed on /sys/kernel/debug/sync/sw_sync: %s",
                     strerror(errno));
}


x86 assembly (clang, -O0):
<sync_api_supported>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116a <sync_api_supported+0x2a>
jmp    11d3 <sync_api_supported+0x93>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%rax
jne    1190 <sync_api_supported+0x50>
lea    0xe94(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
jne    11b6 <sync_api_supported+0x76>
lea    0xe96(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
call   1030 <ksft_exit_fail_msg@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_api_supported>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %eax,%eax
je     11b2 <sync_api_supported+0x72>
mov    0x2e77(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2e5d(%rip),%rax
cmp    (%rax),%rdi
jne    117f <sync_api_supported+0x3f>
lea    0xea8(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
mov    (%rbx),%rdi
mov    0x2e62(%rip),%rax
cmp    (%rax),%rdi
jne    119a <sync_api_supported+0x5a>
lea    0xeb5(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
mov    (%rbx),%rdi
call   1060 <strerror@plt>
lea    0xeb9(%rip),%rdi
mov    %eax,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <ksft_exit_fail_msg@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [31 x i8] c"/sys/kernel/debug/sync/sw_sync\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [40 x i8] c"Sync framework not supported by kernel\0A\00"
@EACCES = global i64 0
@.str.2 = [24 x i8] c"Run Sync test as root.\0A\00"
@.str.3 = [50 x i8] c"stat failed on /sys/kernel/debug/sync/sw_sync: %s\00"
define void @sync_api_supported() {
%1 = alloca %struct.stat
%2 = alloca i32
%3 = call i32 @stat(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
br label %23
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @ksft_exit_skip(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = load i64, i64* @errno
%15 = load i64, i64* @EACCES
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @ksft_exit_skip(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = load i64, i64* @errno
%21 = call i32 @strerror(i64 %20)
%22 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %6
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [31 x i8] c"/sys/kernel/debug/sync/sw_sync\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [40 x i8] c"Sync framework not supported by kernel\0A\00"
@EACCES = global i64 0
@.str.2 = [24 x i8] c"Run Sync test as root.\0A\00"
@.str.3 = [50 x i8] c"stat failed on /sys/kernel/debug/sync/sw_sync: %s\00"
define void @sync_api_supported() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @ksft_exit_skip(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%11 = load i64, i64* @errno
br label %12
12: ; preds = %9, %5
%13 = phi i64 [ %11, %9 ], [ %6, %5 ]
%14 = load i64, i64* @EACCES
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @ksft_exit_skip(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%18 = load i64, i64* @errno
br label %19
19: ; preds = %16, %12
%20 = phi i64 [ %18, %16 ], [ %13, %12 ]
%21 = tail call i32 @strerror(i64 %20)
%22 = tail call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %0, %19
ret void
}