#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 EINVAL;
int /*<<< orphan*/ printf(char *, ...);
int pthread_spin_trylock(int /*<<< orphan*/ *);
char *strerror(int);
int main(void) {
  pthread_spinlock_t spinlock;
  int rc;
  rc = pthread_spin_trylock(&spinlock);
  if (rc == EINVAL) {
    printf("Correctly got EINVAL at pthread_spin_trylock()\n");
    printf("Test PASSED\n");
  } else {
    printf("Expected EINVAL, but get return code: %d,%s\n", rc, strerror(rc));
    printf("Test PASSED: *Note: Returned incorrect value, but standard says "
           "'may' fail\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <pthread_spin_trylock@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jne    117e <main+0x4e>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <main+0x7e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1050 <pthread_spin_trylock@plt>
mov    %eax,%ebx
mov    0x2e88(%rip),%rax
cmp    (%rax),%ebx
jne    1171 <main+0x31>
lea    0xf15(%rip),%rdi
call   1030 <puts@plt>
lea    0xf38(%rip),%rdi
jmp    1192 <main+0x52>
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [48 x i8] c"Correctly got EINVAL at pthread_spin_trylock()\0A\00"
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [45 x i8] c"Expected EINVAL, but get return code: %d,%s\0A\00"
@.str.3 = [76 x i8] c"Test PASSED: *Note: Returned incorrect value, but standard says 'may' fail\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @pthread_spin_trylock(i32* %2)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @EINVAL
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %17
11: ; preds = %0
%12 = load i32, i32* %3
%13 = load i32, i32* %3
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %11, %8
ret i32 0
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str.2 = [45 x i8] c"Expected EINVAL, but get return code: %d,%s\0A\00"
@str = [75 x i8] c"Test PASSED: *Note: Returned incorrect value, but standard says 'may' fail\00"
@str.4 = [47 x i8] c"Correctly got EINVAL at pthread_spin_trylock()\00"
@str.5 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_spin_trylock(i32* %1)
%4 = load i32, i32* @EINVAL
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.4, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = call i8* @strerror(i32 %3)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %3, i8* %9)
br label %11
11: ; preds = %8, %6
%12 = phi i8* [ getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0), %6 ]
%13 = call i32 @puts(i8* dereferenceable(1) %12)
ret i32 0
}