#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_DEFAULT;
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*/ *);
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_gettype(&mta, &type) != 0) {
    fprintf(
        stderr,
        "pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n");
    return 2;
  }
  if (type != PTHREAD_MUTEX_DEFAULT) {
    printf("Test FAILED: Incorrect default mutexattr 'type' value: %d\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   1070 <pthread_mutexattr_init@plt>
cmp    $0x0,%rax
je     118a <main+0x3a>
lea    0xe87(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1206 <main+0xb6>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <pthread_mutexattr_gettype@plt>
cmp    $0x0,%rax
je     11c2 <main+0x72>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1206 <main+0xb6>
mov    -0xc(%rbp),%eax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%eax
je     11f1 <main+0xa1>
mov    -0xc(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1206 <main+0xb6>
lea    0xea9(%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   %rax
lea    0x4(%rsp),%rdi
call   1080 <pthread_mutexattr_init@plt>
test   %rax,%rax
jne    11d1 <main+0x71>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <pthread_mutexattr_gettype@plt>
test   %rax,%rax
je     119e <main+0x3e>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%eax
pop    %rcx
ret
mov    (%rsp),%esi
mov    0x2e30(%rip),%rax
cmp    (%rax),%esi
jne    11bc <main+0x5c>
lea    0xeee(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xe28(%rip),%rdi
call   1070 <perror@plt>
jmp    1197 <main+0x37>

LLVM IR (-O0):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@stderr = global i32 0
@.str.1 = [67 x i8] c"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\0A\00"
@PTHREAD_MUTEX_DEFAULT = global i32 0
@.str.2 = [59 x i8] c"Test FAILED: Incorrect default mutexattr 'type' value: %d\0A\00"
@.str.3 = [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 %23
8: ; preds = %0
%9 = call i64 @pthread_mutexattr_gettype(i32* %2, i32* %3)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %23
14: ; preds = %8
%15 = load i32, i32* %3
%16 = load i32, i32* @PTHREAD_MUTEX_DEFAULT
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 1, i32* %1
br label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %23
23: ; preds = %21, %18, %11, %6
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@stderr = global i32 0
@.str.1 = [67 x i8] c"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\0A\00"
@PTHREAD_MUTEX_DEFAULT = global i32 0
@.str.2 = [59 x i8] c"Test FAILED: Incorrect default mutexattr 'type' value: %d\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 %23
9: ; preds = %0
%10 = call i64 @pthread_mutexattr_gettype(i32* %1, i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
br label %23
15: ; preds = %9
%16 = load i32, i32* %2
%17 = load i32, i32* @PTHREAD_MUTEX_DEFAULT
%18 = icmp eq i32 %16, %17
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %23
21: ; preds = %15
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %19, %12, %7
%24 = phi i32 [ 2, %7 ], [ 2, %12 ], [ 1, %19 ], [ 0, %21 ]
ret i32 %24
}