#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 void pthread_t;
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
scalar_t__ malloc(int);
int pthread_attr_getschedpolicy(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setschedparam(int /*<<< orphan*/ *, struct sched_param *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_create(void *, int /*<<< orphan*/ *, void *(*)(void *), void *);
int sched_get_priority_max(int);
void *ThreadCreate(void *(*Start)(void *), void *Parameter, int Quantum) {
  pthread_attr_t attr;
  struct sched_param param;
  int ret = 0;
  pthread_t *thread_id = (pthread_t *)malloc(sizeof(pthread_t));
  int policy = 0;
  int primax = 0;
  pthread_attr_init(&attr);
  ret = pthread_attr_setschedpolicy(&attr, SCHED_RR);
  ret = pthread_attr_getschedpolicy(&attr, &policy);
  primax = sched_get_priority_max(policy);
  param.sched_priority = primax;
  ret = pthread_attr_setschedparam(&attr, &param);
  ret = pthread_create(thread_id, &attr, Start, Parameter);
  return thread_id;
}


x86 assembly (clang, -O0):
<ThreadCreate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <pthread_attr_init@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1060 <pthread_attr_getschedpolicy@plt>
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%edi
call   1090 <sched_get_priority_max@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rsi
call   1070 <pthread_create@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ThreadCreate>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movl   $0x0,0xc(%rsp)
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <pthread_attr_init@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <pthread_attr_setschedpolicy@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <pthread_attr_getschedpolicy@plt>
mov    0xc(%rsp),%edi
call   1090 <sched_get_priority_max@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <pthread_attr_setschedparam@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <pthread_create@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
define i8* @ThreadCreate(i8* (i8*)* %0, i8* %1, i32 %2) {
%4 = alloca i8* (i8*)*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sched_param
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %9
%13 = call i64 @malloc(i32 1)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %10
store i32 0, i32* %11
store i32 0, i32* %12
%15 = call i32 @pthread_attr_init(i32* %7)
%16 = load i32, i32* @SCHED_RR
%17 = call i32 @pthread_attr_setschedpolicy(i32* %7, i32 %16)
store i32 %17, i32* %9
%18 = call i32 @pthread_attr_getschedpolicy(i32* %7, i32* %11)
store i32 %18, i32* %9
%19 = load i32, i32* %11
%20 = call i32 @sched_get_priority_max(i32 %19)
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %8, i32 0, i32 0
store i32 %21, i32* %22
%23 = call i32 @pthread_attr_setschedparam(i32* %7, %struct.sched_param* %8)
store i32 %23, i32* %9
%24 = load i8*, i8** %10
%25 = load i8* (i8*)*, i8* (i8*)** %4
%26 = load i8*, i8** %5
%27 = call i32 @pthread_create(i8* %24, i32* %7, i8* (i8*)* %25, i8* %26)
store i32 %27, i32* %9
%28 = load i8*, i8** %10
ret i8* %28
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
define i8* @ThreadCreate(i8* (i8*)* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sched_param
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sched_param* %5 to i8*
%9 = tail call i64 @malloc(i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%12 = call i32 @pthread_attr_init(i32* %4)
%13 = load i32, i32* @SCHED_RR
%14 = call i32 @pthread_attr_setschedpolicy(i32* %4, i32 %13)
%15 = call i32 @pthread_attr_getschedpolicy(i32* %4, i32* %6)
%16 = load i32, i32* %6
%17 = call i32 @sched_get_priority_max(i32 %16)
%18 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i64 0, i32 0
store i32 %17, i32* %18
%19 = call i32 @pthread_attr_setschedparam(i32* %4, %struct.sched_param* %5)
%20 = call i32 @pthread_create(i8* %10, i32* %4, i8* (i8*)* %0, i8* %1)
ret i8* %10
}