#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 PTHREAD_MUTEX_ERRORCHECK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pthread_mutexattr_gettype(int /*<<< orphan*/ *, int *);
scalar_t__ pthread_mutexattr_init(int /*<<< orphan*/ *);
scalar_t__ pthread_mutexattr_settype(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  pthread_mutexattr_t mta;
  int type;
  if (pthread_mutexattr_init(&mta) != 0) {
    perror("Error at pthread_mutexattr_init()\n");
    return 2;
  }
  if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) {
    fprintf(
        stderr,
        "pthread_mutexattr_settype(): Error setting the attribute 'type'\n");
    return 2;
  }
  if (pthread_mutexattr_gettype(&mta, &type) != 0) {
    fprintf(
        stderr,
        "pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n");
    return 2;
  }
  if (type != PTHREAD_MUTEX_ERRORCHECK) {
    printf("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be "
           "PTHREAD_MUTEX_ERRORCHECK\n",
           type);
    return 1;
  }
  printf("Test PASSED\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   1080 <pthread_mutexattr_init@plt>
cmp    $0x0,%rax
je     119a <main+0x3a>
lea    0xe77(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1253 <main+0xf3>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutexattr_settype@plt>
cmp    $0x0,%rax
je     11d7 <main+0x77>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1253 <main+0xf3>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <pthread_mutexattr_gettype@plt>
cmp    $0x0,%rax
je     120f <main+0xaf>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1253 <main+0xf3>
mov    -0xc(%rbp),%eax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%eax
je     123e <main+0xde>
mov    -0xc(%rbp),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <main+0xf3>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1090 <pthread_mutexattr_init@plt>
test   %rax,%rax
jne    1213 <main+0xa3>
mov    0x2e41(%rip),%rbx
mov    (%rbx),%esi
lea    0x8(%rsp),%rdi
call   1060 <pthread_mutexattr_settype@plt>
test   %rax,%rax
je     11b2 <main+0x42>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
jmp    11d6 <main+0x66>
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1030 <pthread_mutexattr_gettype@plt>
test   %rax,%rax
je     11e6 <main+0x76>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0xc(%rsp),%esi
cmp    (%rbx),%esi
jne    11fe <main+0x8e>
lea    0xf09(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    11e0 <main+0x70>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    11e0 <main+0x70>
lea    0xde6(%rip),%rdi
call   1080 <perror@plt>
jmp    11db <main+0x6b>

LLVM IR (-O0):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@PTHREAD_MUTEX_ERRORCHECK = global i32 0
@stderr = global i32 0
@.str.1 = [65 x i8] c"pthread_mutexattr_settype(): Error setting the attribute 'type'\0A\00"
@.str.2 = [67 x i8] c"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\0A\00"
@.str.3 = [87 x i8] c"Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_ERRORCHECK\0A\00"
@.str.4 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @pthread_mutexattr_init(i32* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %30
8: ; preds = %0
%9 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%10 = call i64 @pthread_mutexattr_settype(i32* %2, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %30
15: ; preds = %8
%16 = call i64 @pthread_mutexattr_gettype(i32* %2, i32* %3)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %30
21: ; preds = %15
%22 = load i32, i32* %3
%23 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i32 %26)
store i32 1, i32* %1
br label %30
28: ; preds = %21
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %30
30: ; preds = %28, %25, %18, %12, %6
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@PTHREAD_MUTEX_ERRORCHECK = global i32 0
@stderr = global i32 0
@.str.1 = [65 x i8] c"pthread_mutexattr_settype(): Error setting the attribute 'type'\0A\00"
@.str.2 = [67 x i8] c"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\0A\00"
@.str.3 = [87 x i8] c"Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_ERRORCHECK\0A\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 @pthread_mutexattr_init(i32* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %30
9: ; preds = %0
%10 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%11 = call i64 @pthread_mutexattr_settype(i32* %1, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
br label %30
16: ; preds = %9
%17 = call i64 @pthread_mutexattr_gettype(i32* %1, i32* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
br label %30
22: ; preds = %16
%23 = load i32, i32* %2
%24 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%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 ([87 x i8], [87 x i8]* @.str.3, 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, %19, %13, %7
%31 = phi i32 [ 2, %7 ], [ 2, %13 ], [ 2, %19 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %31
}