#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 /*<<< 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 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 pid %d, thread %ld, : policy: %s, priority "
         "%d\n",
         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    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
lea    -0x4(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <pthread_getschedparam@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1197 <print_sched_attr+0x37>
lea    0xe6e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11d4 <print_sched_attr+0x74>
lea    0xea6(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1222 <print_sched_attr+0xc2>
mov    -0x4(%rbp),%eax
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%eax
jne    11f6 <print_sched_attr+0x96>
lea    0xe8f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    121a <print_sched_attr+0xba>
mov    -0x4(%rbp),%edx
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rax
lea    0xe75(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8d
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_sched_attr>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%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,%ebx
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    0xc(%rsp),%ecx
mov    0x2e3d(%rip),%rdx
cmp    (%rdx),%ecx
jne    11b0 <print_sched_attr+0x50>
lea    0xec3(%rip),%rcx
jmp    11df <print_sched_attr+0x7f>
mov    0x2e09(%rip),%rdx
cmp    (%rdx),%ecx
jne    11c4 <print_sched_attr+0x64>
lea    0xeba(%rip),%rcx
jmp    11df <print_sched_attr+0x7f>
mov    0x2e05(%rip),%rdx
cmp    (%rdx),%ecx
lea    0xeb1(%rip),%rdx
lea    0xeb6(%rip),%rcx
cmove  %rdx,%rcx
mov    0x8(%rsp),%r8d
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
jmp    1181 <print_sched_attr+0x21>

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

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