#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_getschedparam(int /*<<< orphan*/, int *, struct sched_param *);
int /*<<< orphan*/ pthread_self();
int pthread_setschedparam(int /*<<< orphan*/, int, struct sched_param *);
void *thread_fun(void *arg) {
  pthread_attr_t gattr;
  struct sched_param prio;
  int s;
  int i;
  int p;
  prio.sched_priority = 87;
  p = pthread_setschedparam(pthread_self(), SCHED_RR, &prio);
  if (p != 0)
    printf("pthraedj is failed\n");
  s = pthread_getschedparam(pthread_self(), &i, &prio);
  if (i == SCHED_RR)
    printf("child sched_rr\n");
  printf("child 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)
movl   $0x57,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_setschedparam@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1189 <thread_fun+0x49>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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    0x2e2c(%rip),%rcx
cmp    (%rcx),%eax
jne    11c2 <thread_fun+0x82>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_fun>:
push   %rbx
sub    $0x10,%rsp
movl   $0x57,0x8(%rsp)
xor    %eax,%eax
call   1070 <pthread_self@plt>
mov    0x2e6d(%rip),%rbx
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1040 <pthread_setschedparam@plt>
test   %eax,%eax
je     1189 <thread_fun+0x39>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1060 <pthread_getschedparam@plt>
mov    0xc(%rsp),%eax
cmp    (%rbx),%eax
jne    11b5 <thread_fun+0x65>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [20 x i8] c"pthraedj is failed\0A\00"
@.str.1 = [16 x i8] c"child sched_rr\0A\00"
@.str.2 = [19 x i8] c"child 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
%7 = alloca i32
store i8* %0, i8** %2
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 87, i32* %8
%9 = call i32 (...) @pthread_self()
%10 = load i32, i32* @SCHED_RR
%11 = call i32 @pthread_setschedparam(i32 %9, i32 %10, %struct.sched_param* %4)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = call i32 (...) @pthread_self()
%18 = call i32 @pthread_getschedparam(i32 %17, i32* %6, %struct.sched_param* %4)
store i32 %18, i32* %5
%19 = load i32, i32* %6
%20 = load i32, i32* @SCHED_RR
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret i8* null
}

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