#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 /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
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);
void *a_thread_func() {
  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 != 0) {
    printf("Error at pthread_setschedparam: rc=%d\n", rc);
    exit(1);
  }
  rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam);
  if (rc != 0) {
    printf("Error at pthread_getschedparam: rc=%d\n", rc);
    exit(2);
  }
  if (policy_1 != policy || sparam.sched_priority != priority) {
    printf("pthread_getschedparam did not get the correct value\n");
    exit(1);
  }
  pthread_exit(0);
  return NULL;
}


x86 assembly (clang, -O0):
<a_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <sched_get_priority_min@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1080 <pthread_self@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
lea    -0x8(%rbp),%rdx
call   1030 <pthread_setschedparam@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11d2 <a_thread_func+0x62>
mov    -0x18(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1080 <pthread_self@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <pthread_getschedparam@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1210 <a_thread_func+0xa0>
mov    -0x18(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1228 <a_thread_func+0xb8>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1240 <a_thread_func+0xd0>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_thread_func>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <sched_get_priority_min@plt>
mov    %eax,%ebp
mov    %eax,(%rsp)
xor    %eax,%eax
call   1090 <pthread_self@plt>
mov    %rsp,%rdx
mov    %eax,%edi
mov    %ebx,%esi
call   1040 <pthread_setschedparam@plt>
test   %eax,%eax
jne    11e4 <a_thread_func+0x64>
xor    %eax,%eax
call   1090 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
call   1060 <pthread_getschedparam@plt>
test   %eax,%eax
jne    11fe <a_thread_func+0x7e>
cmp    %ebx,0x4(%rsp)
jne    1218 <a_thread_func+0x98>
cmp    %ebp,(%rsp)
jne    1218 <a_thread_func+0x98>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe15(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe22(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [39 x i8] c"Error at pthread_setschedparam: rc=%d\0A\00"
@.str.1 = [39 x i8] c"Error at pthread_getschedparam: rc=%d\0A\00"
@.str.2 = [53 x i8] c"pthread_getschedparam did not get the correct value\0A\00"
define i8* @a_thread_func() {
%1 = alloca %struct.sched_param
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @SCHED_FIFO
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @sched_get_priority_min(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
store i32 %9, i32* %10
%11 = call i32 (...) @pthread_self()
%12 = load i32, i32* %2
%13 = call i32 @pthread_setschedparam(i32 %11, i32 %12, %struct.sched_param* %1)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = load i32, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i32 (...) @pthread_self()
%22 = call i32 @pthread_getschedparam(i32 %21, i32* %4, %struct.sched_param* %1)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %20
%30 = load i32, i32* %4
%31 = load i32, i32* %2
%32 = icmp ne i32 %30, %31
br i1 %32, label %38, label %33
33: ; preds = %29
%34 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load i32, i32* %3
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %33, %29
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
%42 = call i32 @pthread_exit(i32 0)
ret i8* null
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [39 x i8] c"Error at pthread_setschedparam: rc=%d\0A\00"
@.str.1 = [39 x i8] c"Error at pthread_getschedparam: rc=%d\0A\00"
@str = [52 x i8] c"pthread_getschedparam did not get the correct value\00"
define noalias i8* @a_thread_func() {
%1 = alloca %struct.sched_param
%2 = alloca i32
%3 = bitcast %struct.sched_param* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @SCHED_FIFO
%6 = tail call i32 @sched_get_priority_min(i32 %5)
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %6, i32* %7
%8 = tail call i32 (...) @pthread_self()
%9 = call i32 @pthread_setschedparam(i32 %8, i32 %5, %struct.sched_param* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %9)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 (...) @pthread_self()
%16 = call i32 @pthread_getschedparam(i32 %15, i32* %2, %struct.sched_param* %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %14
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, %5
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, %6
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = call i32 @pthread_exit(i32 0)
ret i8* null
}