#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 */
scalar_t__ pthread_mutex_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_lock(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_unlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  pthread_mutex_t m;
  if (pthread_mutex_init(&m, NULL) != 0) {
    puts("mutex_init 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>
cmp    $0x0,%rax
je     1187 <do_test+0x37>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <do_test+0xbf>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
je     11b2 <do_test+0x62>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <do_test+0xbf>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
cmp    $0x0,%rax
je     11dd <do_test+0x8d>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <do_test+0xbf>
lea    -0x8(%rbp),%rdi
call   1040 <pthread_mutex_destroy@plt>
cmp    $0x0,%rax
je     1208 <do_test+0xb8>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <do_test+0xbf>
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   %rax,%rax
je     116b <do_test+0x1b>
lea    0xe97(%rip),%rdi
jmp    11b1 <do_test+0x61>
lea    0x4(%rsp),%rdi
call   1070 <pthread_mutex_lock@plt>
test   %rax,%rax
je     1183 <do_test+0x33>
lea    0xe91(%rip),%rdi
jmp    11b1 <do_test+0x61>
lea    0x4(%rsp),%rdi
call   1050 <pthread_mutex_unlock@plt>
test   %rax,%rax
je     119b <do_test+0x4b>
lea    0xe8b(%rip),%rdi
jmp    11b1 <do_test+0x61>
lea    0x4(%rsp),%rdi
call   1040 <pthread_mutex_destroy@plt>
test   %rax,%rax
je     11bd <do_test+0x6d>
lea    0xe87(%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"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 @pthread_mutex_init(i32* %2, i32* null)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %23
7: ; preds = %0
%8 = call i64 @pthread_mutex_lock(i32* %2)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = 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 %23
12: ; preds = %7
%13 = call i64 @pthread_mutex_unlock(i32* %2)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = 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 %23
17: ; preds = %12
%18 = call i64 @pthread_mutex_destroy(i32* %2)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = 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 %23
22: ; preds = %17
store i32 0, i32* %1
br label %23
23: ; preds = %22, %20, %15, %10, %5
%24 = load i32, i32* %1
ret i32 %24
}

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"
define i32 @do_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @pthread_mutex_init(i32* %1, i32* null)
%4 = icmp eq i64 %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
}