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

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_EXPLICIT_SCHED;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setinheritsched(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_attr_setschedparam(int /*<<< orphan*/ *, struct sched_param *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), void *);
int create_thread_with_priority(void *(*func)(void *), void *data) {
  pthread_t id;
  pthread_attr_t attr;
  struct sched_param param;
  int res;
  pthread_attr_init(&attr);
  if ((res = pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) != 0)
    printf("setschedpolicy: failure: %m\n");
  param.sched_priority = 30;
  if ((res = pthread_attr_setschedparam(&attr, &param)) != 0)
    printf("setschedparam: failure: %m\n");
  if ((res = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) != 0)
    printf("setinheritsched: failure: %m\n");
  res = pthread_create(&id, &attr, (void *(*)(void *))func, data);
  if (res != 0) {
    printf("pthread create faild: %m\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_thread_with_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pthread_attr_init@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1050 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11a3 <create_thread_with_priority+0x43>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1e,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11cf <create_thread_with_priority+0x6f>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <pthread_attr_setinheritsched@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11f9 <create_thread_with_priority+0x99>
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <pthread_create@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1227 <create_thread_with_priority+0xc7>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_thread_with_priority>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <pthread_attr_init@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
je     119d <create_thread_with_priority+0x3d>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1e,0x8(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
test   %eax,%eax
je     11c4 <create_thread_with_priority+0x64>
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1030 <pthread_attr_setinheritsched@plt>
test   %eax,%eax
je     11e7 <create_thread_with_priority+0x87>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <pthread_create@plt>
test   %eax,%eax
je     120c <create_thread_with_priority+0xac>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [29 x i8] c"setschedpolicy: failure: %m\0A\00"
@.str.1 = [28 x i8] c"setschedparam: failure: %m\0A\00"
@PTHREAD_EXPLICIT_SCHED = global i32 0
@.str.2 = [30 x i8] c"setinheritsched: failure: %m\0A\00"
@.str.3 = [26 x i8] c"pthread create faild: %m\0A\00"
define i32 @create_thread_with_priority(i8* (i8*)* %0, i8* %1) {
%3 = alloca i8* (i8*)*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sched_param
%8 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %3
store i8* %1, i8** %4
%9 = call i32 @pthread_attr_init(i32* %6)
%10 = load i32, i32* @SCHED_FIFO
%11 = call i32 @pthread_attr_setschedpolicy(i32* %6, i32 %10)
store i32 %11, i32* %8
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i32 0, i32 0
store i32 30, i32* %16
%17 = call i32 @pthread_attr_setschedparam(i32* %6, %struct.sched_param* %7)
store i32 %17, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%23 = call i32 @pthread_attr_setinheritsched(i32* %6, i32 %22)
store i32 %23, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i8* (i8*)*, i8* (i8*)** %3
%29 = load i8*, i8** %4
%30 = call i32 @pthread_create(i32* %5, i32* %6, i8* (i8*)* %28, i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [29 x i8] c"setschedpolicy: failure: %m\0A\00"
@.str.1 = [28 x i8] c"setschedparam: failure: %m\0A\00"
@PTHREAD_EXPLICIT_SCHED = global i32 0
@.str.2 = [30 x i8] c"setinheritsched: failure: %m\0A\00"
@.str.3 = [26 x i8] c"pthread create faild: %m\0A\00"
define i32 @create_thread_with_priority(i8* (i8*)* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sched_param
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sched_param* %5 to i8*
%9 = call i32 @pthread_attr_init(i32* %4)
%10 = load i32, i32* @SCHED_FIFO
%11 = call i32 @pthread_attr_setschedpolicy(i32* %4, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i64 0, i32 0
store i32 30, i32* %16
%17 = call i32 @pthread_attr_setschedparam(i32* %4, %struct.sched_param* %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%23 = call i32 @pthread_attr_setinheritsched(i32* %4, i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = call i32 @pthread_create(i32* %3, i32* %4, i8* (i8*)* %0, i8* %1)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
ret i32 0
}