#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;
scalar_t__ pthread_spin_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_spin_init(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ pthread_spin_lock(int /*<<< orphan*/ *);
scalar_t__ pthread_spin_unlock(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("spin_lock failed");
    return 1;
  }
  if (pthread_spin_unlock(&s) != 0) {
    puts("spin_unlock failed");
    return 1;
  }
  if (pthread_spin_destroy(&s) != 0) {
    puts("spin_destroy failed");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <pthread_spin_init@plt>
cmp    $0x0,%rax
je     118c <do_test+0x3c>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1214 <do_test+0xc4>
lea    -0x8(%rbp),%rdi
call   1030 <pthread_spin_lock@plt>
cmp    $0x0,%rax
je     11b7 <do_test+0x67>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1214 <do_test+0xc4>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_spin_unlock@plt>
cmp    $0x0,%rax
je     11e2 <do_test+0x92>
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1214 <do_test+0xc4>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_spin_destroy@plt>
cmp    $0x0,%rax
je     120d <do_test+0xbd>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1214 <do_test+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rax
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1050 <pthread_spin_init@plt>
test   %rax,%rax
je     1172 <do_test+0x22>
lea    0xe90(%rip),%rdi
jmp    11b8 <do_test+0x68>
lea    0x4(%rsp),%rdi
call   1030 <pthread_spin_lock@plt>
test   %rax,%rax
je     118a <do_test+0x3a>
lea    0xe89(%rip),%rdi
jmp    11b8 <do_test+0x68>
lea    0x4(%rsp),%rdi
call   1060 <pthread_spin_unlock@plt>
test   %rax,%rax
je     11a2 <do_test+0x52>
lea    0xe82(%rip),%rdi
jmp    11b8 <do_test+0x68>
lea    0x4(%rsp),%rdi
call   1070 <pthread_spin_destroy@plt>
test   %rax,%rax
je     11c4 <do_test+0x74>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str = [17 x i8] c"spin_init failed\00"
@.str.1 = [17 x i8] c"spin_lock failed\00"
@.str.2 = [19 x i8] c"spin_unlock failed\00"
@.str.3 = [20 x i8] c"spin_destroy failed\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 %24
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 ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %24
13: ; preds = %8
%14 = call i64 @pthread_spin_unlock(i32* %2)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %24
18: ; preds = %13
%19 = call i64 @pthread_spin_destroy(i32* %2)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %24
23: ; preds = %18
store i32 0, i32* %1
br label %24
24: ; preds = %23, %21, %16, %11, %6
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str = [17 x i8] c"spin_init failed\00"
@.str.1 = [17 x i8] c"spin_lock failed\00"
@.str.2 = [19 x i8] c"spin_unlock failed\00"
@.str.3 = [20 x i8] c"spin_destroy failed\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 %15
6: ; preds = %0
%7 = call i64 @pthread_spin_lock(i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = call i64 @pthread_spin_unlock(i32* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i64 @pthread_spin_destroy(i32* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12, %9, %6, %0
%16 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %12 ]
%17 = call i32 @puts(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %15, %12
%19 = phi i32 [ 0, %12 ], [ 1, %15 ]
ret i32 %19
}