#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 SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *);
int pthread_attr_getschedpolicy(int /*<<< orphan*/ *, int *);
int get_thread_policy(pthread_attr_t *attr) {
  int policy;
  int rs = pthread_attr_getschedpolicy(attr, &policy);
  assert(rs == 0);
  switch (policy) {
  case SCHED_FIFO:
    printf("policy=SCHED_FIFO\n");
    break;
  case SCHED_RR:
    printf("policy=SCHED_RR\n");
    break;
  case SCHED_OTHER:
    printf("policy=SCHED_OTHER\n");
    break;
  default:
    printf("policy=UNKNOWN\n");
    break;
  }
  return policy;
}


x86 assembly (clang, -O0):
<get_thread_policy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <pthread_attr_getschedpolicy@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
test   %eax,%eax
sete   %al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     11a9 <get_thread_policy+0x79>
jmp    1172 <get_thread_policy+0x42>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     11ba <get_thread_policy+0x8a>
jmp    1185 <get_thread_policy+0x55>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
jne    11cb <get_thread_policy+0x9b>
jmp    1198 <get_thread_policy+0x68>
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <get_thread_policy+0xa7>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <get_thread_policy+0xa7>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <get_thread_policy+0xa7>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_thread_policy>:
push   %rax
lea    0x4(%rsp),%rsi
call   1050 <pthread_attr_getschedpolicy@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x4(%rsp),%eax
add    $0xffffff80,%eax
cmp    $0x2,%eax
ja     1166 <get_thread_policy+0x36>
cltq
lea    0xee7(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    116d <get_thread_policy+0x3d>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"policy=SCHED_FIFO\0A\00"
@.str.1 = [17 x i8] c"policy=SCHED_RR\0A\00"
@.str.2 = [20 x i8] c"policy=SCHED_OTHER\0A\00"
@.str.3 = [16 x i8] c"policy=UNKNOWN\0A\00"
define i32 @get_thread_policy(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @pthread_attr_getschedpolicy(i32* %5, i32* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %3
switch i32 %11, label %18 [
i32 130, label %12
i32 128, label %14
i32 129, label %16
]
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %20
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %20
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %20
18: ; preds = %1
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %16, %14, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@str = [19 x i8] c"policy=SCHED_OTHER\00"
@str.4 = [16 x i8] c"policy=SCHED_RR\00"
@str.5 = [18 x i8] c"policy=SCHED_FIFO\00"
@str.6 = [15 x i8] c"policy=UNKNOWN\00"
@reltable.get_thread_policy = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.get_thread_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @str to i64), i64 ptrtoint ([3 x i32]* @reltable.get_thread_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.5 to i64), i64 ptrtoint ([3 x i32]* @reltable.get_thread_policy to i64)) to i32)]
define i32 @get_thread_policy(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @pthread_attr_getschedpolicy(i32* %0, i32* %2)
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %2
%9 = add i32 %8, -128
%10 = icmp ult i32 %9, 3
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = sext i32 %9 to i64
%13 = shl i64 %12, 2
%14 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.get_thread_policy to i8*), i64 %13)
br label %15
15: ; preds = %1, %11
%16 = phi i8* [ %14, %11 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.6, i64 0, i64 0), %1 ]
%17 = call i32 @puts(i8* dereferenceable(1) %16)
%18 = load i32, i32* %2
ret i32 %18
}