#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 /*<<< orphan*/ sched_priority;
};

/* Variables and functions */
int SCHED_FIFO;
int SCHED_OTHER;
int SCHED_RR;
int /*<<< orphan*/ SYS_gettid;
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int /*<<< orphan*/, char *,
                          int /*<<< orphan*/);
int pthread_getschedparam(int /*<<< orphan*/, int *, struct sched_param *);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
void print_sched_attr(int num) {
  int policy, rtn;
  struct sched_param param;
  rtn = pthread_getschedparam(pthread_self(), &policy, &param);
  if (rtn != 0)
    perror("Unable to retrieve pthread sched param: ");
  printf("Scheduler attributes for [%d]:pid %d, thread %ld, policy: %s, "
         "priority: %d\n",
         num, getpid(), syscall(SYS_gettid),
         (policy == SCHED_FIFO)    ? "SCHED_FIFO"
         : (policy == SCHED_RR)    ? "SCHED_RR"
         : (policy == SCHED_OTHER) ? "SCHED_OTHER"
                                   : "???",
         param.sched_priority);
}


x86 assembly (clang, -O0):
<print_sched_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <pthread_getschedparam@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     119a <print_sched_attr+0x3a>
lea    0xe6b(%rip),%rdi
call   1080 <perror@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%eax
jne    11dd <print_sched_attr+0x7d>
lea    0xea1(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    122b <print_sched_attr+0xcb>
mov    -0x8(%rbp),%eax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%eax
jne    11ff <print_sched_attr+0x9f>
lea    0xe8a(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1223 <print_sched_attr+0xc3>
mov    -0x8(%rbp),%edx
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rax
lea    0xe70(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%r8
mov    -0x10(%rbp),%r9d
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_sched_attr>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
call   1060 <pthread_getschedparam@plt>
test   %eax,%eax
jne    11fa <print_sched_attr+0x9a>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    0x4(%rsp),%ecx
mov    0x2e3f(%rip),%rdx
cmp    (%rdx),%ecx
jne    11ae <print_sched_attr+0x4e>
lea    0xec9(%rip),%r8
jmp    11dd <print_sched_attr+0x7d>
mov    0x2e0b(%rip),%rdx
cmp    (%rdx),%ecx
jne    11c2 <print_sched_attr+0x62>
lea    0xec0(%rip),%r8
jmp    11dd <print_sched_attr+0x7d>
mov    0x2e07(%rip),%rdx
cmp    (%rdx),%ecx
lea    0xeb7(%rip),%rcx
lea    0xebc(%rip),%r8
cmove  %rcx,%r8
mov    (%rsp),%r9d
lea    0xe41(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
jmp    117f <print_sched_attr+0x1f>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [41 x i8] c"Unable to retrieve pthread sched param: \00"
@.str.1 = [76 x i8] c"Scheduler attributes for [%d]:pid %d, thread %ld, policy: %s, priority: %d\0A\00"
@SYS_gettid = global i32 0
@SCHED_FIFO = global i32 0
@.str.2 = [11 x i8] c"SCHED_FIFO\00"
@SCHED_RR = global i32 0
@.str.3 = [9 x i8] c"SCHED_RR\00"
@SCHED_OTHER = global i32 0
@.str.4 = [12 x i8] c"SCHED_OTHER\00"
@.str.5 = [4 x i8] c"???\00"
define void @print_sched_attr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sched_param
store i32 %0, i32* %2
%6 = call i32 (...) @pthread_self()
%7 = call i32 @pthread_getschedparam(i32 %6, i32* %3, %struct.sched_param* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i32, i32* %2
%14 = call i32 (...) @getpid()
%15 = load i32, i32* @SYS_gettid
%16 = call i32 @syscall(i32 %15)
%17 = load i32, i32* %3
%18 = load i32, i32* @SCHED_FIFO
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %12
br label %34
21: ; preds = %12
%22 = load i32, i32* %3
%23 = load i32, i32* @SCHED_RR
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %32
26: ; preds = %21
%27 = load i32, i32* %3
%28 = load i32, i32* @SCHED_OTHER
%29 = icmp eq i32 %27, %28
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
br label %32
32: ; preds = %26, %25
%33 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %25 ], [ %31, %26 ]
br label %34
34: ; preds = %32, %20
%35 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %20 ], [ %33, %32 ]
%36 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i32 %16, i8* %35, i32 %37)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [41 x i8] c"Unable to retrieve pthread sched param: \00"
@.str.1 = [76 x i8] c"Scheduler attributes for [%d]:pid %d, thread %ld, policy: %s, priority: %d\0A\00"
@SYS_gettid = global i32 0
@SCHED_FIFO = global i32 0
@.str.2 = [11 x i8] c"SCHED_FIFO\00"
@SCHED_RR = global i32 0
@.str.3 = [9 x i8] c"SCHED_RR\00"
@SCHED_OTHER = global i32 0
@.str.4 = [12 x i8] c"SCHED_OTHER\00"
@.str.5 = [4 x i8] c"???\00"
define void @print_sched_attr(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sched_param* %3 to i8*
%6 = tail call i32 (...) @pthread_self()
%7 = call i32 @pthread_getschedparam(i32 %6, i32* %2, %struct.sched_param* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 (...) @getpid()
%13 = load i32, i32* @SYS_gettid
%14 = call i32 @syscall(i32 %13)
%15 = load i32, i32* %2
%16 = load i32, i32* @SCHED_FIFO
%17 = icmp eq i32 %15, %16
br i1 %17, label %25, label %18
18: ; preds = %11
%19 = load i32, i32* @SCHED_RR
%20 = icmp eq i32 %15, %19
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @SCHED_OTHER
%23 = icmp eq i32 %15, %22
%24 = select i1 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
br label %25
25: ; preds = %21, %18, %11
%26 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %11 ], [ %24, %21 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %18 ]
%27 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %12, i32 %14, i8* %26, i32 %28)
ret void
}