#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 /*<<< orphan*/ lksmith_postunlock(int /*<<< orphan*/ *);
int lksmith_preunlock(int /*<<< orphan*/ *);
int r_pthread_mutex_unlock(int /*<<< orphan*/ *);
int pthread_mutex_unlock(pthread_mutex_t *__restrict mutex) {
  int ret = lksmith_preunlock(mutex);
  if (ret)
    return ret;
  ret = r_pthread_mutex_unlock(mutex);
  if (ret)
    return ret;
  lksmith_postunlock(mutex);
  return 0;
}


x86 assembly (clang, -O0):
<pthread_mutex_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <lksmith_preunlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115d <pthread_mutex_unlock+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <pthread_mutex_unlock+0x5e>
mov    -0x10(%rbp),%rdi
call   1040 <r_pthread_mutex_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117e <pthread_mutex_unlock+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <pthread_mutex_unlock+0x5e>
mov    -0x10(%rbp),%rdi
call   1050 <lksmith_postunlock@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pthread_mutex_unlock>:
push   %rbx
mov    %rdi,%rbx
call   1030 <lksmith_preunlock@plt>
test   %eax,%eax
je     113f <pthread_mutex_unlock+0xf>
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <r_pthread_mutex_unlock@plt>
test   %eax,%eax
jne    113d <pthread_mutex_unlock+0xd>
mov    %rbx,%rdi
call   1050 <lksmith_postunlock@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @pthread_mutex_unlock(i32* noalias %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @lksmith_preunlock(i32* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %21
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i32 @r_pthread_mutex_unlock(i32* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %21
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = call i32 @lksmith_postunlock(i32* %19)
store i32 0, i32* %2
br label %21
21: ; preds = %18, %16, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
define i32 @pthread_mutex_unlock(i32* noalias %0) {
%2 = tail call i32 @lksmith_preunlock(i32* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = tail call i32 @r_pthread_mutex_unlock(i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @lksmith_postunlock(i32* %0)
br label %9
9: ; preds = %4, %1, %7
%10 = phi i32 [ 0, %7 ], [ %2, %1 ], [ %5, %4 ]
ret i32 %10
}