#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 */
typedef int /*<<< orphan*/ pthread_mutexattr_t;
typedef int /*<<< orphan*/ pthread_mutex_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_PRIO_INHERIT;
int /*<<< orphan*/ PTHREAD_PRIO_NONE;
int /*<<< orphan*/ PTHREAD_PRIO_PROTECT;
scalar_t__ mutex_reinit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_setprioceiling(int /*<<< orphan*/ *, int, int *);
scalar_t__ pthread_mutexattr_setprotocol(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/);
int test_setprotocol(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) {
  int result = 1;
  int old_prioceiling;
  if (pthread_mutexattr_setprotocol(attr, PTHREAD_PRIO_INHERIT) == 0 &&
      mutex_reinit(mutex, attr) == 0 &&
      pthread_mutexattr_setprotocol(attr, PTHREAD_PRIO_PROTECT) == 0 &&
      mutex_reinit(mutex, attr) == 0 &&
      pthread_mutex_setprioceiling(mutex, 42, &old_prioceiling) == 0 &&
      pthread_mutexattr_setprotocol(attr, PTHREAD_PRIO_NONE) == 0 &&
      mutex_reinit(mutex, attr) == 0)
    result = 0;
  return result;
}


x86 assembly (clang, -O0):
<test_setprotocol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1050 <pthread_mutexattr_setprotocol@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <mutex_reinit@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
mov    -0x10(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1050 <pthread_mutexattr_setprotocol@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <mutex_reinit@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
mov    -0x8(%rbp),%rdi
mov    $0x2a,%esi
lea    -0x18(%rbp),%rdx
call   1040 <pthread_mutex_setprioceiling@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
mov    -0x10(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1050 <pthread_mutexattr_setprotocol@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <mutex_reinit@plt>
cmp    $0x0,%rax
jne    1203 <test_setprotocol+0xd3>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_setprotocol>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <pthread_mutexattr_setprotocol@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11d0 <test_setprotocol+0xa0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <mutex_reinit@plt>
test   %rax,%rax
jne    11d0 <test_setprotocol+0xa0>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <pthread_mutexattr_setprotocol@plt>
test   %rax,%rax
jne    11d0 <test_setprotocol+0xa0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <mutex_reinit@plt>
test   %rax,%rax
jne    11d0 <test_setprotocol+0xa0>
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    $0x2a,%esi
call   1040 <pthread_mutex_setprioceiling@plt>
test   %rax,%rax
jne    11d0 <test_setprotocol+0xa0>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <pthread_mutexattr_setprotocol@plt>
test   %rax,%rax
jne    11d0 <test_setprotocol+0xa0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <mutex_reinit@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PTHREAD_PRIO_INHERIT = global i32 0
@PTHREAD_PRIO_PROTECT = global i32 0
@PTHREAD_PRIO_NONE = global i32 0
define i32 @test_setprotocol(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 1, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* @PTHREAD_PRIO_INHERIT
%9 = call i64 @pthread_mutexattr_setprotocol(i32* %7, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %2
%12 = load i32*, i32** %3
%13 = load i32*, i32** %4
%14 = call i64 @mutex_reinit(i32* %12, i32* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %41
16: ; preds = %11
%17 = load i32*, i32** %4
%18 = load i32, i32* @PTHREAD_PRIO_PROTECT
%19 = call i64 @pthread_mutexattr_setprotocol(i32* %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = load i32*, i32** %4
%24 = call i64 @mutex_reinit(i32* %22, i32* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %21
%27 = load i32*, i32** %3
%28 = call i64 @pthread_mutex_setprioceiling(i32* %27, i32 42, i32* %6)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i32*, i32** %4
%32 = load i32, i32* @PTHREAD_PRIO_NONE
%33 = call i64 @pthread_mutexattr_setprotocol(i32* %31, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32*, i32** %3
%37 = load i32*, i32** %4
%38 = call i64 @mutex_reinit(i32* %36, i32* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %5
br label %41
41: ; preds = %40, %35, %30, %26, %21, %16, %11, %2
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@PTHREAD_PRIO_INHERIT = global i32 0
@PTHREAD_PRIO_PROTECT = global i32 0
@PTHREAD_PRIO_NONE = global i32 0
define i32 @test_setprotocol(i32* %0, i32* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @PTHREAD_PRIO_INHERIT
%6 = tail call i64 @pthread_mutexattr_setprotocol(i32* %1, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %2
%9 = tail call i64 @mutex_reinit(i32* %0, i32* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i32, i32* @PTHREAD_PRIO_PROTECT
%13 = tail call i64 @pthread_mutexattr_setprotocol(i32* %1, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = tail call i64 @mutex_reinit(i32* %0, i32* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = call i64 @pthread_mutex_setprioceiling(i32* %0, i32 42, i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32, i32* @PTHREAD_PRIO_NONE
%23 = call i64 @pthread_mutexattr_setprotocol(i32* %1, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i64 @mutex_reinit(i32* %0, i32* %1)
%27 = icmp ne i64 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %25, %21, %18, %15, %11, %8, %2
%30 = phi i32 [ 1, %21 ], [ 1, %18 ], [ 1, %15 ], [ 1, %11 ], [ 1, %8 ], [ 1, %2 ], [ %28, %25 ]
ret i32 %30
}