#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 /*<<< orphan*/ PTHREAD_EXPLICIT_SCHED;
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_attr_setinheritsched(int /*<<< orphan*/ *,
                                                int /*<<< orphan*/);
int /*<<< orphan*/ pthread_attr_setschedparam(int /*<<< orphan*/ *,
                                              struct sched_param *);
int /*<<< orphan*/ pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int);
void set_threads_sched(pthread_attr_t *thread_attr, int priority,
                       int sched_alg) {
  struct sched_param thread_sched;
  pthread_attr_init(thread_attr);
  pthread_attr_setinheritsched(thread_attr, PTHREAD_EXPLICIT_SCHED);
  pthread_attr_setschedpolicy(thread_attr, sched_alg);
  thread_sched.sched_priority = priority;
  pthread_attr_setschedparam(thread_attr, &thread_sched);
}


x86 assembly (clang, -O0):
<set_threads_sched>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1030 <pthread_attr_setinheritsched@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <pthread_attr_setschedparam@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_threads_sched>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1050 <pthread_attr_init@plt>
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1030 <pthread_attr_setinheritsched@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %r14d,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <pthread_attr_setschedparam@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@PTHREAD_EXPLICIT_SCHED = global i32 0
define void @set_threads_sched(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sched_param
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = call i32 @pthread_attr_init(i32* %8)
%10 = load i32*, i32** %4
%11 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%12 = call i32 @pthread_attr_setinheritsched(i32* %10, i32 %11)
%13 = load i32*, i32** %4
%14 = load i32, i32* %6
%15 = call i32 @pthread_attr_setschedpolicy(i32* %13, i32 %14)
%16 = load i32, i32* %5
%17 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32*, i32** %4
%19 = call i32 @pthread_attr_setschedparam(i32* %18, %struct.sched_param* %7)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@PTHREAD_EXPLICIT_SCHED = global i32 0
define void @set_threads_sched(i32* %0, i32 %1, i32 %2) {
%4 = alloca %struct.sched_param
%5 = bitcast %struct.sched_param* %4 to i8*
%6 = tail call i32 @pthread_attr_init(i32* %0)
%7 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%8 = tail call i32 @pthread_attr_setinheritsched(i32* %0, i32 %7)
%9 = tail call i32 @pthread_attr_setschedpolicy(i32* %0, i32 %2)
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i64 0, i32 0
store i32 %1, i32* %10
%11 = call i32 @pthread_attr_setschedparam(i32* %0, %struct.sched_param* %4)
ret void
}