#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 ENOENT;
int lksmith_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ lksmith_error(int, char *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/, int);
int r_pthread_mutex_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ terror(int);
int pthread_mutex_destroy(pthread_mutex_t *mutex) {
  int ret;
  ret = lksmith_destroy(mutex);
  if ((ret != 0) && (ret != ENOENT)) {
    return ret;
  }
  ret = r_pthread_mutex_destroy(mutex);
  if (ret) {
    lksmith_error(ret,
                  "pthread_mutex_destroy(mutex=%p): "
                  "failed with error %s (%d)",
                  mutex, terror(ret), ret);
  }
  return ret;
}


x86 assembly (clang, -O0):
<pthread_mutex_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <lksmith_destroy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117f <pthread_mutex_destroy+0x3f>
mov    -0x14(%rbp),%eax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%eax
je     117f <pthread_mutex_destroy+0x3f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <pthread_mutex_destroy+0x8a>
mov    -0x10(%rbp),%rdi
call   1050 <r_pthread_mutex_destroy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c4 <pthread_mutex_destroy+0x84>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <terror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
mov    -0x14(%rbp),%r8d
lea    0xe41(%rip),%rsi
call   1030 <lksmith_error@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pthread_mutex_destroy>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <lksmith_destroy@plt>
test   %eax,%eax
je     115d <pthread_mutex_destroy+0x1d>
mov    %eax,%ebx
mov    0x2e7f(%rip),%rax
cmp    (%rax),%ebx
jne    118c <pthread_mutex_destroy+0x4c>
mov    %r14,%rdi
call   1050 <r_pthread_mutex_destroy@plt>
test   %eax,%eax
je     118a <pthread_mutex_destroy+0x4a>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <terror@plt>
lea    0xe87(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %eax,%ecx
mov    %ebx,%r8d
call   1030 <lksmith_error@plt>
jmp    118c <pthread_mutex_destroy+0x4c>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ENOENT = global i32 0
@.str = [59 x i8] c"pthread_mutex_destroy(mutex=%p): failed with error %s (%d)\00"
define i32 @pthread_mutex_destroy(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @lksmith_destroy(i32* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* %4
%11 = load i32, i32* @ENOENT
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %29
15: ; preds = %9, %1
%16 = load i32*, i32** %3
%17 = call i32 @r_pthread_mutex_destroy(i32* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i32, i32* %4
%22 = load i32*, i32** %3
%23 = load i32, i32* %4
%24 = call i32 @terror(i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @lksmith_error(i32 %21, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32* %22, i32 %24, i32 %25)
br label %27
27: ; preds = %20, %15
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %13
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@ENOENT = global i32 0
@.str = [59 x i8] c"pthread_mutex_destroy(mutex=%p): failed with error %s (%d)\00"
define i32 @pthread_mutex_destroy(i32* %0) {
%2 = tail call i32 @lksmith_destroy(i32* %0)
%3 = icmp eq i32 %2, 0
%4 = load i32, i32* @ENOENT
%5 = icmp eq i32 %2, %4
%6 = select i1 %3, i1 true, i1 %5
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = tail call i32 @r_pthread_mutex_destroy(i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @terror(i32 %8)
%12 = tail call i32 @lksmith_error(i32 %8, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32* %0, i32 %11, i32 %8)
br label %13
13: ; preds = %7, %10, %1
%14 = phi i32 [ %2, %1 ], [ %8, %10 ], [ 0, %7 ]
ret i32 %14
}