#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_spinlock_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_PROCESS_PRIVATE;
int /*<<< orphan*/ alarm(int);
scalar_t__ pthread_spin_init(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ pthread_spin_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  pthread_spinlock_t s;
  if (pthread_spin_init(&s, PTHREAD_PROCESS_PRIVATE) != 0) {
    puts("spin_init failed");
    return 1;
  }
  if (pthread_spin_lock(&s) != 0) {
    puts("1st spin_lock failed");
    return 1;
  }
  alarm(1);
  pthread_spin_lock(&s);
  puts("2nd spin_lock returned");
  return 1;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1060 <pthread_spin_init@plt>
cmp    $0x0,%rax
je     117c <do_test+0x3c>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <do_test+0x8d>
lea    -0x8(%rbp),%rdi
call   1030 <pthread_spin_lock@plt>
cmp    $0x0,%rax
je     11a7 <do_test+0x67>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <do_test+0x8d>
mov    $0x1,%edi
call   1050 <alarm@plt>
lea    -0x8(%rbp),%rdi
call   1030 <pthread_spin_lock@plt>
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rax
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1060 <pthread_spin_init@plt>
test   %rax,%rax
je     1162 <do_test+0x22>
lea    0xea0(%rip),%rdi
jmp    1195 <do_test+0x55>
lea    0x4(%rsp),%rdi
call   1030 <pthread_spin_lock@plt>
test   %rax,%rax
je     117a <do_test+0x3a>
lea    0xe99(%rip),%rdi
jmp    1195 <do_test+0x55>
mov    $0x1,%edi
call   1050 <alarm@plt>
lea    0x4(%rsp),%rdi
call   1030 <pthread_spin_lock@plt>
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str = [17 x i8] c"spin_init failed\00"
@.str.1 = [21 x i8] c"1st spin_lock failed\00"
@.str.2 = [23 x i8] c"2nd spin_lock returned\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%4 = call i64 @pthread_spin_init(i32* %2, i32 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %17
8: ; preds = %0
%9 = call i64 @pthread_spin_lock(i32* %2)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %17
13: ; preds = %8
%14 = call i32 @alarm(i32 1)
%15 = call i64 @pthread_spin_lock(i32* %2)
%16 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %17
17: ; preds = %13, %11, %6
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str = [17 x i8] c"spin_init failed\00"
@.str.1 = [21 x i8] c"1st spin_lock failed\00"
@.str.2 = [23 x i8] c"2nd spin_lock returned\00"
define i32 @do_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%4 = call i64 @pthread_spin_init(i32* %1, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = call i64 @pthread_spin_lock(i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 @alarm(i32 1)
%11 = call i64 @pthread_spin_lock(i32* %1)
br label %12
12: ; preds = %6, %0, %9
%13 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %6 ]
%14 = call i32 @puts(i8* dereferenceable(1) %13)
ret i32 1
}