#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*/ printf(char *);
scalar_t__ pthread_mutex_lock(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_unlock(int /*<<< orphan*/ *);
int test_nocontention_lock(pthread_mutex_t *mutex) {
  printf("test_nocontention_lock()\n");
  if (pthread_mutex_lock(mutex)) {
    printf("pthread_mutex_lock() ERROR\n");
    return (-1);
  }
  if (pthread_mutex_unlock(mutex)) {
    printf("pthread_mutex_unlock() ERROR\n");
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<test_nocontention_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
je     1173 <test_nocontention_lock+0x43>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <test_nocontention_lock+0x75>
mov    -0x10(%rbp),%rdi
call   1040 <pthread_mutex_unlock@plt>
cmp    $0x0,%rax
je     119e <test_nocontention_lock+0x6e>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <test_nocontention_lock+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_nocontention_lock>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <pthread_mutex_lock@plt>
test   %rax,%rax
je     1156 <test_nocontention_lock+0x26>
lea    0xee2(%rip),%rdi
jmp    116a <test_nocontention_lock+0x3a>
mov    %rbx,%rdi
call   1040 <pthread_mutex_unlock@plt>
test   %rax,%rax
je     1176 <test_nocontention_lock+0x46>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"test_nocontention_lock()\0A\00"
@.str.1 = [28 x i8] c"pthread_mutex_lock() ERROR\0A\00"
@.str.2 = [30 x i8] c"pthread_mutex_unlock() ERROR\0A\00"
define i32 @test_nocontention_lock(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
store i32* %0, i32** %3
%4 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = load i32*, i32** %3
%6 = call i64 @pthread_mutex_lock(i32* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %17
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i64 @pthread_mutex_unlock(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %17
16: ; preds = %10
store i32 0, i32* %2
br label %17
17: ; preds = %16, %14, %8
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@str = [25 x i8] c"test_nocontention_lock()\00"
@str.3 = [29 x i8] c"pthread_mutex_unlock() ERROR\00"
@str.4 = [27 x i8] c"pthread_mutex_lock() ERROR\00"
define i32 @test_nocontention_lock(i32* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%3 = tail call i64 @pthread_mutex_lock(i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i64 @pthread_mutex_unlock(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %1
%9 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0), %1 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0), %5 ]
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 0, %5 ], [ -1, %8 ]
ret i32 %12
}