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

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_SCOPE_PROCESS;
int /*<<< orphan*/ PTHREAD_SCOPE_SYSTEM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int pthread_attr_destroy(int /*<<< orphan*/ *);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setscope(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ verify_scope(int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(void) {
  int rc = 0;
  pthread_attr_t attr;
  rc = pthread_attr_init(&attr);
  if (rc != 0) {
    perror("unexpected error: "
           "pthread_attr_getscope"
           " "
           "1-1"
           ": "
           "pthread_attr_init");
    exit(2);
  }
  rc = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
  if (rc != 0) {
    perror("unexpected error: "
           "pthread_attr_getscope"
           " "
           "1-1"
           ": "
           "PTHREAD_SCOPE_SYSTEM is not supported");
  } else {
    verify_scope(&attr, PTHREAD_SCOPE_SYSTEM);
  }
  rc = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
  if (rc != 0) {
    perror("unexpected error: "
           "pthread_attr_getscope"
           " "
           "1-1"
           ": "
           "PTHREAD_SCOPE_SYSTEM is not supported");
  } else {
    verify_scope(&attr, PTHREAD_SCOPE_PROCESS);
  }
  rc = pthread_attr_destroy(&attr);
  if (rc != 0) {
    perror("unexpected error: "
           "pthread_attr_getscope"
           " "
           "1-1"
           ": "
           "pthread_attr_destroy");
    exit(2);
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b2 <main+0x42>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1050 <pthread_attr_setscope@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e2 <main+0x72>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
jmp    11f4 <main+0x84>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1090 <verify_scope@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1050 <pthread_attr_setscope@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1224 <main+0xb4>
lea    0xe25(%rip),%rdi
call   1060 <perror@plt>
jmp    1236 <main+0xc6>
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1090 <verify_scope@plt>
lea    -0xc(%rbp),%rdi
call   1070 <pthread_attr_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1262 <main+0xf2>
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe6b(%rip),%rdi
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   1040 <pthread_attr_init@plt>
test   %eax,%eax
jne    120b <main+0x9b>
mov    0x2e5a(%rip),%rbx
mov    (%rbx),%esi
lea    0xc(%rsp),%rdi
call   1050 <pthread_attr_setscope@plt>
test   %eax,%eax
jne    11ef <main+0x7f>
mov    (%rbx),%esi
lea    0xc(%rsp),%rdi
call   1090 <verify_scope@plt>
mov    0x2e27(%rip),%rbx
mov    (%rbx),%esi
lea    0xc(%rsp),%rdi
call   1050 <pthread_attr_setscope@plt>
test   %eax,%eax
jne    11fd <main+0x8d>
mov    (%rbx),%esi
lea    0xc(%rsp),%rdi
call   1090 <verify_scope@plt>
lea    0xc(%rsp),%rdi
call   1070 <pthread_attr_destroy@plt>
test   %eax,%eax
jne    1214 <main+0xa4>
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe49(%rip),%rdi
call   1060 <perror@plt>
jmp    11aa <main+0x3a>
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
jmp    11cd <main+0x5d>
lea    0xdee(%rip),%rdi
jmp    121b <main+0xab>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"unexpected error: pthread_attr_getscope 1-1: pthread_attr_init\00"
@PTHREAD_SCOPE_SYSTEM = global i32 0
@.str.1 = [83 x i8] c"unexpected error: pthread_attr_getscope 1-1: PTHREAD_SCOPE_SYSTEM is not supported\00"
@PTHREAD_SCOPE_PROCESS = global i32 0
@.str.2 = [66 x i8] c"unexpected error: pthread_attr_getscope 1-1: pthread_attr_destroy\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
store i32 0, i32* %2
%4 = call i32 @pthread_attr_init(i32* %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 2)
unreachable
10: ; preds = %0
%11 = load i32, i32* @PTHREAD_SCOPE_SYSTEM
%12 = call i32 @pthread_attr_setscope(i32* %3, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = load i32, i32* @PTHREAD_SCOPE_SYSTEM
%19 = call i32 @verify_scope(i32* %3, i32 %18)
br label %20
20: ; preds = %17, %15
%21 = load i32, i32* @PTHREAD_SCOPE_PROCESS
%22 = call i32 @pthread_attr_setscope(i32* %3, i32 %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.1, i64 0, i64 0))
br label %30
27: ; preds = %20
%28 = load i32, i32* @PTHREAD_SCOPE_PROCESS
%29 = call i32 @verify_scope(i32* %3, i32 %28)
br label %30
30: ; preds = %27, %25
%31 = call i32 @pthread_attr_destroy(i32* %3)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %30
%38 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [63 x i8] c"unexpected error: pthread_attr_getscope 1-1: pthread_attr_init\00"
@PTHREAD_SCOPE_SYSTEM = global i32 0
@.str.1 = [83 x i8] c"unexpected error: pthread_attr_getscope 1-1: PTHREAD_SCOPE_SYSTEM is not supported\00"
@PTHREAD_SCOPE_PROCESS = global i32 0
@.str.2 = [66 x i8] c"unexpected error: pthread_attr_getscope 1-1: pthread_attr_destroy\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_attr_init(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 2)
unreachable
8: ; preds = %0
%9 = load i32, i32* @PTHREAD_SCOPE_SYSTEM
%10 = call i32 @pthread_attr_setscope(i32* %1, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.1, i64 0, i64 0))
br label %17
14: ; preds = %8
%15 = load i32, i32* @PTHREAD_SCOPE_SYSTEM
%16 = call i32 @verify_scope(i32* %1, i32 %15)
br label %17
17: ; preds = %14, %12
%18 = load i32, i32* @PTHREAD_SCOPE_PROCESS
%19 = call i32 @pthread_attr_setscope(i32* %1, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.1, i64 0, i64 0))
br label %26
23: ; preds = %17
%24 = load i32, i32* @PTHREAD_SCOPE_PROCESS
%25 = call i32 @verify_scope(i32* %1, i32 %24)
br label %26
26: ; preds = %23, %21
%27 = call i32 @pthread_attr_destroy(i32* %1)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 2)
unreachable
32: ; preds = %26
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
}