#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*/ alarm(int);
scalar_t__ pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_lock(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("1st mutex_lock failed");
    return 1;
  }
  alarm(1);
  pthread_mutex_lock(&m);
  puts("2nd mutex_lock returned");
  return 1;
}


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   1050 <pthread_mutex_init@plt>
cmp    $0x0,%rax
je     1177 <do_test+0x37>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <do_test+0x88>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
je     11a2 <do_test+0x62>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <do_test+0x88>
mov    $0x1,%edi
call   1040 <alarm@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_mutex_lock@plt>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-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   1050 <pthread_mutex_init@plt>
test   %rax,%rax
je     115b <do_test+0x1b>
lea    0xea7(%rip),%rdi
jmp    118e <do_test+0x4e>
lea    0x4(%rsp),%rdi
call   1060 <pthread_mutex_lock@plt>
test   %rax,%rax
je     1173 <do_test+0x33>
lea    0xea1(%rip),%rdi
jmp    118e <do_test+0x4e>
mov    $0x1,%edi
call   1040 <alarm@plt>
lea    0x4(%rsp),%rdi
call   1060 <pthread_mutex_lock@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"mutex_init failed\00"
@.str.1 = [22 x i8] c"1st mutex_lock failed\00"
@.str.2 = [24 x i8] c"2nd mutex_lock returned\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 %16
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 ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %16
12: ; preds = %7
%13 = call i32 @alarm(i32 1)
%14 = call i64 @pthread_mutex_lock(i32* %2)
%15 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %16
16: ; preds = %12, %10, %5
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [18 x i8] c"mutex_init failed\00"
@.str.1 = [22 x i8] c"1st mutex_lock failed\00"
@.str.2 = [24 x i8] c"2nd mutex_lock returned\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 %11
5: ; preds = %0
%6 = call i64 @pthread_mutex_lock(i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = call i32 @alarm(i32 1)
%10 = call i64 @pthread_mutex_lock(i32* %1)
br label %11
11: ; preds = %5, %0, %8
%12 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %5 ]
%13 = call i32 @puts(i8* dereferenceable(1) %12)
ret i32 1
}