#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_PRIVATE_EXPEDITED_SYNC_CORE;
int /*<<< orphan*/ MEMBARRIER_CMD_QUERY;
int /*<<< orphan*/ ksft_test_result_fail(char *);
int sys_membarrier(int /*<<< orphan*/, int /*<<< orphan*/);
int test_membarrier_cmd_fail();
int test_membarrier_flags_fail();
int test_membarrier_global_expedited_success();
int test_membarrier_global_success();
int test_membarrier_private_expedited_fail();
int test_membarrier_private_expedited_success();
int test_membarrier_private_expedited_sync_core_fail();
int test_membarrier_private_expedited_sync_core_success();
int test_membarrier_register_global_expedited_success();
int test_membarrier_register_private_expedited_success();
int test_membarrier_register_private_expedited_sync_core_success();
int test_membarrier(void) {
  int status;
  status = test_membarrier_cmd_fail();
  if (status)
    return status;
  status = test_membarrier_flags_fail();
  if (status)
    return status;
  status = test_membarrier_global_success();
  if (status)
    return status;
  status = test_membarrier_private_expedited_fail();
  if (status)
    return status;
  status = test_membarrier_register_private_expedited_success();
  if (status)
    return status;
  status = test_membarrier_private_expedited_success();
  if (status)
    return status;
  status = sys_membarrier(MEMBARRIER_CMD_QUERY, 0);
  if (status < 0) {
    ksft_test_result_fail("sys_membarrier() failed\n");
    return status;
  }
  if (status & MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE) {
    status = test_membarrier_private_expedited_sync_core_fail();
    if (status)
      return status;
    status = test_membarrier_register_private_expedited_sync_core_success();
    if (status)
      return status;
    status = test_membarrier_private_expedited_sync_core_success();
    if (status)
      return status;
  }
  status = test_membarrier_global_expedited_success();
  if (status)
    return status;
  status = test_membarrier_register_global_expedited_success();
  if (status)
    return status;
  status = test_membarrier_global_expedited_success();
  if (status)
    return status;
  return 0;
}


x86 assembly (clang, -O0):
<test_membarrier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   10f0 <test_membarrier_cmd_fail@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11f7 <test_membarrier+0x27>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   1030 <test_membarrier_flags_fail@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1216 <test_membarrier+0x46>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   1060 <test_membarrier_global_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1235 <test_membarrier+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   1070 <test_membarrier_private_expedited_fail@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1254 <test_membarrier+0x84>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   1050 <test_membarrier_register_private_expedited_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1273 <test_membarrier+0xa3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   1090 <test_membarrier_private_expedited_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1292 <test_membarrier+0xc2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   10a0 <sys_membarrier@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12c6 <test_membarrier+0xf6>
lea    0xd4a(%rip),%rdi
call   1080 <ksft_test_result_fail@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    -0x8(%rbp),%eax
mov    0x2d10(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     133d <test_membarrier+0x16d>
mov    $0x0,%al
call   10d0 <test_membarrier_private_expedited_sync_core_fail@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12fa <test_membarrier+0x12a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   10c0 <test_membarrier_register_private_expedited_sync_core_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1319 <test_membarrier+0x149>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   10e0 <test_membarrier_private_expedited_sync_core_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1338 <test_membarrier+0x168>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
jmp    133d <test_membarrier+0x16d>
mov    $0x0,%al
call   1040 <test_membarrier_global_expedited_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     135c <test_membarrier+0x18c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   10b0 <test_membarrier_register_global_expedited_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     137b <test_membarrier+0x1ab>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
mov    $0x0,%al
call   1040 <test_membarrier_global_expedited_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     139a <test_membarrier+0x1ca>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <test_membarrier+0x1d1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_membarrier>:
push   %rbx
xor    %eax,%eax
call   10f0 <test_membarrier_cmd_fail@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   1030 <test_membarrier_flags_fail@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   1060 <test_membarrier_global_success@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   1070 <test_membarrier_private_expedited_fail@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   1050 <test_membarrier_register_private_expedited_success@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   1090 <test_membarrier_private_expedited_success@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1223 <test_membarrier+0x53>
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   10a0 <sys_membarrier@plt>
mov    %eax,%ebx
test   %eax,%eax
js     128d <test_membarrier+0xbd>
mov    0x2da0(%rip),%rax
test   %ebx,(%rax)
je     126b <test_membarrier+0x9b>
xor    %eax,%eax
call   10d0 <test_membarrier_private_expedited_sync_core_fail@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   10c0 <test_membarrier_register_private_expedited_sync_core_success@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   10e0 <test_membarrier_private_expedited_sync_core_success@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   1040 <test_membarrier_global_expedited_success@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
call   10b0 <test_membarrier_register_global_expedited_success@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    121f <test_membarrier+0x4f>
xor    %eax,%eax
pop    %rbx
jmp    1040 <test_membarrier_global_expedited_success@plt>
lea    0xd6c(%rip),%rdi
call   1080 <ksft_test_result_fail@plt>
jmp    121f <test_membarrier+0x4f>

LLVM IR (-O0):
@MEMBARRIER_CMD_QUERY = global i32 0
@.str = [25 x i8] c"sys_membarrier() failed\0A\00"
@MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE = global i32 0
define i32 @test_membarrier() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @test_membarrier_cmd_fail()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = load i32, i32* %2
store i32 %7, i32* %1
br label %89
8: ; preds = %0
%9 = call i32 (...) @test_membarrier_flags_fail()
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i32, i32* %2
store i32 %13, i32* %1
br label %89
14: ; preds = %8
%15 = call i32 (...) @test_membarrier_global_success()
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* %2
store i32 %19, i32* %1
br label %89
20: ; preds = %14
%21 = call i32 (...) @test_membarrier_private_expedited_fail()
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i32, i32* %2
store i32 %25, i32* %1
br label %89
26: ; preds = %20
%27 = call i32 (...) @test_membarrier_register_private_expedited_success()
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i32, i32* %2
store i32 %31, i32* %1
br label %89
32: ; preds = %26
%33 = call i32 (...) @test_membarrier_private_expedited_success()
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i32, i32* %2
store i32 %37, i32* %1
br label %89
38: ; preds = %32
%39 = load i32, i32* @MEMBARRIER_CMD_QUERY
%40 = call i32 @sys_membarrier(i32 %39, i32 0)
store i32 %40, i32* %2
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = call i32 @ksft_test_result_fail(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%45 = load i32, i32* %2
store i32 %45, i32* %1
br label %89
46: ; preds = %38
%47 = load i32, i32* %2
%48 = load i32, i32* @MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
%49 = and i32 %47, %48
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %70
51: ; preds = %46
%52 = call i32 (...) @test_membarrier_private_expedited_sync_core_fail()
store i32 %52, i32* %2
%53 = load i32, i32* %2
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = load i32, i32* %2
store i32 %56, i32* %1
br label %89
57: ; preds = %51
%58 = call i32 (...) @test_membarrier_register_private_expedited_sync_core_success()
store i32 %58, i32* %2
%59 = load i32, i32* %2
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = load i32, i32* %2
store i32 %62, i32* %1
br label %89
63: ; preds = %57
%64 = call i32 (...) @test_membarrier_private_expedited_sync_core_success()
store i32 %64, i32* %2
%65 = load i32, i32* %2
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = load i32, i32* %2
store i32 %68, i32* %1
br label %89
69: ; preds = %63
br label %70
70: ; preds = %69, %46
%71 = call i32 (...) @test_membarrier_global_expedited_success()
store i32 %71, i32* %2
%72 = load i32, i32* %2
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = load i32, i32* %2
store i32 %75, i32* %1
br label %89
76: ; preds = %70
%77 = call i32 (...) @test_membarrier_register_global_expedited_success()
store i32 %77, i32* %2
%78 = load i32, i32* %2
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = load i32, i32* %2
store i32 %81, i32* %1
br label %89
82: ; preds = %76
%83 = call i32 (...) @test_membarrier_global_expedited_success()
store i32 %83, i32* %2
%84 = load i32, i32* %2
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = load i32, i32* %2
store i32 %87, i32* %1
br label %89
88: ; preds = %82
store i32 0, i32* %1
br label %89
89: ; preds = %88, %86, %80, %74, %67, %61, %55, %43, %36, %30, %24, %18, %12, %6
%90 = load i32, i32* %1
ret i32 %90
}

LLVM IR (-O2):
@MEMBARRIER_CMD_QUERY = global i32 0
@.str = [25 x i8] c"sys_membarrier() failed\0A\00"
@MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE = global i32 0
define i32 @test_membarrier() {
%1 = tail call i32 (...) @test_membarrier_cmd_fail()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %45
3: ; preds = %0
%4 = tail call i32 (...) @test_membarrier_flags_fail()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %45
6: ; preds = %3
%7 = tail call i32 (...) @test_membarrier_global_success()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %45
9: ; preds = %6
%10 = tail call i32 (...) @test_membarrier_private_expedited_fail()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %45
12: ; preds = %9
%13 = tail call i32 (...) @test_membarrier_register_private_expedited_success()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %12
%16 = tail call i32 (...) @test_membarrier_private_expedited_success()
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %45
18: ; preds = %15
%19 = load i32, i32* @MEMBARRIER_CMD_QUERY
%20 = tail call i32 @sys_membarrier(i32 %19, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @ksft_test_result_fail(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %45
24: ; preds = %18
%25 = load i32, i32* @MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
%26 = and i32 %25, %20
%27 = icmp eq i32 %26, 0
br i1 %27, label %37, label %28
28: ; preds = %24
%29 = tail call i32 (...) @test_membarrier_private_expedited_sync_core_fail()
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = tail call i32 (...) @test_membarrier_register_private_expedited_sync_core_success()
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = tail call i32 (...) @test_membarrier_private_expedited_sync_core_success()
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34, %24
%38 = tail call i32 (...) @test_membarrier_global_expedited_success()
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = tail call i32 (...) @test_membarrier_register_global_expedited_success()
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = tail call i32 (...) @test_membarrier_global_expedited_success()
br label %45
45: ; preds = %43, %40, %37, %34, %31, %28, %15, %12, %9, %6, %3, %0, %22
%46 = phi i32 [ %20, %22 ], [ %1, %0 ], [ %4, %3 ], [ %7, %6 ], [ %10, %9 ], [ %13, %12 ], [ %16, %15 ], [ %29, %28 ], [ %32, %31 ], [ %35, %34 ], [ %38, %37 ], [ %41, %40 ], [ %44, %43 ]
ret i32 %46
}