#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 */

/* Variables and functions */
unsigned int _add_thread(unsigned int);
int _create_joinable();
int /*<<< orphan*/ _decode_sched_status(unsigned int);
unsigned int _get_highest_priority();
unsigned int _get_schedparam(unsigned int);
unsigned int _read_sched_status(unsigned int);
int /*<<< orphan*/ _reset_hardware();
unsigned int _set_schedparam(unsigned int, unsigned int);
int /*<<< orphan*/ xil_printf(char *, ...);
int main() {
  {
    _reset_hardware();
    unsigned int tid, sta, pr, dbg;
    int count = 0;
    volatile unsigned int *addr = 0;
    for (count = 0; count < 5; count++) {
      xil_printf("***********************\r\n");
      addr = (unsigned int *)(0xB0001000) + count * 4;
      *addr = 0xCAFEBABE;
      tid = (((_create_joinable()) >> 1) & 0x000000FF);
      sta = _set_schedparam(tid, (unsigned int)addr);
      xil_printf("\tSET PR status = 0x%08x\r\n", sta);
      pr = _get_schedparam(tid);
      sta = _add_thread(tid);
      dbg = _get_highest_priority();
      xil_printf("DEBUG = 0x%08x\r\n", dbg);
      xil_printf("Create - TID = 0x%08x, PR = 0x%08x (STA = 0x%08x)\r\n", tid,
                 pr, sta);
      xil_printf("\t *ADDR = 0x%08x\r\n", *addr);
      sta = _read_sched_status(tid);
      _decode_sched_status(sta);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10b0 <_reset_hardware@plt>
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    12a8 <main+0x118>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1070 <xil_printf@plt>
mov    -0x18(%rbp),%eax
shl    $0x2,%eax
movslq %eax,%rcx
mov    $0xb0001000,%eax
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0xcafebabe,(%rax)
mov    $0x0,%al
call   1050 <_create_joinable@plt>
sar    $0x1,%eax
and    $0xff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
call   10a0 <_set_schedparam@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1070 <xil_printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <_get_schedparam@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <_add_thread@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <_get_highest_priority@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1070 <xil_printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1070 <xil_printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1070 <xil_printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <_read_sched_status@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <_decode_sched_status@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bc <main+0x2c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xb0001000,%r12d
xor    %eax,%eax
call   10b0 <_reset_hardware@plt>
lea    0xeca(%rip),%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1070 <xil_printf@plt>
movl   $0xcafebabe,(%r12,%r13,1)
ca
xor    %eax,%eax
call   1050 <_create_joinable@plt>
shr    %eax
movzbl %al,%ebp
lea    (%r12,%r13,1),%esi
mov    %ebp,%edi
call   10a0 <_set_schedparam@plt>
lea    0xe26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <xil_printf@plt>
mov    %ebp,%edi
call   1080 <_get_schedparam@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1040 <_add_thread@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1060 <_get_highest_priority@plt>
lea    0xe15(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <xil_printf@plt>
lea    0xe16(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <xil_printf@plt>
mov    (%r12,%r13,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <xil_printf@plt>
mov    %ebp,%edi
call   1090 <_read_sched_status@plt>
mov    %eax,%edi
call   1030 <_decode_sched_status@plt>
add    $0x10,%r13
cmp    $0x50,%r13
jne    11c0 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"***********************\0D\0A\00"
@.str.1 = [26 x i8] c"\09SET PR status = 0x%08x\0D\0A\00"
@.str.2 = [17 x i8] c"DEBUG = 0x%08x\0D\0A\00"
@.str.3 = [52 x i8] c"Create - TID = 0x%08x, PR = 0x%08x (STA = 0x%08x)\0D\0A\00"
@.str.4 = [19 x i8] c"\09 *ADDR = 0x%08x\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32 (...) @_reset_hardware()
store i32 0, i32* %6
store i32* null, i32** %7
store i32 0, i32* %6
br label %9
9: ; preds = %46, %0
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %49
12: ; preds = %9
%13 = call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %6
%15 = mul nsw i32 %14, 4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* inttoptr (i64 2952794112 to i32*), i64 %16
store i32* %17, i32** %7
%18 = load i32*, i32** %7
store volatile i32 -889275714, i32* %18
%19 = call i32 (...) @_create_joinable()
%20 = ashr i32 %19, 1
%21 = and i32 %20, 255
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = load i32*, i32** %7
%24 = ptrtoint i32* %23 to i32
%25 = call i32 @_set_schedparam(i32 %22, i32 %24)
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %2
%29 = call i32 @_get_schedparam(i32 %28)
store i32 %29, i32* %4
%30 = load i32, i32* %2
%31 = call i32 @_add_thread(i32 %30)
store i32 %31, i32* %3
%32 = call i32 (...) @_get_highest_priority()
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %2
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36, i32 %37)
%39 = load i32*, i32** %7
%40 = load volatile i32, i32* %39
%41 = call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %2
%43 = call i32 @_read_sched_status(i32 %42)
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = call i32 @_decode_sched_status(i32 %44)
br label %46
46: ; preds = %12
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %9
49: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"***********************\0D\0A\00"
@.str.1 = [26 x i8] c"\09SET PR status = 0x%08x\0D\0A\00"
@.str.2 = [17 x i8] c"DEBUG = 0x%08x\0D\0A\00"
@.str.3 = [52 x i8] c"Create - TID = 0x%08x, PR = 0x%08x (STA = 0x%08x)\0D\0A\00"
@.str.4 = [19 x i8] c"\09 *ADDR = 0x%08x\0D\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @_reset_hardware()
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %23, %2 ]
%4 = tail call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = shl nuw nsw i64 %3, 2
%6 = getelementptr inbounds i32, i32* inttoptr (i64 2952794112 to i32*), i64 %5
store volatile i32 -889275714, i32* %6
%7 = tail call i32 (...) @_create_joinable()
%8 = lshr i32 %7, 1
%9 = and i32 %8, 255
%10 = ptrtoint i32* %6 to i64
%11 = trunc i64 %10 to i32
%12 = tail call i32 @_set_schedparam(i32 %9, i32 %11)
%13 = tail call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @_get_schedparam(i32 %9)
%15 = tail call i32 @_add_thread(i32 %9)
%16 = tail call i32 (...) @_get_highest_priority()
%17 = tail call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = tail call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %14, i32 %15)
%19 = load volatile i32, i32* %6
%20 = tail call i32 (i8*, ...) @xil_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = tail call i32 @_read_sched_status(i32 %9)
%22 = tail call i32 @_decode_sched_status(i32 %21)
%23 = add nuw nsw i64 %3, 1
%24 = icmp eq i64 %23, 5
br i1 %24, label %25, label %2
25: ; preds = %2
ret i32 0
}