#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*/ errno;
int /*<<< orphan*/ logdebug3(char *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ logwarn(char *, char const *, int /*<<< orphan*/);
scalar_t__ pthread_mutex_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int oml_lock(pthread_mutex_t *mutexP, const char *mutexName) {
  logdebug3("%s trying to lock %p\n", mutexName, mutexP);
  if (mutexP) {
    if (pthread_mutex_lock(mutexP)) {
      logwarn("%s: Couldn't get mutex lock (%s)\n", mutexName, strerror(errno));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<oml_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xea1(%rip),%rdi
call   1040 <logdebug3@plt>
cmpq   $0x0,-0x10(%rbp)
je     11bb <oml_lock+0x7b>
mov    -0x10(%rbp),%rdi
call   1060 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
je     11b6 <oml_lock+0x76>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe71(%rip),%rdi
call   1030 <logwarn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <oml_lock+0x82>
jmp    11bb <oml_lock+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oml_lock>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdi
mov    %rbx,%rdx
call   1040 <logdebug3@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     1191 <oml_lock+0x51>
mov    %rbx,%rdi
call   1060 <pthread_mutex_lock@plt>
test   %rax,%rax
je     1191 <oml_lock+0x51>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe94(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <logwarn@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%s trying to lock %p\0A\00"
@.str.1 = [34 x i8] c"%s: Couldn't get mutex lock (%s)\0A\00"
@errno = global i32 0
define i32 @oml_lock(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = load i32*, i32** %4
%8 = call i32 @logdebug3(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %7)
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = call i64 @pthread_mutex_lock(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @logwarn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %18)
store i32 -1, i32* %3
br label %22
20: ; preds = %11
br label %21
21: ; preds = %20, %2
store i32 0, i32* %3
br label %22
22: ; preds = %21, %15
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [22 x i8] c"%s trying to lock %p\0A\00"
@.str.1 = [34 x i8] c"%s: Couldn't get mutex lock (%s)\0A\00"
@errno = global i32 0
define i32 @oml_lock(i32* %0, i8* %1) {
%3 = tail call i32 @logdebug3(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %1, i32* %0)
%4 = icmp eq i32* %0, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i64 @pthread_mutex_lock(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 @logwarn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %10)
br label %12
12: ; preds = %2, %5, %8
%13 = phi i32 [ -1, %8 ], [ 0, %5 ], [ 0, %2 ]
ret i32 %13
}