#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 EBUSY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int pthread_mutex_trylock(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int pt_mutex_trylock(pthread_mutex_t *m, char *msg) {
  int res;
  if ((res = pthread_mutex_trylock(m)) != EBUSY) {
    fprintf(stderr, "%s: %d: %s\n", msg, res, strerror(res));
    exit(1);
  }
  return (res ? 1 : 0);
}


x86 assembly (clang, -O0):
<pt_mutex_trylock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <pthread_mutex_trylock@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%eax
je     11b0 <pt_mutex_trylock+0x70>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    %rax,%r8
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pt_mutex_trylock>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1030 <pthread_mutex_trylock@plt>
mov    %eax,%ebp
mov    0x2e83(%rip),%rax
cmp    (%rax),%ebp
jne    1165 <pt_mutex_trylock+0x25>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%r14d
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe83(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EBUSY = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"%s: %d: %s\0A\00"
define i32 @pt_mutex_trylock(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
%7 = call i32 @pthread_mutex_trylock(i32* %6)
store i32 %7, i32* %5
%8 = load i32, i32* @EBUSY
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 1, i32 0
ret i32 %22
}

LLVM IR (-O2):
@EBUSY = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"%s: %d: %s\0A\00"
define i32 @pt_mutex_trylock(i32* %0, i8* %1) {
%3 = tail call i32 @pthread_mutex_trylock(i32* %0)
%4 = load i32, i32* @EBUSY
%5 = icmp eq i32 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i8* @strerror(i32 %3)
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %3, i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = icmp ne i32 %3, 0
%13 = zext i1 %12 to i32
ret i32 %13
}