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

/* Variables and functions */
int /*<<< orphan*/ lksmith_postunlock(void const *);
int lksmith_preunlock(void const *);
int r_pthread_spin_unlock(int /*<<< orphan*/ *);
int pthread_spin_unlock(pthread_spinlock_t *lock) {
  int ret = lksmith_preunlock((const void *)lock);
  if (ret)
    return ret;
  ret = r_pthread_spin_unlock(lock);
  if (ret)
    return ret;
  lksmith_postunlock((const void *)lock);
  return 0;
}


x86 assembly (clang, -O0):
<pthread_spin_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_spin_unlock+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <pthread_spin_unlock+0x5e>
mov    -0x10(%rbp),%rdi
call   1040 <r_pthread_spin_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117e <pthread_spin_unlock+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <pthread_spin_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_spin_unlock>:
push   %rbx
mov    %rdi,%rbx
call   1030 <lksmith_preunlock@plt>
test   %eax,%eax
je     113f <pthread_spin_unlock+0xf>
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <r_pthread_spin_unlock@plt>
test   %eax,%eax
jne    113d <pthread_spin_unlock+0xd>
mov    %rbx,%rdi
call   1050 <lksmith_postunlock@plt>
xor    %eax,%eax
pop    %rbx
ret

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

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