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

/* Variables and functions */
int EINVAL;
int PTHREAD_MUTEX_DEFAULT;
int PTHREAD_MUTEX_ERRORCHECK;
int PTHREAD_MUTEX_NORMAL;
int PTHREAD_MUTEX_RECURSIVE;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pthread_mutexattr_init(int /*<<< orphan*/ *);
int pthread_mutexattr_settype(int /*<<< orphan*/ *, int);
int main(void) {
  pthread_mutexattr_t mta;
  int ret;
  int invalid_type = -1;
  if (pthread_mutexattr_init(&mta) != 0) {
    perror("Error at pthread_mutexattr_init()\n");
    return 2;
  }
  while (invalid_type == PTHREAD_MUTEX_NORMAL ||
         invalid_type == PTHREAD_MUTEX_ERRORCHECK ||
         invalid_type == PTHREAD_MUTEX_RECURSIVE ||
         invalid_type == PTHREAD_MUTEX_DEFAULT) {
    invalid_type--;
  }
  ret = pthread_mutexattr_settype(&mta, invalid_type);
  if (ret != EINVAL) {
    printf("Test FAILED: Expected return code of EINVAL, got: %d\n", ret);
    return 1;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <pthread_mutexattr_init@plt>
cmp    $0x0,%rax
je     1181 <main+0x41>
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    124e <main+0x10e>
jmp    1186 <main+0x46>
mov    -0x10(%rbp),%ecx
mov    $0x1,%al
mov    0x2e4e(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     11dd <main+0x9d>
mov    -0x10(%rbp),%ecx
mov    $0x1,%al
mov    0x2e0f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     11dd <main+0x9d>
mov    -0x10(%rbp),%ecx
mov    $0x1,%al
mov    0x2e38(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     11dd <main+0x9d>
mov    -0x10(%rbp),%eax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11ed <main+0xad>
jmp    11fb <main+0xbb>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <main+0x46>
mov    -0x10(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1040 <pthread_mutexattr_settype@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%eax
je     1239 <main+0xf9>
mov    -0xc(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0x10e>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0x4(%rsp),%rdi
call   1070 <pthread_mutexattr_init@plt>
test   %rax,%rax
jne    11f2 <main+0xa2>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    0x2e44(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e7b(%rip),%rdx
mov    (%rdx),%edx
mov    0x2e4a(%rip),%rsi
mov    (%rsi),%r8d
add    $0x1,%r8d
add    $0x1,%edx
add    $0x1,%ecx
add    $0x1,%eax
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
mov    %esi,%edi
lea    -0x1(%rdi),%esi
cmp    %edi,%eax
je     11a0 <main+0x50>
cmp    %edi,%ecx
je     11a0 <main+0x50>
cmp    %edi,%edx
je     11a0 <main+0x50>
cmp    %edi,%r8d
je     11a0 <main+0x50>
lea    0x4(%rsp),%rdi
call   1050 <pthread_mutexattr_settype@plt>
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%eax
jne    11db <main+0x8b>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe41(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xe07(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@PTHREAD_MUTEX_NORMAL = global i32 0
@PTHREAD_MUTEX_ERRORCHECK = global i32 0
@PTHREAD_MUTEX_RECURSIVE = global i32 0
@PTHREAD_MUTEX_DEFAULT = global i32 0
@EINVAL = global i32 0
@.str.1 = [54 x i8] c"Test FAILED: Expected return code of EINVAL, got: %d\0A\00"
@.str.2 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %4
%5 = call i64 @pthread_mutexattr_init(i32* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %42
9: ; preds = %0
br label %10
10: ; preds = %28, %9
%11 = load i32, i32* %4
%12 = load i32, i32* @PTHREAD_MUTEX_NORMAL
%13 = icmp eq i32 %11, %12
br i1 %13, label %26, label %14
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%17 = icmp eq i32 %15, %16
br i1 %17, label %26, label %18
18: ; preds = %14
%19 = load i32, i32* %4
%20 = load i32, i32* @PTHREAD_MUTEX_RECURSIVE
%21 = icmp eq i32 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* @PTHREAD_MUTEX_DEFAULT
%25 = icmp eq i32 %23, %24
br label %26
26: ; preds = %22, %18, %14, %10
%27 = phi i1 [ true, %18 ], [ true, %14 ], [ true, %10 ], [ %25, %22 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
br label %10
31: ; preds = %26
%32 = load i32, i32* %4
%33 = call i32 @pthread_mutexattr_settype(i32* %2, i32 %32)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = load i32, i32* @EINVAL
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %38)
store i32 1, i32* %1
br label %42
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %42
42: ; preds = %40, %37, %7
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@PTHREAD_MUTEX_NORMAL = global i32 0
@PTHREAD_MUTEX_ERRORCHECK = global i32 0
@PTHREAD_MUTEX_RECURSIVE = global i32 0
@PTHREAD_MUTEX_DEFAULT = global i32 0
@EINVAL = global i32 0
@.str.1 = [54 x i8] c"Test FAILED: Expected return code of EINVAL, got: %d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @pthread_mutexattr_init(i32* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @PTHREAD_MUTEX_NORMAL
%7 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%8 = load i32, i32* @PTHREAD_MUTEX_RECURSIVE
%9 = load i32, i32* @PTHREAD_MUTEX_DEFAULT
br label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %30
12: ; preds = %12, %5
%13 = phi i32 [ %21, %12 ], [ -1, %5 ]
%14 = icmp eq i32 %13, %6
%15 = icmp eq i32 %13, %7
%16 = select i1 %14, i1 true, i1 %15
%17 = icmp eq i32 %13, %8
%18 = select i1 %16, i1 true, i1 %17
%19 = icmp eq i32 %13, %9
%20 = select i1 %18, i1 true, i1 %19
%21 = add nsw i32 %13, -1
br i1 %20, label %12, label %22
22: ; preds = %12
%23 = call i32 @pthread_mutexattr_settype(i32* %1, i32 %13)
%24 = load i32, i32* @EINVAL
%25 = icmp eq i32 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %30
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %26, %10
%31 = phi i32 [ 2, %10 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %31
}