#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 ENOTSUP;
scalar_t__ pthread_mutex_destroy(int /*<<< orphan*/ *);
int pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_lock(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_unlock(int /*<<< orphan*/ *);
scalar_t__ pthread_mutexattr_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  pthread_mutex_t m;
  int e = pthread_mutex_init(&m, NULL);
  if (NULL != NULL && e == ENOTSUP) {
    puts("cannot support selected type of mutexes");
    return 0;
  } else if (e != 0) {
    puts("mutex_init failed");
    return 1;
  }
  if (NULL != NULL && pthread_mutexattr_destroy(NULL) != 0) {
    puts("mutexattr_destroy failed");
    return 1;
  }
  if (pthread_mutex_lock(&m) != 0) {
    puts("mutex_lock failed");
    return 1;
  }
  if (pthread_mutex_unlock(&m) != 0) {
    puts("mutex_unlock failed");
    return 1;
  }
  if (pthread_mutex_destroy(&m) != 0) {
    puts("mutex_destroy failed");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <pthread_mutex_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     118a <do_test+0x3a>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1212 <do_test+0xc2>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
je     11b5 <do_test+0x65>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1212 <do_test+0xc2>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
cmp    $0x0,%rax
je     11e0 <do_test+0x90>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1212 <do_test+0xc2>
lea    -0x8(%rbp),%rdi
call   1040 <pthread_mutex_destroy@plt>
cmp    $0x0,%rax
je     120b <do_test+0xbb>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1212 <do_test+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rax
lea    0x4(%rsp),%rdi
xor    %esi,%esi
call   1060 <pthread_mutex_init@plt>
test   %eax,%eax
je     116a <do_test+0x1a>
lea    0xe98(%rip),%rdi
jmp    11b0 <do_test+0x60>
lea    0x4(%rsp),%rdi
call   1070 <pthread_mutex_lock@plt>
test   %rax,%rax
je     1182 <do_test+0x32>
lea    0xe92(%rip),%rdi
jmp    11b0 <do_test+0x60>
lea    0x4(%rsp),%rdi
call   1050 <pthread_mutex_unlock@plt>
test   %rax,%rax
je     119a <do_test+0x4a>
lea    0xe8c(%rip),%rdi
jmp    11b0 <do_test+0x60>
lea    0x4(%rsp),%rdi
call   1040 <pthread_mutex_destroy@plt>
test   %rax,%rax
je     11bc <do_test+0x6c>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"mutex_init failed\00"
@.str.1 = [18 x i8] c"mutex_lock failed\00"
@.str.2 = [20 x i8] c"mutex_unlock failed\00"
@.str.3 = [21 x i8] c"mutex_destroy failed\00"
@ENOTSUP = global i32 0
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @pthread_mutex_init(i32* %2, i32* null)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %25
9: ; preds = %0
%10 = call i64 @pthread_mutex_lock(i32* %2)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %25
14: ; preds = %9
%15 = call i64 @pthread_mutex_unlock(i32* %2)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %25
19: ; preds = %14
%20 = call i64 @pthread_mutex_destroy(i32* %2)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %25
24: ; preds = %19
store i32 0, i32* %1
br label %25
25: ; preds = %24, %22, %17, %12, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [18 x i8] c"mutex_init failed\00"
@.str.1 = [18 x i8] c"mutex_lock failed\00"
@.str.2 = [20 x i8] c"mutex_unlock failed\00"
@.str.3 = [21 x i8] c"mutex_destroy failed\00"
@ENOTSUP = global i32 0
define i32 @do_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_mutex_init(i32* %1, i32* null)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = call i64 @pthread_mutex_lock(i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = call i64 @pthread_mutex_unlock(i32* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i64 @pthread_mutex_destroy(i32* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11, %8, %5, %0
%15 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %11 ]
%16 = call i32 @puts(i8* dereferenceable(1) %15)
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ 0, %11 ], [ 1, %14 ]
ret i32 %18
}