#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;
};

/* Variables and functions */
int SCHED_FIFO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int pthread_getschedparam(int /*<<< orphan*/, int *, struct sched_param *);
int /*<<< orphan*/ pthread_self();
int pthread_setschedparam(int /*<<< orphan*/, int, struct sched_param *);
int sched_get_priority_min(int);
char *strerror(int);
void *thread_func(void *arg __attribute__((unused))) {
  struct sched_param sparam;
  int policy, priority, policy_1;
  int rc;
  policy = SCHED_FIFO;
  priority = sched_get_priority_min(policy);
  sparam.sched_priority = priority;
  rc = pthread_setschedparam(pthread_self(), policy, &sparam);
  if (rc) {
    printf("Failed: func %s rc: %s (%u)\n", "pthread_setschedparam()",
           strerror(rc), rc);
    exit(2);
  }
  rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam);
  if (rc != 0) {
    printf("Failed: func %s rc: %s (%u)\n", "pthread_getschedparam()",
           strerror(rc), rc);
    exit(1);
  }
  if (policy_1 != policy) {
    printf("Failed:  policys:  %u != %u\n", policy_1, policy);
    exit(1);
  }
  if (sparam.sched_priority != priority) {
    printf("Failed:  priorities: %u != %u\n", sparam.sched_priority, priority);
    exit(1);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <sched_get_priority_min@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_setschedparam@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11e8 <thread_func+0x78>
mov    -0x20(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%ecx
lea    0xe30(%rip),%rdi
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <pthread_getschedparam@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1238 <thread_func+0xc8>
mov    -0x20(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%ecx
lea    0xde0(%rip),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1262 <thread_func+0xf2>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     128c <thread_func+0x11c>
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_func>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1060 <sched_get_priority_min@plt>
mov    %eax,%r14d
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    %ebp,%esi
call   1030 <pthread_setschedparam@plt>
test   %eax,%eax
jne    11e0 <thread_func+0x70>
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1050 <pthread_getschedparam@plt>
test   %eax,%eax
jne    120d <thread_func+0x9d>
mov    0xc(%rsp),%esi
cmp    %ebp,%esi
jne    123a <thread_func+0xca>
mov    0x8(%rsp),%esi
cmp    %r14d,%esi
jne    1245 <thread_func+0xd5>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <strerror@plt>
lea    0xe10(%rip),%rdi
lea    0xe26(%rip),%rsi
mov    %rax,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <strerror@plt>
lea    0xde3(%rip),%rdi
lea    0xe11(%rip),%rsi
mov    %rax,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe0c(%rip),%rdi
mov    %ebp,%edx
jmp    124f <thread_func+0xdf>
lea    0xe1e(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [29 x i8] c"Failed: func %s rc: %s (%u)\0A\00"
@.str.1 = [24 x i8] c"pthread_setschedparam()\00"
@.str.2 = [24 x i8] c"pthread_getschedparam()\00"
@.str.3 = [29 x i8] c"Failed: policys: %u != %u\0A\00"
@.str.4 = [31 x i8] c"Failed: priorities: %u != %u\0A\00"
define i8* @thread_func(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.sched_param
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i32, i32* @SCHED_FIFO
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i32 @sched_get_priority_min(i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %11, i32* %12
%13 = call i32 (...) @pthread_self()
%14 = load i32, i32* %4
%15 = call i32 @pthread_setschedparam(i32 %13, i32 %14, %struct.sched_param* %3)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %1
%19 = load i32, i32* %7
%20 = call i8* @strerror(i32 %19)
%21 = load i32, i32* %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
%23 = call i32 @exit(i32 2)
unreachable
24: ; preds = %1
%25 = call i32 (...) @pthread_self()
%26 = call i32 @pthread_getschedparam(i32 %25, i32* %6, %struct.sched_param* %3)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i32, i32* %7
%31 = call i8* @strerror(i32 %30)
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %24
%36 = load i32, i32* %6
%37 = load i32, i32* %4
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
%45 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
%46 = load i32, i32* %45
%47 = load i32, i32* %5
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
%51 = load i32, i32* %50
%52 = load i32, i32* %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %51, i32 %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %44
ret i8* null
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [29 x i8] c"Failed: func %s rc: %s (%u)\0A\00"
@.str.1 = [24 x i8] c"pthread_setschedparam()\00"
@.str.2 = [24 x i8] c"pthread_getschedparam()\00"
@.str.3 = [29 x i8] c"Failed: policys: %u != %u\0A\00"
@.str.4 = [31 x i8] c"Failed: priorities: %u != %u\0A\00"
define noalias i8* @thread_func(i8* nocapture readnone %0) {
%2 = alloca %struct.sched_param
%3 = alloca i32
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @SCHED_FIFO
%7 = tail call i32 @sched_get_priority_min(i32 %6)
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %7, i32* %8
%9 = tail call i32 (...) @pthread_self()
%10 = call i32 @pthread_setschedparam(i32 %9, i32 %6, %struct.sched_param* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = call i8* @strerror(i32 %10)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %10)
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %1
%17 = call i32 (...) @pthread_self()
%18 = call i32 @pthread_getschedparam(i32 %17, i32* %3, %struct.sched_param* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = call i8* @strerror(i32 %18)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %18)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, %6
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %6)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %24
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, %7
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 %7)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %30
ret i8* null
}