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


x86 assembly (clang, -O0):
<a_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e59(%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   1090 <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     11e2 <a_thread_func+0x62>
mov    -0x18(%rbp),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1090 <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     1220 <a_thread_func+0xa0>
mov    -0x18(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    124c <a_thread_func+0xcc>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1264 <a_thread_func+0xe4>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1090 <pthread_self@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
call   1080 <pthread_setschedprio@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     12a0 <a_thread_func+0x120>
mov    -0x18(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1090 <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     12de <a_thread_func+0x15e>
mov    -0x18(%rbp),%esi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     131b <a_thread_func+0x19b>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <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    0x2e4e(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <sched_get_priority_min@plt>
mov    %eax,%ebx
mov    %eax,(%rsp)
xor    %eax,%eax
call   10a0 <pthread_self@plt>
mov    %rsp,%rdx
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <pthread_setschedparam@plt>
test   %eax,%eax
jne    1265 <a_thread_func+0xd5>
xor    %eax,%eax
call   10a0 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
call   1060 <pthread_getschedparam@plt>
test   %eax,%eax
jne    125c <a_thread_func+0xcc>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebp,0x4(%rsp)
jne    127f <a_thread_func+0xef>
cmp    %ebx,(%rsp)
jne    127f <a_thread_func+0xef>
xor    %eax,%eax
call   10a0 <pthread_self@plt>
add    $0x1,%ebx
mov    %eax,%edi
mov    %ebx,%esi
call   1090 <pthread_setschedprio@plt>
test   %eax,%eax
jne    1295 <a_thread_func+0x105>
xor    %eax,%eax
call   10a0 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
call   1060 <pthread_getschedparam@plt>
test   %eax,%eax
jne    125c <a_thread_func+0xcc>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebx,(%rsp)
jne    12af <a_thread_func+0x11f>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdc4(%rip),%rdi
jmp    126c <a_thread_func+0xdc>
lea    0xd94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xdcc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <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 = [26 x i8] c"policy: %d, priority: %d\0A\00"
@.str.3 = [53 x i8] c"pthread_getschedparam did not get the correct value\0A\00"
@.str.4 = [38 x i8] c"Error at pthread_setschedprio: rc=%d\0A\00"
@.str.5 = [31 x i8] c"Priority is not set correctly\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 2)
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 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
%34 = load i32, i32* %4
%35 = load i32, i32* %2
%36 = icmp ne i32 %34, %35
br i1 %36, label %42, label %37
37: ; preds = %29
%38 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%39 = load i32, i32* %38
%40 = load i32, i32* %3
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %37, %29
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 2)
unreachable
45: ; preds = %37
%46 = call i32 (...) @pthread_self()
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
%49 = call i32 @pthread_setschedprio(i32 %46, i32 %48)
store i32 %49, i32* %5
%50 = load i32, i32* %5
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i32, i32* %5
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %45
%57 = call i32 (...) @pthread_self()
%58 = call i32 @pthread_getschedparam(i32 %57, i32* %4, %struct.sched_param* %1)
store i32 %58, i32* %5
%59 = load i32, i32* %5
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = load i32, i32* %5
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %62)
%64 = call i32 @exit(i32 2)
unreachable
65: ; preds = %56
%66 = load i32, i32* %4
%67 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %66, i32 %68)
%70 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load i32, i32* %3
%73 = add nsw i32 %72, 1
%74 = icmp ne i32 %71, %73
br i1 %74, label %75, label %78
75: ; preds = %65
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %65
%79 = 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.2 = [26 x i8] c"policy: %d, priority: %d\0A\00"
@.str.4 = [38 x i8] c"Error at pthread_setschedprio: rc=%d\0A\00"
@str = [30 x i8] c"Priority is not set correctly\00"
@str.6 = [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 2)
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 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, %5
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, %6
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %33, label %30
30: ; preds = %21
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.6, i64 0, i64 0))
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %21
%34 = call i32 (...) @pthread_self()
%35 = add nsw i32 %6, 1
%36 = call i32 @pthread_setschedprio(i32 %34, i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
%42 = call i32 (...) @pthread_self()
%43 = call i32 @pthread_getschedparam(i32 %42, i32* %2, %struct.sched_param* %1)
%44 = icmp eq i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%47 = call i32 @exit(i32 2)
unreachable
48: ; preds = %41
%49 = load i32, i32* %2
%50 = load i32, i32* %7
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %50)
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, %35
br i1 %53, label %57, label %54
54: ; preds = %48
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = call i32 @pthread_exit(i32 0)
ret i8* null
}