#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 */
#define PTHREAD_SCOPE_PROCESS 132
#define PTHREAD_SCOPE_SYSTEM 131
#define SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ pthread_attr_getschedpolicy(int /*<<< orphan*/ *, int *);
scalar_t__ pthread_attr_getscope(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  pthread_attr_t attr;
  int scope;
  int policy;
  pthread_attr_init(&attr);
  if (pthread_attr_getscope(&attr, &scope) != 0)
    perror("pthread_attr_getscope()");
  switch (scope) {
  case PTHREAD_SCOPE_PROCESS:
    printf("PTHREAD_SCOPE_PROCESS\n");
    break;
  case PTHREAD_SCOPE_SYSTEM:
    printf("PTHREAD_SCOPE_SYSTEM\n");
  }
  if (pthread_attr_getschedpolicy(&attr, &policy) != 0)
    perror("pthread_attr_getschedpolicy()");
  switch (policy) {
  case SCHED_FIFO:
    printf("SCHED_FIFO\n");
    break;
  case SCHED_RR:
    printf("SCHED_RR\n");
    break;
  case SCHED_OTHER:
    printf("SCHED_OTHER\n");
    break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <pthread_attr_getscope@plt>
cmp    $0x0,%rax
je     1192 <main+0x42>
lea    0xe73(%rip),%rdi
call   1070 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x83,%eax
je     11cc <main+0x7c>
jmp    11a8 <main+0x58>
mov    -0x20(%rbp),%eax
sub    $0x84,%eax
jne    11d8 <main+0x88>
jmp    11bb <main+0x6b>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
jmp    11d8 <main+0x88>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <pthread_attr_getschedpolicy@plt>
cmp    $0x0,%rax
je     11fb <main+0xab>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     1248 <main+0xf8>
jmp    1211 <main+0xc1>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     1259 <main+0x109>
jmp    1224 <main+0xd4>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
jne    1265 <main+0x115>
jmp    1237 <main+0xe7>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
jmp    1265 <main+0x115>
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
jmp    1265 <main+0x115>
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <pthread_attr_init@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <pthread_attr_getscope@plt>
test   %rax,%rax
jne    11d8 <main+0x88>
mov    0x8(%rsp),%eax
cmp    $0x84,%eax
je     118f <main+0x3f>
cmp    $0x83,%eax
jne    119b <main+0x4b>
lea    0xea9(%rip),%rdi
jmp    1196 <main+0x46>
lea    0xed5(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1060 <pthread_attr_getschedpolicy@plt>
test   %rax,%rax
jne    11e6 <main+0x96>
mov    0x4(%rsp),%eax
add    $0xffffff80,%eax
cmp    $0x2,%eax
ja     11d0 <main+0x80>
cltq
lea    0xec0(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
jmp    1174 <main+0x24>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
jmp    11af <main+0x5f>

LLVM IR (-O0):
@.str = [24 x i8] c"pthread_attr_getscope()\00"
@.str.1 = [23 x i8] c"PTHREAD_SCOPE_PROCESS\0A\00"
@.str.2 = [22 x i8] c"PTHREAD_SCOPE_SYSTEM\0A\00"
@.str.3 = [30 x i8] c"pthread_attr_getschedpolicy()\00"
@.str.4 = [12 x i8] c"SCHED_FIFO\0A\00"
@.str.5 = [10 x i8] c"SCHED_RR\0A\00"
@.str.6 = [13 x i8] c"SCHED_OTHER\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @pthread_attr_init(i32* %6)
%10 = call i64 @pthread_attr_getscope(i32* %6, i32* %7)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %7
switch i32 %15, label %20 [
i32 132, label %16
i32 131, label %18
]
16: ; preds = %14
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14, %16
%21 = call i64 @pthread_attr_getschedpolicy(i32* %6, i32* %8)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %8
switch i32 %26, label %33 [
i32 130, label %27
i32 128, label %29
i32 129, label %31
]
27: ; preds = %25
%28 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %33
29: ; preds = %25
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %33
31: ; preds = %25
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %33
33: ; preds = %25, %31, %29, %27
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [24 x i8] c"pthread_attr_getscope()\00"
@.str.3 = [30 x i8] c"pthread_attr_getschedpolicy()\00"
@str = [21 x i8] c"PTHREAD_SCOPE_SYSTEM\00"
@str.7 = [12 x i8] c"SCHED_OTHER\00"
@str.8 = [9 x i8] c"SCHED_RR\00"
@str.9 = [11 x i8] c"SCHED_FIFO\00"
@str.10 = [22 x i8] c"PTHREAD_SCOPE_PROCESS\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @str.8 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.7 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.9 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 @pthread_attr_init(i32* %3)
%10 = call i64 @pthread_attr_getscope(i32* %3, i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %4
switch i32 %15, label %20 [
i32 132, label %17
i32 131, label %16
]
16: ; preds = %14
br label %17
17: ; preds = %14, %16
%18 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %16 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0), %14 ]
%19 = call i32 @puts(i8* dereferenceable(1) %18)
br label %20
20: ; preds = %17, %14
%21 = call i64 @pthread_attr_getschedpolicy(i32* %3, i32* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %5
%27 = add i32 %26, -128
%28 = icmp ult i32 %27, 3
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = sext i32 %27 to i64
%31 = shl i64 %30, 2
%32 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %31)
%33 = call i32 @puts(i8* dereferenceable(1) %32)
br label %34
34: ; preds = %25, %29
ret i32 0
}