#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*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int pthread_spin_destroy(int /*<<< orphan*/ *);
int pthread_spin_init(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int test_spin_init_teardown(void) {
  pthread_spinlock_t spin;
  do {
    int __my_ret__ = pthread_spin_init(&spin, 0);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 57,
              "pthread_spin_init(&spin, 0)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_spin_destroy(&spin);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 58,
              "pthread_spin_destroy(&spin)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_spin_init_teardown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <pthread_spin_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117c <test_spin_init_teardown+0x4c>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x39,%edx
lea    0xeab(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <test_spin_init_teardown+0xa4>
jmp    1181 <test_spin_init_teardown+0x51>
jmp    1186 <test_spin_init_teardown+0x56>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_spin_destroy@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11c8 <test_spin_init_teardown+0x98>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    $0x3a,%edx
lea    0xe7b(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <test_spin_init_teardown+0xa4>
jmp    11cd <test_spin_init_teardown+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_spin_init_teardown>:
push   %rbp
push   %rbx
push   %rax
lea    0x4(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <pthread_spin_init@plt>
test   %eax,%eax
je     1165 <test_spin_init_teardown+0x35>
mov    %eax,%ebp
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
lea    0xeb9(%rip),%rcx
mov    $0x39,%edx
jmp    1191 <test_spin_init_teardown+0x61>
lea    0x4(%rsp),%rdi
call   1050 <pthread_spin_destroy@plt>
test   %eax,%eax
je     1198 <test_spin_init_teardown+0x68>
mov    %eax,%ebp
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
lea    0xea7(%rip),%rcx
mov    $0x3a,%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 = [28 x i8] c"pthread_spin_init(&spin, 0)\00"
@.str.2 = [28 x i8] c"pthread_spin_destroy(&spin)\00"
define i32 @test_spin_init_teardown() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
br label %5
5: ; preds = %0
%6 = call i32 @pthread_spin_init(i32* %2, i32 0)
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 57, i8* getelementptr inbounds ([28 x i8], [28 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_spin_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 58, i8* getelementptr inbounds ([28 x i8], [28 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 = [28 x i8] c"pthread_spin_init(&spin, 0)\00"
@.str.2 = [28 x i8] c"pthread_spin_destroy(&spin)\00"
define i32 @test_spin_init_teardown() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_spin_init(i32* %1, i32 0)
%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 57, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = call i32 @pthread_spin_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 58, i8* getelementptr inbounds ([28 x i8], [28 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
}