#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_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ test_contention_lock(int /*<<< orphan*/ *);
scalar_t__ test_nocontention_lock(int /*<<< orphan*/ *);
int test_mutex_fast(void) {
  pthread_mutex_t mutex_fast;
  printf("test_mutex_fast()\n");
  if (pthread_mutex_init(&mutex_fast, NULL)) {
    printf("pthread_mutex_init() ERROR\n");
    return (-1);
  }
  if (test_nocontention_lock(&mutex_fast) ||
      test_contention_lock(&mutex_fast)) {
    return (-1);
  }
  if (pthread_mutex_destroy(&mutex_fast)) {
    printf("pthread_mutex_destroy() ERROR\n");
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<test_mutex_fast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pthread_mutex_init@plt>
cmp    $0x0,%rax
je     1193 <test_mutex_fast+0x43>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <test_mutex_fast+0xa7>
lea    -0x8(%rbp),%rdi
call   1060 <test_nocontention_lock@plt>
cmp    $0x0,%rax
jne    11b9 <test_mutex_fast+0x69>
lea    -0x8(%rbp),%rdi
call   1030 <test_contention_lock@plt>
cmp    $0x0,%rax
je     11c5 <test_mutex_fast+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <test_mutex_fast+0xa7>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutex_destroy@plt>
cmp    $0x0,%rax
je     11f0 <test_mutex_fast+0xa0>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <test_mutex_fast+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mutex_fast>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1070 <pthread_mutex_init@plt>
test   %rax,%rax
je     1185 <test_mutex_fast+0x35>
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11a8 <test_mutex_fast+0x58>
lea    0xc(%rsp),%rdi
call   1060 <test_nocontention_lock@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11a8 <test_mutex_fast+0x58>
lea    0xc(%rsp),%rdi
call   1030 <test_contention_lock@plt>
test   %rax,%rax
je     11b0 <test_mutex_fast+0x60>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xc(%rsp),%rdi
call   1050 <pthread_mutex_destroy@plt>
test   %rax,%rax
je     11c8 <test_mutex_fast+0x78>
lea    0xe4c(%rip),%rdi
jmp    1179 <test_mutex_fast+0x29>
xor    %ebx,%ebx
jmp    11a8 <test_mutex_fast+0x58>

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

LLVM IR (-O2):
@str = [18 x i8] c"test_mutex_fast()\00"
@str.3 = [30 x i8] c"pthread_mutex_destroy() ERROR\00"
@str.4 = [27 x i8] c"pthread_mutex_init() ERROR\00"
define i32 @test_mutex_fast() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%4 = call i64 @pthread_mutex_init(i32* %1, i32* null)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = call i64 @test_nocontention_lock(i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = call i64 @test_contention_lock(i32* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i64 @pthread_mutex_destroy(i32* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12, %0
%16 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0), %0 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0), %12 ]
%17 = call i32 @puts(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %15, %12, %6, %9
%19 = phi i32 [ -1, %9 ], [ -1, %6 ], [ 0, %12 ], [ -1, %15 ]
ret i32 %19
}