#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 pthread_mutex_lock(int /*<<< orphan*/ *);
int pthread_mutex_unlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int test_spin_lock_simple(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", 94,
              "pthread_mutex_init(&mutex, NULL)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_mutex_lock(&mutex);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 95,
              "pthread_mutex_lock(&mutex)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_mutex_unlock(&mutex);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 96,
              "pthread_mutex_unlock(&mutex)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_mutex_lock(&mutex);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 97,
              "pthread_mutex_lock(&mutex)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_mutex_unlock(&mutex);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 98,
              "pthread_mutex_unlock(&mutex)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pthread_mutex_destroy(&mutex);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 99,
              "pthread_mutex_destroy(&mutex)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_spin_lock_simple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <pthread_mutex_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     119e <test_spin_lock_simple+0x4e>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    $0x5e,%edx
lea    0xe89(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1326 <test_spin_lock_simple+0x1d6>
jmp    11a3 <test_spin_lock_simple+0x53>
jmp    11a8 <test_spin_lock_simple+0x58>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_mutex_lock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ea <test_spin_lock_simple+0x9a>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    $0x5f,%edx
lea    0xe5e(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1326 <test_spin_lock_simple+0x1d6>
jmp    11ef <test_spin_lock_simple+0x9f>
jmp    11f4 <test_spin_lock_simple+0xa4>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1236 <test_spin_lock_simple+0xe6>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    $0x60,%edx
lea    0xe2d(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1326 <test_spin_lock_simple+0x1d6>
jmp    123b <test_spin_lock_simple+0xeb>
jmp    1240 <test_spin_lock_simple+0xf0>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_mutex_lock@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1282 <test_spin_lock_simple+0x132>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    $0x61,%edx
lea    0xdc6(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1326 <test_spin_lock_simple+0x1d6>
jmp    1287 <test_spin_lock_simple+0x137>
jmp    128c <test_spin_lock_simple+0x13c>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12ce <test_spin_lock_simple+0x17e>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    $0x62,%edx
lea    0xd95(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1326 <test_spin_lock_simple+0x1d6>
jmp    12d3 <test_spin_lock_simple+0x183>
jmp    12d8 <test_spin_lock_simple+0x188>
lea    -0x8(%rbp),%rdi
call   1030 <pthread_mutex_destroy@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     131a <test_spin_lock_simple+0x1ca>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
mov    $0x63,%edx
lea    0xd66(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1326 <test_spin_lock_simple+0x1d6>
jmp    131f <test_spin_lock_simple+0x1cf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_spin_lock_simple>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1060 <pthread_mutex_init@plt>
test   %eax,%eax
je     1188 <test_spin_lock_simple+0x38>
mov    %eax,%ebx
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
lea    0xe99(%rip),%rcx
mov    $0x5e,%edx
jmp    1272 <test_spin_lock_simple+0x122>
lea    0xc(%rsp),%rdi
call   1070 <pthread_mutex_lock@plt>
test   %eax,%eax
je     11b9 <test_spin_lock_simple+0x69>
mov    %eax,%ebx
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
lea    0xe89(%rip),%rcx
mov    $0x5f,%edx
jmp    1272 <test_spin_lock_simple+0x122>
lea    0xc(%rsp),%rdi
call   1050 <pthread_mutex_unlock@plt>
test   %eax,%eax
je     11ea <test_spin_lock_simple+0x9a>
mov    %eax,%ebx
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
lea    0xe73(%rip),%rcx
mov    $0x60,%edx
jmp    1272 <test_spin_lock_simple+0x122>
lea    0xc(%rsp),%rdi
call   1070 <pthread_mutex_lock@plt>
test   %eax,%eax
je     1218 <test_spin_lock_simple+0xc8>
mov    %eax,%ebx
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
lea    0xe27(%rip),%rcx
mov    $0x61,%edx
jmp    1272 <test_spin_lock_simple+0x122>
lea    0xc(%rsp),%rdi
call   1050 <pthread_mutex_unlock@plt>
test   %eax,%eax
je     1246 <test_spin_lock_simple+0xf6>
mov    %eax,%ebx
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
lea    0xe14(%rip),%rcx
mov    $0x62,%edx
jmp    1272 <test_spin_lock_simple+0x122>
lea    0xc(%rsp),%rdi
call   1030 <pthread_mutex_destroy@plt>
test   %eax,%eax
je     127f <test_spin_lock_simple+0x12f>
mov    %eax,%ebx
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
lea    0xe03(%rip),%rcx
mov    $0x63,%edx
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %ebx,%ebx
jmp    1277 <test_spin_lock_simple+0x127>

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 = [27 x i8] c"pthread_mutex_lock(&mutex)\00"
@.str.3 = [29 x i8] c"pthread_mutex_unlock(&mutex)\00"
@.str.4 = [30 x i8] c"pthread_mutex_destroy(&mutex)\00"
define i32 @test_spin_lock_simple() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
br label %9
9: ; preds = %0
%10 = call i32 @pthread_mutex_init(i32* %2, i32* null)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 94, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %3
store i32 %16, i32* %1
br label %69
17: ; preds = %9
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
%20 = call i32 @pthread_mutex_lock(i32* %2)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 95, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %4
store i32 %26, i32* %1
br label %69
27: ; preds = %19
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
%30 = call i32 @pthread_mutex_unlock(i32* %2)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* %5
store i32 %36, i32* %1
br label %69
37: ; preds = %29
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
%40 = call i32 @pthread_mutex_lock(i32* %2)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 97, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* %6
store i32 %46, i32* %1
br label %69
47: ; preds = %39
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = call i32 @pthread_mutex_unlock(i32* %2)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 98, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* %7
store i32 %56, i32* %1
br label %69
57: ; preds = %49
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = call i32 @pthread_mutex_destroy(i32* %2)
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* %8
store i32 %66, i32* %1
br label %69
67: ; preds = %59
br label %68
68: ; preds = %67
store i32 0, i32* %1
br label %69
69: ; preds = %68, %63, %53, %43, %33, %23, %13
%70 = load i32, i32* %1
ret i32 %70
}

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 = [27 x i8] c"pthread_mutex_lock(&mutex)\00"
@.str.3 = [29 x i8] c"pthread_mutex_unlock(&mutex)\00"
@.str.4 = [30 x i8] c"pthread_mutex_destroy(&mutex)\00"
define i32 @test_spin_lock_simple() {
%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 94, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %38
8: ; preds = %0
%9 = call i32 @pthread_mutex_lock(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 95, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %38
14: ; preds = %8
%15 = call i32 @pthread_mutex_unlock(i32* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %38
20: ; preds = %14
%21 = call i32 @pthread_mutex_lock(i32* %1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 97, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %38
26: ; preds = %20
%27 = call i32 @pthread_mutex_unlock(i32* %1)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 98, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %38
32: ; preds = %26
%33 = call i32 @pthread_mutex_destroy(i32* %1)
%34 = icmp eq i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %35, %32, %29, %23, %17, %11, %5
%39 = phi i32 [ %27, %29 ], [ %21, %23 ], [ %15, %17 ], [ %9, %11 ], [ %3, %5 ], [ 0, %32 ], [ %33, %35 ]
ret i32 %39
}