#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;
typedef int /*<<< orphan*/ pthread_cond_t;

/* Variables and functions */
scalar_t__ pthread_cond_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutex_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int mutex_cond_init(pthread_mutex_t *mutex, pthread_cond_t *cond) {
  if (pthread_mutex_init(mutex, NULL) != 0) {
    return (-1);
  }
  if (pthread_cond_init(cond, NULL) != 0) {
    (void)pthread_mutex_destroy(mutex);
    return (-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mutex_cond_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_mutex_init@plt>
cmp    $0x0,%rax
je     1163 <mutex_cond_init+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <mutex_cond_init+0x66>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_cond_init@plt>
cmp    $0x0,%rax
je     118f <mutex_cond_init+0x5f>
mov    -0x10(%rbp),%rdi
call   1030 <pthread_mutex_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <mutex_cond_init+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutex_cond_init>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %esi,%esi
call   1050 <pthread_mutex_init@plt>
test   %rax,%rax
jne    1160 <mutex_cond_init+0x30>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <pthread_cond_init@plt>
test   %rax,%rax
je     1165 <mutex_cond_init+0x35>
mov    %r14,%rdi
call   1030 <pthread_mutex_destroy@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @mutex_cond_init(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
%6 = load i32*, i32** %4
%7 = call i64 @pthread_mutex_init(i32* %6, i32* null)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %18
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = call i64 @pthread_cond_init(i32* %11, i32* null)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = call i32 @pthread_mutex_destroy(i32* %15)
store i32 -1, i32* %3
br label %18
17: ; preds = %10
store i32 0, i32* %3
br label %18
18: ; preds = %17, %14, %9
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
define i32 @mutex_cond_init(i32* %0, i32* %1) {
%3 = tail call i64 @pthread_mutex_init(i32* %0, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call i64 @pthread_cond_init(i32* %1, i32* null)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @pthread_mutex_destroy(i32* %0)
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32 [ -1, %8 ], [ -1, %2 ], [ 0, %5 ]
ret i32 %11
}