#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*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int pthread_mutex_destroy(int /*<<< orphan*/ *);
int pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int test_mutex_init_teardown(void) {
  pthread_mutex_t mutex;
  do {
    int __my_ret__ = pthread_mutex_init(&mutex, NULL);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 42,
              "pthread_mutex_init(&mutex, NULL)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_mutex_destroy(&mutex);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 43,
              "pthread_mutex_destroy(&mutex)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_mutex_init_teardown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_mutex_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117e <test_mutex_init_teardown+0x4e>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    $0x2a,%edx
lea    0xea9(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <test_mutex_init_teardown+0xa6>
jmp    1183 <test_mutex_init_teardown+0x53>
jmp    1188 <test_mutex_init_teardown+0x58>
lea    -0x8(%rbp),%rdi
call   1030 <pthread_mutex_destroy@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ca <test_mutex_init_teardown+0x9a>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    $0x2b,%edx
lea    0xe7e(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <test_mutex_init_teardown+0xa6>
jmp    11cf <test_mutex_init_teardown+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mutex_init_teardown>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
lea    0x4(%rsp),%rdi
xor    %esi,%esi
call   1050 <pthread_mutex_init@plt>
test   %eax,%eax
je     1165 <test_mutex_init_teardown+0x35>
mov    %eax,%ebp
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
lea    0xeb9(%rip),%rcx
mov    $0x2a,%edx
jmp    1191 <test_mutex_init_teardown+0x61>
lea    0x4(%rsp),%rdi
call   1030 <pthread_mutex_destroy@plt>
test   %eax,%eax
je     1198 <test_mutex_init_teardown+0x68>
mov    %eax,%ebp
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
lea    0xeac(%rip),%rcx
mov    $0x2b,%edx
call   1040 <fprintf@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.1 = [33 x i8] c"pthread_mutex_init(&mutex, NULL)\00"
@.str.2 = [30 x i8] c"pthread_mutex_destroy(&mutex)\00"
define i32 @test_mutex_init_teardown() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
br label %5
5: ; preds = %0
%6 = call i32 @pthread_mutex_init(i32* %2, i32* null)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %3
store i32 %12, i32* %1
br label %25
13: ; preds = %5
br label %14
14: ; preds = %13
br label %15
15: ; preds = %14
%16 = call i32 @pthread_mutex_destroy(i32* %2)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %4
store i32 %22, i32* %1
br label %25
23: ; preds = %15
br label %24
24: ; preds = %23
store i32 0, i32* %1
br label %25
25: ; preds = %24, %19, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.1 = [33 x i8] c"pthread_mutex_init(&mutex, NULL)\00"
@.str.2 = [30 x i8] c"pthread_mutex_destroy(&mutex)\00"
define i32 @test_mutex_init_teardown() {
%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 %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = call i32 @pthread_mutex_destroy(i32* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %11, %8, %5
%15 = phi i32 [ %3, %5 ], [ 0, %8 ], [ %9, %11 ]
ret i32 %15
}