#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 test_membarrier_cmd_fail();
int test_membarrier_flags_fail();
int test_membarrier_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_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   1050 <test_membarrier_cmd_fail@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1157 <test_membarrier+0x27>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <test_membarrier+0x6c>
mov    $0x0,%al
call   1040 <test_membarrier_flags_fail@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1176 <test_membarrier+0x46>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <test_membarrier+0x6c>
mov    $0x0,%al
call   1030 <test_membarrier_success@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1195 <test_membarrier+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <test_membarrier+0x6c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_membarrier>:
push   %rax
xor    %eax,%eax
call   1050 <test_membarrier_cmd_fail@plt>
test   %eax,%eax
jne    1147 <test_membarrier+0x17>
xor    %eax,%eax
call   1040 <test_membarrier_flags_fail@plt>
test   %eax,%eax
je     1149 <test_membarrier+0x19>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
jmp    1030 <test_membarrier_success@plt>

LLVM IR (-O0):
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 %21
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 %21
14: ; preds = %8
%15 = call i32 (...) @test_membarrier_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 %21
20: ; preds = %14
store i32 0, i32* %1
br label %21
21: ; preds = %20, %18, %12, %6
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
define i32 @test_membarrier() {
%1 = tail call i32 (...) @test_membarrier_cmd_fail()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = tail call i32 (...) @test_membarrier_flags_fail()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (...) @test_membarrier_success()
br label %8
8: ; preds = %6, %3, %0
%9 = phi i32 [ %1, %0 ], [ %4, %3 ], [ %7, %6 ]
ret i32 %9
}