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

/* Variables and functions */
scalar_t__ EINVAL;
int MEMBARRIER_CMD_QUERY;
scalar_t__ errno;
int /*<<< orphan*/ ksft_exit_fail_msg(char *, char const *, int, ...);
int /*<<< orphan*/ ksft_test_result_pass(char *, char const *, int, scalar_t__);
int /*<<< orphan*/ strerror(scalar_t__);
int sys_membarrier(int, int);
int test_membarrier_flags_fail(void) {
  int cmd = MEMBARRIER_CMD_QUERY, flags = 1;
  const char *test_name = "sys membarrier MEMBARRIER_CMD_QUERY invalid flags";
  if (sys_membarrier(cmd, flags) != -1) {
    ksft_exit_fail_msg("%s test: flags = %d. Should fail, but passed\n",
                       test_name, flags);
  }
  if (errno != EINVAL) {
    ksft_exit_fail_msg("%s test: flags = %d. Should return (%d: \"%s\"), but "
                       "returned (%d: \"%s\").\n",
                       test_name, flags, EINVAL, strerror(EINVAL), errno,
                       strerror(errno));
  }
  ksft_test_result_pass("%s test: flags = %d, errno = %d. Failed as expected\n",
                        test_name, flags, errno);
  return 0;
}


x86 assembly (clang, -O0):
<test_membarrier_flags_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xe9e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <sys_membarrier@plt>
cmp    $0xffffffff,%eax
je     118f <test_membarrier_flags_fail+0x4f>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_exit_fail_msg@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
je     1218 <test_membarrier_flags_fail+0xd8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
mov    -0x18(%rbp),%r9
lea    0xe52(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <ksft_exit_fail_msg@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    0x2db2(%rip),%rax
mov    (%rax),%rcx
lea    0xe79(%rip),%rdi
call   1030 <ksft_test_result_pass@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_membarrier_flags_fail>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <sys_membarrier@plt>
cmp    $0xffffffff,%eax
je     1179 <test_membarrier_flags_fail+0x39>
lea    0xecc(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <ksft_exit_fail_msg@plt>
mov    0x2e58(%rip),%r15
mov    (%r15),%rcx
mov    0x2e46(%rip),%rax
mov    (%rax),%rbx
cmp    %rbx,%rcx
je     11d1 <test_membarrier_flags_fail+0x91>
mov    %rbx,%rdi
call   1060 <strerror@plt>
mov    %eax,%r14d
mov    (%r15),%rbp
mov    %rbp,%rdi
call   1060 <strerror@plt>
mov    %eax,(%rsp)
lea    0xeae(%rip),%rdi
lea    0xe47(%rip),%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
mov    %r14d,%r8d
mov    %rbp,%r9
xor    %eax,%eax
call   1040 <ksft_exit_fail_msg@plt>
mov    (%r15),%rcx
lea    0xed1(%rip),%rdi
lea    0xe21(%rip),%rsi
mov    $0x1,%edx
call   1030 <ksft_test_result_pass@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MEMBARRIER_CMD_QUERY = global i32 0
@.str = [50 x i8] c"sys membarrier MEMBARRIER_CMD_QUERY invalid flags\00"
@.str.1 = [46 x i8] c"%s test: flags = %d. Should fail, but passed\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [73 x i8] c"%s test: flags = %d. Should return (%d: \22%s\22), but returned (%d: \22%s\22).\0A\00"
@.str.3 = [53 x i8] c"%s test: flags = %d, errno = %d. Failed as expected\0A\00"
define i32 @test_membarrier_flags_fail() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = load i32, i32* @MEMBARRIER_CMD_QUERY
store i32 %4, i32* %1
store i32 1, i32* %2
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = call i32 @sys_membarrier(i32 %5, i32 %6)
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i8*, i8** %3
%11 = load i32, i32* %2
%12 = call i32 (i8*, i8*, i32, ...) @ksft_exit_fail_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %11)
br label %13
13: ; preds = %9, %0
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = load i64, i64* @EINVAL
%21 = load i64, i64* @EINVAL
%22 = call i32 @strerror(i64 %21)
%23 = load i64, i64* @errno
%24 = load i64, i64* @errno
%25 = call i32 @strerror(i64 %24)
%26 = call i32 (i8*, i8*, i32, ...) @ksft_exit_fail_msg(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %19, i64 %20, i32 %22, i64 %23, i32 %25)
br label %27
27: ; preds = %17, %13
%28 = load i8*, i8** %3
%29 = load i32, i32* %2
%30 = load i64, i64* @errno
%31 = call i32 @ksft_test_result_pass(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32 %29, i64 %30)
ret i32 0
}

LLVM IR (-O2):
@MEMBARRIER_CMD_QUERY = global i32 0
@.str = [50 x i8] c"sys membarrier MEMBARRIER_CMD_QUERY invalid flags\00"
@.str.1 = [46 x i8] c"%s test: flags = %d. Should fail, but passed\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [73 x i8] c"%s test: flags = %d. Should return (%d: \22%s\22), but returned (%d: \22%s\22).\0A\00"
@.str.3 = [53 x i8] c"%s test: flags = %d, errno = %d. Failed as expected\0A\00"
define i32 @test_membarrier_flags_fail() {
%1 = load i32, i32* @MEMBARRIER_CMD_QUERY
%2 = tail call i32 @sys_membarrier(i32 %1, i32 1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 (i8*, i8*, i32, ...) @ksft_exit_fail_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 1)
br label %6
6: ; preds = %4, %0
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINVAL
%9 = icmp eq i64 %7, %8
br i1 %9, label %16, label %10
10: ; preds = %6
%11 = tail call i32 @strerror(i64 %8)
%12 = load i64, i64* @errno
%13 = tail call i32 @strerror(i64 %12)
%14 = tail call i32 (i8*, i8*, i32, ...) @ksft_exit_fail_msg(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 1, i64 %8, i32 %11, i64 %12, i32 %13)
%15 = load i64, i64* @errno
br label %16
16: ; preds = %10, %6
%17 = phi i64 [ %15, %10 ], [ %7, %6 ]
%18 = tail call i32 @ksft_test_result_pass(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 1, i64 %17)
ret i32 0
}