#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 */
struct sched_param {
  int sched_priority;
};
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int SCHED_RR;
int /*<<< orphan*/ printf(char *, ...);
int pthread_getattr_np(int /*<<< orphan*/, int /*<<< orphan*/ *);
int pthread_getschedparam(int /*<<< orphan*/, int *, struct sched_param *);
int /*<<< orphan*/ pthread_self();
void *thread_fun(void *arg) {
  pthread_attr_t gattr;
  struct sched_param prio;
  int th_status;
  int i;
  th_status = pthread_getattr_np(pthread_self(), &gattr);
  th_status = pthread_getschedparam(pthread_self(), &i, &prio);
  if (i == SCHED_RR)
    printf("sched_rr\n");
  printf("priority %d\n", prio.sched_priority);
  return NULL;
}


x86 assembly (clang, -O0):
<thread_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
lea    -0xc(%rbp),%rsi
call   1030 <pthread_getattr_np@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <pthread_getschedparam@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%eax
jne    119a <thread_fun+0x5a>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_fun>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x14(%rsp),%rsi
mov    %eax,%edi
call   1040 <pthread_getattr_np@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1060 <pthread_getschedparam@plt>
mov    0x10(%rsp),%eax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%eax
jne    119a <thread_fun+0x4a>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [10 x i8] c"sched_rr\0A\00"
@.str.1 = [13 x i8] c"priority %d\0A\00"
define i8* @thread_fun(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sched_param
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i32 (...) @pthread_self()
%8 = call i32 @pthread_getattr_np(i32 %7, i32* %3)
store i32 %8, i32* %5
%9 = call i32 (...) @pthread_self()
%10 = call i32 @pthread_getschedparam(i32 %9, i32* %6, %struct.sched_param* %4)
store i32 %10, i32* %5
%11 = load i32, i32* %6
%12 = load i32, i32* @SCHED_RR
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18)
ret i8* null
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str.1 = [13 x i8] c"priority %d\0A\00"
@str = [9 x i8] c"sched_rr\00"
define noalias i8* @thread_fun(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.sched_param* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 (...) @pthread_self()
%9 = call i32 @pthread_getattr_np(i32 %8, i32* %2)
%10 = call i32 (...) @pthread_self()
%11 = call i32 @pthread_getschedparam(i32 %10, i32* %4, %struct.sched_param* %3)
%12 = load i32, i32* %4
%13 = load i32, i32* @SCHED_RR
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %19)
ret i8* null
}