#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_RR;
int /*<<< orphan*/ error(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ info(char *, char *, char *, int /*<<< orphan*/);
int pthread_getschedparam(int /*<<< orphan*/, int *, struct sched_param *);
int /*<<< orphan*/ pthread_self();
void report_threadinfo(char *name) {
  int status;
  struct sched_param thread_param;
  int thread_policy;
  status = pthread_getschedparam(pthread_self(), &thread_policy, &thread_param);
  if (status) {
    error("report_threadinfo: failed to get scheduler param: 0x%x\n", status);
    exit(1);
  }
  info("%s: running as %s thread at priority %d\n", name,
       thread_policy == SCHED_FIFO ? "FIFO"
       : thread_policy == SCHED_RR ? "RR"
                                   : "OTHER",
       thread_param.sched_priority);
}


x86 assembly (clang, -O0):
<report_threadinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_getschedparam@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1198 <report_threadinfo+0x48>
mov    -0xc(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1040 <error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
jne    11c2 <report_threadinfo+0x72>
lea    0xea8(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11e6 <report_threadinfo+0x96>
mov    -0x14(%rbp),%edx
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rax
lea    0xe8a(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe40(%rip),%rdi
call   1070 <info@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<report_threadinfo>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1030 <pthread_getschedparam@plt>
test   %eax,%eax
jne    11c0 <report_threadinfo+0x70>
mov    0xc(%rsp),%eax
mov    0x2e69(%rip),%rcx
mov    0x2e4a(%rip),%rdx
cmp    (%rdx),%eax
lea    0xed7(%rip),%rdx
lea    0xed3(%rip),%rsi
cmove  %rdx,%rsi
cmp    (%rcx),%eax
lea    0xebe(%rip),%rdx
cmovne %rsi,%rdx
mov    0x8(%rsp),%ecx
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
call   1070 <info@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe39(%rip),%rdi
mov    %eax,%esi
call   1040 <error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [56 x i8] c"report_threadinfo: failed to get scheduler param: 0x%x\0A\00"
@.str.1 = [41 x i8] c"%s: running as %s thread at priority %d\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [5 x i8] c"FIFO\00"
@SCHED_RR = global i32 0
@.str.3 = [3 x i8] c"RR\00"
@.str.4 = [6 x i8] c"OTHER\00"
define void @report_threadinfo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sched_param
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 (...) @pthread_self()
%7 = call i32 @pthread_getschedparam(i32 %6, i32* %5, %struct.sched_param* %4)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32 @error(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = load i32, i32* %5
%17 = load i32, i32* @SCHED_FIFO
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %14
br label %26
20: ; preds = %14
%21 = load i32, i32* %5
%22 = load i32, i32* @SCHED_RR
%23 = icmp eq i32 %21, %22
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
br label %26
26: ; preds = %20, %19
%27 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %19 ], [ %25, %20 ]
%28 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @info(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %27, i32 %29)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [56 x i8] c"report_threadinfo: failed to get scheduler param: 0x%x\0A\00"
@.str.1 = [41 x i8] c"%s: running as %s thread at priority %d\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [5 x i8] c"FIFO\00"
@SCHED_RR = global i32 0
@.str.3 = [3 x i8] c"RR\00"
@.str.4 = [6 x i8] c"OTHER\00"
define void @report_threadinfo(i8* %0) {
%2 = alloca %struct.sched_param
%3 = alloca i32
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 (...) @pthread_self()
%7 = call i32 @pthread_getschedparam(i32 %6, i32* %3, %struct.sched_param* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32 @error(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %7)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i32, i32* @SCHED_FIFO
%15 = icmp eq i32 %13, %14
%16 = load i32, i32* @SCHED_RR
%17 = icmp eq i32 %13, %16
%18 = select i1 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%19 = select i1 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %18
%20 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @info(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %19, i32 %21)
ret void
}