#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*/ 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) {
  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)
cmpq   $0x0,-0x10(%rbp)
je     1197 <oml_lock+0x67>
mov    -0x10(%rbp),%rdi
call   1050 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
je     1192 <oml_lock+0x62>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe7f(%rip),%rdi
call   1030 <logwarn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119e <oml_lock+0x6e>
jmp    1197 <oml_lock+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oml_lock>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     116b <oml_lock+0x3b>
mov    %rsi,%rbx
call   1050 <pthread_mutex_lock@plt>
test   %rax,%rax
je     116b <oml_lock+0x3b>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <logwarn@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [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 i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i32*, i32** %4
%10 = call i64 @pthread_mutex_lock(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @logwarn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %15)
store i32 -1, i32* %3
br label %19
17: ; preds = %8
br label %18
18: ; preds = %17, %2
store i32 0, i32* %3
br label %19
19: ; preds = %18, %12
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [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 = icmp eq i32* %0, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i64 @pthread_mutex_lock(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @logwarn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %9)
br label %11
11: ; preds = %2, %4, %7
%12 = phi i32 [ -1, %7 ], [ 0, %4 ], [ 0, %2 ]
ret i32 %12
}