#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 */
int MEMBARRIER_CMD_GLOBAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ ksft_exit_fail_msg(char *, char const *, int,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ ksft_test_result_pass(char *, char const *, int);
scalar_t__ sys_membarrier(int, int);
int test_membarrier_global_success(void) {
  int cmd = MEMBARRIER_CMD_GLOBAL, flags = 0;
  const char *test_name = "sys membarrier MEMBARRIER_CMD_GLOBAL";
  if (sys_membarrier(cmd, flags) != 0) {
    ksft_exit_fail_msg("%s test: flags = %d, errno = %d\n", test_name, flags,
                       errno);
  }
  ksft_test_result_pass("%s test: flags = %d\n", test_name, flags);
  return 0;
}


x86 assembly (clang, -O0):
<test_membarrier_global_success>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <sys_membarrier@plt>
cmp    $0x0,%rax
je     1187 <test_membarrier_global_success+0x57>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    0x2e5f(%rip),%rax
mov    (%rax),%ecx
lea    0xea3(%rip),%rdi
call   1040 <ksft_exit_fail_msg@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xeb1(%rip),%rdi
call   1030 <ksft_test_result_pass@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_membarrier_global_success>:
push   %rax
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <sys_membarrier@plt>
test   %rax,%rax
je     1164 <test_membarrier_global_success+0x34>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
lea    0xecf(%rip),%rdi
lea    0xea3(%rip),%rsi
xor    %edx,%edx
call   1040 <ksft_exit_fail_msg@plt>
lea    0xedb(%rip),%rdi
lea    0xe8e(%rip),%rsi
xor    %edx,%edx
call   1030 <ksft_test_result_pass@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@MEMBARRIER_CMD_GLOBAL = global i32 0
@.str = [37 x i8] c"sys membarrier MEMBARRIER_CMD_GLOBAL\00"
@.str.1 = [33 x i8] c"%s test: flags = %d, errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"%s test: flags = %d\0A\00"
define i32 @test_membarrier_global_success() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = load i32, i32* @MEMBARRIER_CMD_GLOBAL
store i32 %4, i32* %1
store i32 0, i32* %2
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = call i64 @sys_membarrier(i32 %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i8*, i8** %3
%11 = load i32, i32* %2
%12 = load i32, i32* @errno
%13 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %11, i32 %12)
br label %14
14: ; preds = %9, %0
%15 = load i8*, i8** %3
%16 = load i32, i32* %2
%17 = call i32 @ksft_test_result_pass(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %16)
ret i32 0
}

LLVM IR (-O2):
@MEMBARRIER_CMD_GLOBAL = global i32 0
@.str = [37 x i8] c"sys membarrier MEMBARRIER_CMD_GLOBAL\00"
@.str.1 = [33 x i8] c"%s test: flags = %d, errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"%s test: flags = %d\0A\00"
define i32 @test_membarrier_global_success() {
%1 = load i32, i32* @MEMBARRIER_CMD_GLOBAL
%2 = tail call i64 @sys_membarrier(i32 %1, i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 0, i32 %5)
br label %7
7: ; preds = %4, %0
%8 = tail call i32 @ksft_test_result_pass(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 0)
ret i32 0
}