#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 */
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int SCHED_FIFO;
int SCHED_RR;
int /*<<< orphan*/ assert(int);
int get_thread_policy(int /*<<< orphan*/ *);
int /*<<< orphan*/ get_thread_priority(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int pthread_attr_destroy(int /*<<< orphan*/ *);
int pthread_attr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ set_thread_policy(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ show_thread_priority(int /*<<< orphan*/ *, int);
int main(void) {
  pthread_attr_t attr;
  int rs;
  rs = pthread_attr_init(&attr);
  assert(rs == 0);
  int policy = get_thread_policy(&attr);
  printf("Show current configuration of priority\n");
  get_thread_policy(&attr);
  show_thread_priority(&attr, policy);
  printf("show SCHED_FIFO of priority\n");
  show_thread_priority(&attr, SCHED_FIFO);
  printf("show SCHED_RR of priority\n");
  show_thread_priority(&attr, SCHED_RR);
  printf("show priority of current thread\n");
  get_thread_priority(&attr);
  printf("Set thread policy\n");
  printf("set SCHED_FIFO policy\n");
  set_thread_policy(&attr, SCHED_FIFO);
  get_thread_policy(&attr);
  get_thread_priority(&attr);
  printf("set SCHED_RR policy\n");
  set_thread_policy(&attr, SCHED_RR);
  get_thread_policy(&attr);
  printf("Restore current policy\n");
  set_thread_policy(&attr, policy);
  get_thread_priority(&attr);
  rs = pthread_attr_destroy(&attr);
  assert(rs == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <pthread_attr_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0x8(%rbp),%rdi
call   1080 <get_thread_policy@plt>
mov    %eax,-0x10(%rbp)
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1080 <get_thread_policy@plt>
mov    -0x10(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <show_thread_priority@plt>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <show_thread_priority@plt>
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <show_thread_priority@plt>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1060 <get_thread_priority@plt>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <set_thread_policy@plt>
lea    -0x8(%rbp),%rdi
call   1080 <get_thread_policy@plt>
lea    -0x8(%rbp),%rdi
call   1060 <get_thread_priority@plt>
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <set_thread_policy@plt>
lea    -0x8(%rbp),%rdi
call   1080 <get_thread_policy@plt>
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1050 <set_thread_policy@plt>
lea    -0x8(%rbp),%rdi
call   1060 <get_thread_priority@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_attr_destroy@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <pthread_attr_init@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1080 <get_thread_policy@plt>
mov    %eax,%ebp
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1080 <get_thread_policy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10a0 <show_thread_priority@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e0c(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   10a0 <show_thread_priority@plt>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd6(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10a0 <show_thread_priority@plt>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <get_thread_priority@plt>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <set_thread_policy@plt>
mov    %rbx,%rdi
call   1080 <get_thread_policy@plt>
mov    %rbx,%rdi
call   1060 <get_thread_priority@plt>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1050 <set_thread_policy@plt>
mov    %rbx,%rdi
call   1080 <get_thread_policy@plt>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <set_thread_policy@plt>
mov    %rbx,%rdi
call   1060 <get_thread_priority@plt>
mov    %rbx,%rdi
call   1090 <pthread_attr_destroy@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Show current configuration of priority\0A\00"
@.str.1 = [29 x i8] c"show SCHED_FIFO of priority\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [27 x i8] c"show SCHED_RR of priority\0A\00"
@SCHED_RR = global i32 0
@.str.3 = [33 x i8] c"show priority of current thread\0A\00"
@.str.4 = [19 x i8] c"Set thread policy\0A\00"
@.str.5 = [23 x i8] c"set SCHED_FIFO policy\0A\00"
@.str.6 = [21 x i8] c"set SCHED_RR policy\0A\00"
@.str.7 = [24 x i8] c"Restore current policy\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @pthread_attr_init(i32* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @get_thread_policy(i32* %2)
store i32 %10, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @get_thread_policy(i32* %2)
%13 = load i32, i32* %4
%14 = call i32 @show_thread_priority(i32* %2, i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @SCHED_FIFO
%17 = call i32 @show_thread_priority(i32* %2, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @SCHED_RR
%20 = call i32 @show_thread_priority(i32* %2, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @get_thread_priority(i32* %2)
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* @SCHED_FIFO
%26 = call i32 @set_thread_policy(i32* %2, i32 %25)
%27 = call i32 @get_thread_policy(i32* %2)
%28 = call i32 @get_thread_priority(i32* %2)
%29 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%30 = load i32, i32* @SCHED_RR
%31 = call i32 @set_thread_policy(i32* %2, i32 %30)
%32 = call i32 @get_thread_policy(i32* %2)
%33 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = call i32 @set_thread_policy(i32* %2, i32 %34)
%36 = call i32 @get_thread_priority(i32* %2)
%37 = call i32 @pthread_attr_destroy(i32* %2)
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
ret i32 0
}

LLVM IR (-O2):
@SCHED_FIFO = global i32 0
@SCHED_RR = global i32 0
@str = [39 x i8] c"Show current configuration of priority\00"
@str.8 = [28 x i8] c"show SCHED_FIFO of priority\00"
@str.9 = [26 x i8] c"show SCHED_RR of priority\00"
@str.10 = [32 x i8] c"show priority of current thread\00"
@str.11 = [18 x i8] c"Set thread policy\00"
@str.12 = [22 x i8] c"set SCHED_FIFO policy\00"
@str.13 = [20 x i8] c"set SCHED_RR policy\00"
@str.14 = [23 x i8] c"Restore current policy\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_attr_init(i32* %1)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = call i32 @get_thread_policy(i32* %1)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%9 = call i32 @get_thread_policy(i32* %1)
%10 = call i32 @show_thread_priority(i32* %1, i32 %7)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0))
%12 = load i32, i32* @SCHED_FIFO
%13 = call i32 @show_thread_priority(i32* %1, i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
%15 = load i32, i32* @SCHED_RR
%16 = call i32 @show_thread_priority(i32* %1, i32 %15)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.10, i64 0, i64 0))
%18 = call i32 @get_thread_priority(i32* %1)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.12, i64 0, i64 0))
%21 = load i32, i32* @SCHED_FIFO
%22 = call i32 @set_thread_policy(i32* %1, i32 %21)
%23 = call i32 @get_thread_policy(i32* %1)
%24 = call i32 @get_thread_priority(i32* %1)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
%26 = load i32, i32* @SCHED_RR
%27 = call i32 @set_thread_policy(i32* %1, i32 %26)
%28 = call i32 @get_thread_policy(i32* %1)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.14, i64 0, i64 0))
%30 = call i32 @set_thread_policy(i32* %1, i32 %7)
%31 = call i32 @get_thread_priority(i32* %1)
%32 = call i32 @pthread_attr_destroy(i32* %1)
%33 = icmp eq i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
ret i32 0
}