#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_mutex_t;

/* Variables and functions */
int EOWNERDEAD;
int /*<<< orphan*/ filebench_log(int, char *, int /*<<< orphan*/);
scalar_t__ pthread_mutex_consistent_np(int /*<<< orphan*/ *);
int pthread_mutex_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int);
int ipc_mutex_lock(pthread_mutex_t *mutex) {
  int error;
  error = pthread_mutex_lock(mutex);
  if (error == EOWNERDEAD) {
    if (pthread_mutex_consistent_np(mutex) != 0) {
      filebench_log(999,
                    "mutex make consistent "
                    "failed: %s",
                    strerror(error));
      return (-1);
    }
    return (0);
  }
  if (error != 0) {
    filebench_log(999, "mutex lock failed: %s", strerror(error));
  }
  return (error);
}


x86 assembly (clang, -O0):
<ipc_mutex_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <pthread_mutex_lock@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
jne    11b0 <ipc_mutex_lock+0x70>
mov    -0x10(%rbp),%rdi
call   1040 <pthread_mutex_consistent_np@plt>
cmp    $0x0,%rax
je     11a4 <ipc_mutex_lock+0x64>
mov    -0x14(%rbp),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x3e7,%edi
lea    0xe6d(%rip),%rsi
call   1030 <filebench_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <ipc_mutex_lock+0x9b>
movl   $0x0,-0x4(%rbp)
jmp    11db <ipc_mutex_lock+0x9b>
cmpl   $0x0,-0x14(%rbp)
je     11d5 <ipc_mutex_lock+0x95>
mov    -0x14(%rbp),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x3e7,%edi
lea    0xe51(%rip),%rsi
call   1030 <filebench_log@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipc_mutex_lock>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1060 <pthread_mutex_lock@plt>
mov    %eax,%ebx
mov    0x2e8b(%rip),%rax
cmp    (%rax),%ebx
jne    1174 <ipc_mutex_lock+0x34>
mov    %rbp,%rdi
call   1040 <pthread_mutex_consistent_np@plt>
test   %rax,%rax
je     1199 <ipc_mutex_lock+0x59>
mov    $0xffffffff,%ebp
lea    0xe8e(%rip),%r14
jmp    1181 <ipc_mutex_lock+0x41>
test   %ebx,%ebx
je     1199 <ipc_mutex_lock+0x59>
lea    0xea2(%rip),%r14
mov    %ebx,%ebp
mov    %ebx,%edi
call   1050 <strerror@plt>
mov    $0x3e7,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <filebench_log@plt>
jmp    119b <ipc_mutex_lock+0x5b>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOWNERDEAD = global i32 0
@.str = [33 x i8] c"mutex make consistent failed: %s\00"
@.str.1 = [22 x i8] c"mutex lock failed: %s\00"
define i32 @ipc_mutex_lock(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @pthread_mutex_lock(i32* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @EOWNERDEAD
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i64 @pthread_mutex_consistent_np(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %4
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @filebench_log(i32 999, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 -1, i32* %2
br label %28
18: ; preds = %10
store i32 0, i32* %2
br label %28
19: ; preds = %1
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %4
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @filebench_log(i32 999, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %19
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %18, %14
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@EOWNERDEAD = global i32 0
@.str = [33 x i8] c"mutex make consistent failed: %s\00"
@.str.1 = [22 x i8] c"mutex lock failed: %s\00"
define i32 @ipc_mutex_lock(i32* %0) {
%2 = tail call i32 @pthread_mutex_lock(i32* %0)
%3 = load i32, i32* @EOWNERDEAD
%4 = icmp eq i32 %2, %3
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i64 @pthread_mutex_consistent_np(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %10
8: ; preds = %1
%9 = icmp eq i32 %2, 0
br i1 %9, label %15, label %10
10: ; preds = %8, %5
%11 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %8 ]
%12 = phi i32 [ -1, %5 ], [ %2, %8 ]
%13 = tail call i32 @strerror(i32 %2)
%14 = tail call i32 @filebench_log(i32 999, i8* %11, i32 %13)
br label %15
15: ; preds = %10, %8, %5
%16 = phi i32 [ 0, %5 ], [ 0, %8 ], [ %12, %10 ]
ret i32 %16
}