#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 */
scalar_t__ EINVAL;
scalar_t__ ESRCH;
int SCHED_FIFO;
int SCHED_OTHER;
int SCHED_RR;
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sched_get_priority_max(int);
int sched_get_priority_min(int);
int sched_getscheduler(int);
int sched_setscheduler(int, int, struct sched_param *);
int /*<<< orphan*/ stdout;
int test_scheduler(void) {
  int policy;
  int err;
  struct sched_param param;
  int i;
  int max_prio;
  int min_prio;
  printf("Test sched_setscheduler() (SCHED_FIFO)...");
  min_prio = sched_get_priority_min(SCHED_FIFO);
  max_prio = sched_get_priority_max(SCHED_FIFO);
  for (i = min_prio; i <= max_prio; i++) {
    param.sched_priority = i;
    if (sched_setscheduler(getpid(), SCHED_FIFO, &param) < 0) {
      fflush(stdout);
      perror("failed");
      return -1;
    }
  }
  printf("passed\n");
  printf("Test sched_getscheduler() (SCHED_FIFO)...");
  policy = sched_getscheduler(getpid());
  if (policy < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  if (policy == SCHED_FIFO) {
    printf("passed\n");
  } else {
    printf("failed policy should be SCHED_FIFO not %d\n", policy);
    return -1;
  }
  printf("Test sched_setscheduler() (SCHED_RR)...");
  min_prio = sched_get_priority_min(SCHED_RR);
  max_prio = sched_get_priority_max(SCHED_RR);
  for (i = min_prio; i <= max_prio; i++) {
    param.sched_priority = i;
    if (sched_setscheduler(getpid(), SCHED_RR, &param) < 0) {
      fflush(stdout);
      perror("failed");
      return -1;
    }
  }
  printf("passed\n");
  printf("Test sched_getscheduler() (SCHED_RR)...");
  policy = sched_getscheduler(getpid());
  if (policy < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  if (policy == SCHED_RR) {
    printf("passed\n");
  } else {
    printf("failed policy should be SCHED_RR not %d\n", policy);
    return -1;
  }
  printf("Test sched_setscheduler() (SCHED_OTHER)...");
  min_prio = sched_get_priority_min(SCHED_OTHER);
  max_prio = sched_get_priority_max(SCHED_OTHER);
  for (i = min_prio; i <= max_prio; i++) {
    param.sched_priority = i;
    if (sched_setscheduler(getpid(), SCHED_OTHER, &param) < 0) {
      fflush(stdout);
      perror("failed");
      return -1;
    }
  }
  printf("passed\n");
  printf("Test sched_getscheduler() (SCHED_OTHER)...");
  policy = sched_getscheduler(getpid());
  if (policy < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  if (policy == SCHED_OTHER) {
    printf("passed\n");
  } else {
    printf("failed policy should be SCHED_OTHER not %d\n", policy);
    return -1;
  }
  printf("Test sched_setscheduler() (ESRCH)...");
  err = sched_setscheduler(-1, SCHED_OTHER, &param);
  if ((err == 0) || (errno != ESRCH)) {
    fflush(stdout);
    perror("should have failed with ESRCH");
    return -1;
  } else {
    errno = 0;
    printf("passed\n");
  }
  printf("Test sched_setscheduler() (EINVAL:policy)...");
  err = sched_setscheduler(getpid(), 500, &param);
  if ((err == 0) || (errno != EINVAL)) {
    fflush(stdout);
    perror("should have failed with EINVAL");
    return -1;
  } else {
    errno = 0;
    printf("passed\n");
  }
  printf("Test sched_setscheduler() (EINVAL:priority)...");
  param.sched_priority = sched_get_priority_max(SCHED_FIFO) + 1;
  err = sched_setscheduler(getpid(), SCHED_FIFO, &param);
  if ((err == 0) || (errno != EINVAL)) {
    fflush(stdout);
    perror("should have failed with EINVAL");
    return -1;
  } else {
    errno = 0;
    printf("passed\n");
  }
  printf("Test sched_setscheduler() (EINVAL:priority)...");
  param.sched_priority = sched_get_priority_max(SCHED_RR) + 1;
  err = sched_setscheduler(getpid(), SCHED_RR, &param);
  if ((err == 0) || (errno != EINVAL)) {
    fflush(stdout);
    perror("should have failed with EINVAL");
    return -1;
  } else {
    errno = 0;
    printf("passed\n");
  }
  printf("Test sched_setscheduler() (EINVAL:priority)...");
  param.sched_priority = sched_get_priority_max(SCHED_OTHER) + 1;
  err = sched_setscheduler(getpid(), SCHED_OTHER, &param);
  if ((err == 0) || (errno != EINVAL)) {
    fflush(stdout);
    perror("should have failed with EINVAL");
    return -1;
  } else {
    errno = 0;
    printf("passed\n");
  }
  printf("Test sched_getscheduler() (ESRCH)...");
  err = sched_getscheduler(-1);
  if ((err == 0) || (errno != ESRCH)) {
    fflush(stdout);
    perror("should have failed with ESRCH");
    return -1;
  } else {
    errno = 0;
    printf("passed\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_scheduler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1080 <sched_get_priority_min@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     122d <test_scheduler+0xad>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
cmp    $0x0,%eax
jge    121a <test_scheduler+0x9a>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xe21(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
jmp    121f <test_scheduler+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <test_scheduler+0x3e>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    128a <test_scheduler+0x10a>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    -0x8(%rbp),%eax
mov    0x2d54(%rip),%rcx
cmp    (%rcx),%eax
jne    12af <test_scheduler+0x12f>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cc <test_scheduler+0x14c>
mov    -0x8(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1080 <sched_get_priority_min@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1371 <test_scheduler+0x1f1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2c8c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
cmp    $0x0,%eax
jge    135e <test_scheduler+0x1de>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xcdd(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
jmp    1363 <test_scheduler+0x1e3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1302 <test_scheduler+0x182>
lea    0xcb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    13ce <test_scheduler+0x24e>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xc6d(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    -0x8(%rbp),%eax
mov    0x2bd8(%rip),%rcx
cmp    (%rcx),%eax
jne    13f3 <test_scheduler+0x273>
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1410 <test_scheduler+0x290>
mov    -0x8(%rbp),%esi
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
call   1080 <sched_get_priority_min@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     14b5 <test_scheduler+0x335>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2b70(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
cmp    $0x0,%eax
jge    14a2 <test_scheduler+0x322>
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xb99(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
jmp    14a7 <test_scheduler+0x327>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1446 <test_scheduler+0x2c6>
lea    0xb75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1512 <test_scheduler+0x392>
mov    0x2acd(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xb29(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    -0x8(%rbp),%eax
mov    0x2abc(%rip),%rcx
cmp    (%rcx),%eax
jne    1537 <test_scheduler+0x3b7>
lea    0xb06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1554 <test_scheduler+0x3d4>
mov    -0x8(%rbp),%esi
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
lea    0xc2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2a6f(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     15a0 <test_scheduler+0x420>
mov    0x2a43(%rip),%rax
mov    (%rax),%rax
mov    0x2a11(%rip),%rcx
cmp    (%rcx),%rax
je     15c6 <test_scheduler+0x446>
mov    0x2a19(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xbf9(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    0x2a03(%rip),%rax
movq   $0x0,(%rax)
lea    0xa56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbe3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    $0x1f4,%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     162e <test_scheduler+0x4ae>
mov    0x29b5(%rip),%rax
mov    (%rax),%rax
mov    0x29a3(%rip),%rcx
cmp    (%rcx),%rax
je     1654 <test_scheduler+0x4d4>
mov    0x298b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xbb6(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    0x2975(%rip),%rax
movq   $0x0,(%rax)
lea    0x9c8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xba1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2963(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2946(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     16d4 <test_scheduler+0x554>
mov    0x290f(%rip),%rax
mov    (%rax),%rax
mov    0x28fd(%rip),%rcx
cmp    (%rcx),%rax
je     16fa <test_scheduler+0x57a>
mov    0x28e5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xb10(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    0x28cf(%rip),%rax
movq   $0x0,(%rax)
lea    0x922(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xafb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2885(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2868(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     177a <test_scheduler+0x5fa>
mov    0x2869(%rip),%rax
mov    (%rax),%rax
mov    0x2857(%rip),%rcx
cmp    (%rcx),%rax
je     17a0 <test_scheduler+0x620>
mov    0x283f(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xa6a(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    0x2829(%rip),%rax
movq   $0x0,(%rax)
lea    0x87c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xa55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2807(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x27ea(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1820 <test_scheduler+0x6a0>
mov    0x27c3(%rip),%rax
mov    (%rax),%rax
mov    0x27b1(%rip),%rcx
cmp    (%rcx),%rax
je     1846 <test_scheduler+0x6c6>
mov    0x2799(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0x9c4(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    0x2783(%rip),%rax
movq   $0x0,(%rax)
lea    0x7d6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x9de(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     18a1 <test_scheduler+0x721>
mov    0x2742(%rip),%rax
mov    (%rax),%rax
mov    0x2710(%rip),%rcx
cmp    (%rcx),%rax
je     18c7 <test_scheduler+0x747>
mov    0x2718(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0x8f8(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    18ea <test_scheduler+0x76a>
mov    0x2702(%rip),%rax
movq   $0x0,(%rax)
lea    0x755(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_scheduler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e38(%rip),%r15
mov    (%r15),%edi
call   1090 <sched_get_priority_min@plt>
mov    %eax,%ebx
mov    (%r15),%edi
call   10b0 <sched_get_priority_max@plt>
cmp    %eax,%ebx
jg     11f6 <test_scheduler+0x66>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %rsp,%r14
xchg   %ax,%ax
mov    %ebx,(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r15),%esi
mov    %eax,%edi
mov    %r14,%rdx
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
js     15a7 <test_scheduler+0x417>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11d0 <test_scheduler+0x40>
lea    0x1067(%rip),%rdi
call   1040 <puts@plt>
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1030 <sched_getscheduler@plt>
test   %eax,%eax
js     15a7 <test_scheduler+0x417>
cmp    (%r15),%eax
jne    1595 <test_scheduler+0x405>
lea    0x102e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d60(%rip),%r12
mov    (%r12),%edi
call   1090 <sched_get_priority_min@plt>
mov    %eax,%ebx
mov    (%r12),%edi
call   10b0 <sched_get_priority_max@plt>
cmp    %eax,%ebx
jg     1297 <test_scheduler+0x107>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %rsp,%r14
mov    %ebx,(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r12),%esi
mov    %eax,%edi
mov    %r14,%rdx
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
js     15a7 <test_scheduler+0x417>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1270 <test_scheduler+0xe0>
lea    0xfc6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1030 <sched_getscheduler@plt>
test   %eax,%eax
js     15a7 <test_scheduler+0x417>
cmp    (%r12),%eax
jne    159e <test_scheduler+0x40e>
lea    0xf8c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe1b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2ce6(%rip),%r13
mov    0x0(%r13),%edi
call   1090 <sched_get_priority_min@plt>
mov    %eax,%ebx
mov    0x0(%r13),%edi
call   10b0 <sched_get_priority_max@plt>
cmp    %eax,%ebx
jg     1347 <test_scheduler+0x1b7>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    0x0(%r13),%esi
mov    %eax,%edi
mov    %r14,%rdx
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
js     15a7 <test_scheduler+0x417>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1320 <test_scheduler+0x190>
lea    0xf16(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1030 <sched_getscheduler@plt>
test   %eax,%eax
js     15a7 <test_scheduler+0x417>
cmp    0x0(%r13),%eax
jne    15c3 <test_scheduler+0x433>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%esi
mov    $0xffffffff,%ebx
mov    %rsp,%rdx
mov    $0xffffffff,%edi
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
je     1600 <test_scheduler+0x470>
mov    0x2c10(%rip),%rbp
mov    0x0(%rbp),%rax
mov    0x2bdd(%rip),%r14
cmp    (%r14),%rax
jne    1600 <test_scheduler+0x470>
movq   $0x0,0x0(%rbp)
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rsp,%rdx
mov    %eax,%edi
mov    $0x1f4,%esi
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
je     15e9 <test_scheduler+0x459>
mov    0x0(%rbp),%rax
mov    0x2ba9(%rip),%rbx
cmp    (%rbx),%rax
jne    15e9 <test_scheduler+0x459>
movq   $0x0,0x0(%rbp)
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%edi
call   10b0 <sched_get_priority_max@plt>
add    $0x1,%eax
mov    %eax,(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r15),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
je     15e9 <test_scheduler+0x459>
mov    0x0(%rbp),%rax
cmp    (%rbx),%rax
jne    15e9 <test_scheduler+0x459>
movq   $0x0,0x0(%rbp)
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
lea    0xd74(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%edi
call   10b0 <sched_get_priority_max@plt>
add    $0x1,%eax
mov    %eax,(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r12),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
je     15e9 <test_scheduler+0x459>
mov    0x0(%rbp),%rax
cmp    (%rbx),%rax
jne    15e9 <test_scheduler+0x459>
movq   $0x0,0x0(%rbp)
lea    0xd79(%rip),%rdi
call   1040 <puts@plt>
lea    0xd19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edi
call   10b0 <sched_get_priority_max@plt>
add    $0x1,%eax
mov    %eax,(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    0x0(%r13),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1070 <sched_setscheduler@plt>
test   %eax,%eax
je     15e9 <test_scheduler+0x459>
mov    0x0(%rbp),%rax
cmp    (%rbx),%rax
jne    15e9 <test_scheduler+0x459>
movq   $0x0,0x0(%rbp)
lea    0xd1e(%rip),%rdi
call   1040 <puts@plt>
lea    0xced(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
call   1030 <sched_getscheduler@plt>
test   %eax,%eax
je     1600 <test_scheduler+0x470>
mov    0x0(%rbp),%rax
cmp    (%r14),%rax
jne    1600 <test_scheduler+0x470>
movq   $0x0,0x0(%rbp)
lea    0xcd8(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    15d8 <test_scheduler+0x448>
lea    0xabf(%rip),%rdi
jmp    15ca <test_scheduler+0x43a>
lea    0xb31(%rip),%rdi
jmp    15ca <test_scheduler+0x43a>
mov    0x2a12(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    0xa6e(%rip),%rdi
call   10a0 <perror@plt>
jmp    15d3 <test_scheduler+0x443>
lea    0xb8b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x29d0(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    0xbf3(%rip),%rdi
jmp    15bc <test_scheduler+0x42c>
mov    0x29b9(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    0xb91(%rip),%rdi
call   10a0 <perror@plt>
jmp    15d8 <test_scheduler+0x448>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [42 x i8] c"Test sched_setscheduler() (SCHED_FIFO)...\00"
@SCHED_FIFO = global i32 0
@stdout = global i32 0
@.str.1 = [7 x i8] c"failed\00"
@.str.2 = [8 x i8] c"passed\0A\00"
@.str.3 = [42 x i8] c"Test sched_getscheduler() (SCHED_FIFO)...\00"
@.str.4 = [43 x i8] c"failed policy should be SCHED_FIFO not %d\0A\00"
@.str.5 = [40 x i8] c"Test sched_setscheduler() (SCHED_RR)...\00"
@SCHED_RR = global i32 0
@.str.6 = [40 x i8] c"Test sched_getscheduler() (SCHED_RR)...\00"
@.str.7 = [41 x i8] c"failed policy should be SCHED_RR not %d\0A\00"
@.str.8 = [43 x i8] c"Test sched_setscheduler() (SCHED_OTHER)...\00"
@SCHED_OTHER = global i32 0
@.str.9 = [43 x i8] c"Test sched_getscheduler() (SCHED_OTHER)...\00"
@.str.10 = [44 x i8] c"failed policy should be SCHED_OTHER not %d\0A\00"
@.str.11 = [37 x i8] c"Test sched_setscheduler() (ESRCH)...\00"
@errno = global i64 0
@ESRCH = global i64 0
@.str.12 = [30 x i8] c"should have failed with ESRCH\00"
@.str.13 = [45 x i8] c"Test sched_setscheduler() (EINVAL:policy)...\00"
@EINVAL = global i64 0
@.str.14 = [31 x i8] c"should have failed with EINVAL\00"
@.str.15 = [47 x i8] c"Test sched_setscheduler() (EINVAL:priority)...\00"
@.str.16 = [37 x i8] c"Test sched_getscheduler() (ESRCH)...\00"
define i32 @test_scheduler() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sched_param
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @SCHED_FIFO
%10 = call i32 @sched_get_priority_min(i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* @SCHED_FIFO
%12 = call i32 @sched_get_priority_max(i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %7
store i32 %13, i32* %5
br label %14
14: ; preds = %30, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i32, i32* %5
%20 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %19, i32* %20
%21 = call i32 (...) @getpid()
%22 = load i32, i32* @SCHED_FIFO
%23 = call i32 @sched_setscheduler(i32 %21, i32 %22, %struct.sched_param* %4)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
29: ; preds = %18
br label %30
30: ; preds = %29
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %14
33: ; preds = %14
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 (...) @getpid()
%37 = call i32 @sched_getscheduler(i32 %36)
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load i32, i32* @stdout
%42 = call i32 @fflush(i32 %41)
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
44: ; preds = %33
%45 = load i32, i32* %2
%46 = load i32, i32* @SCHED_FIFO
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %53
50: ; preds = %44
%51 = load i32, i32* %2
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %51)
store i32 -1, i32* %1
br label %256
53: ; preds = %48
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* @SCHED_RR
%56 = call i32 @sched_get_priority_min(i32 %55)
store i32 %56, i32* %7
%57 = load i32, i32* @SCHED_RR
%58 = call i32 @sched_get_priority_max(i32 %57)
store i32 %58, i32* %6
%59 = load i32, i32* %7
store i32 %59, i32* %5
br label %60
60: ; preds = %76, %53
%61 = load i32, i32* %5
%62 = load i32, i32* %6
%63 = icmp sle i32 %61, %62
br i1 %63, label %64, label %79
64: ; preds = %60
%65 = load i32, i32* %5
%66 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %65, i32* %66
%67 = call i32 (...) @getpid()
%68 = load i32, i32* @SCHED_RR
%69 = call i32 @sched_setscheduler(i32 %67, i32 %68, %struct.sched_param* %4)
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %64
%72 = load i32, i32* @stdout
%73 = call i32 @fflush(i32 %72)
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
75: ; preds = %64
br label %76
76: ; preds = %75
%77 = load i32, i32* %5
%78 = add nsw i32 %77, 1
store i32 %78, i32* %5
br label %60
79: ; preds = %60
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%82 = call i32 (...) @getpid()
%83 = call i32 @sched_getscheduler(i32 %82)
store i32 %83, i32* %2
%84 = load i32, i32* %2
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %90
86: ; preds = %79
%87 = load i32, i32* @stdout
%88 = call i32 @fflush(i32 %87)
%89 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
90: ; preds = %79
%91 = load i32, i32* %2
%92 = load i32, i32* @SCHED_RR
%93 = icmp eq i32 %91, %92
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %99
96: ; preds = %90
%97 = load i32, i32* %2
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %97)
store i32 -1, i32* %1
br label %256
99: ; preds = %94
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%101 = load i32, i32* @SCHED_OTHER
%102 = call i32 @sched_get_priority_min(i32 %101)
store i32 %102, i32* %7
%103 = load i32, i32* @SCHED_OTHER
%104 = call i32 @sched_get_priority_max(i32 %103)
store i32 %104, i32* %6
%105 = load i32, i32* %7
store i32 %105, i32* %5
br label %106
106: ; preds = %122, %99
%107 = load i32, i32* %5
%108 = load i32, i32* %6
%109 = icmp sle i32 %107, %108
br i1 %109, label %110, label %125
110: ; preds = %106
%111 = load i32, i32* %5
%112 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %111, i32* %112
%113 = call i32 (...) @getpid()
%114 = load i32, i32* @SCHED_OTHER
%115 = call i32 @sched_setscheduler(i32 %113, i32 %114, %struct.sched_param* %4)
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %121
117: ; preds = %110
%118 = load i32, i32* @stdout
%119 = call i32 @fflush(i32 %118)
%120 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
121: ; preds = %110
br label %122
122: ; preds = %121
%123 = load i32, i32* %5
%124 = add nsw i32 %123, 1
store i32 %124, i32* %5
br label %106
125: ; preds = %106
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
%128 = call i32 (...) @getpid()
%129 = call i32 @sched_getscheduler(i32 %128)
store i32 %129, i32* %2
%130 = load i32, i32* %2
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %136
132: ; preds = %125
%133 = load i32, i32* @stdout
%134 = call i32 @fflush(i32 %133)
%135 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
136: ; preds = %125
%137 = load i32, i32* %2
%138 = load i32, i32* @SCHED_OTHER
%139 = icmp eq i32 %137, %138
br i1 %139, label %140, label %142
140: ; preds = %136
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %145
142: ; preds = %136
%143 = load i32, i32* %2
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0), i32 %143)
store i32 -1, i32* %1
br label %256
145: ; preds = %140
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
%147 = load i32, i32* @SCHED_OTHER
%148 = call i32 @sched_setscheduler(i32 -1, i32 %147, %struct.sched_param* %4)
store i32 %148, i32* %3
%149 = load i32, i32* %3
%150 = icmp eq i32 %149, 0
br i1 %150, label %155, label %151
151: ; preds = %145
%152 = load i64, i64* @errno
%153 = load i64, i64* @ESRCH
%154 = icmp ne i64 %152, %153
br i1 %154, label %155, label %159
155: ; preds = %151, %145
%156 = load i32, i32* @stdout
%157 = call i32 @fflush(i32 %156)
%158 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
159: ; preds = %151
store i64 0, i64* @errno
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %161
161: ; preds = %159
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0))
%163 = call i32 (...) @getpid()
%164 = call i32 @sched_setscheduler(i32 %163, i32 500, %struct.sched_param* %4)
store i32 %164, i32* %3
%165 = load i32, i32* %3
%166 = icmp eq i32 %165, 0
br i1 %166, label %171, label %167
167: ; preds = %161
%168 = load i64, i64* @errno
%169 = load i64, i64* @EINVAL
%170 = icmp ne i64 %168, %169
br i1 %170, label %171, label %175
171: ; preds = %167, %161
%172 = load i32, i32* @stdout
%173 = call i32 @fflush(i32 %172)
%174 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
175: ; preds = %167
store i64 0, i64* @errno
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %177
177: ; preds = %175
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%179 = load i32, i32* @SCHED_FIFO
%180 = call i32 @sched_get_priority_max(i32 %179)
%181 = add nsw i32 %180, 1
%182 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %181, i32* %182
%183 = call i32 (...) @getpid()
%184 = load i32, i32* @SCHED_FIFO
%185 = call i32 @sched_setscheduler(i32 %183, i32 %184, %struct.sched_param* %4)
store i32 %185, i32* %3
%186 = load i32, i32* %3
%187 = icmp eq i32 %186, 0
br i1 %187, label %192, label %188
188: ; preds = %177
%189 = load i64, i64* @errno
%190 = load i64, i64* @EINVAL
%191 = icmp ne i64 %189, %190
br i1 %191, label %192, label %196
192: ; preds = %188, %177
%193 = load i32, i32* @stdout
%194 = call i32 @fflush(i32 %193)
%195 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
196: ; preds = %188
store i64 0, i64* @errno
%197 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %198
198: ; preds = %196
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%200 = load i32, i32* @SCHED_RR
%201 = call i32 @sched_get_priority_max(i32 %200)
%202 = add nsw i32 %201, 1
%203 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %202, i32* %203
%204 = call i32 (...) @getpid()
%205 = load i32, i32* @SCHED_RR
%206 = call i32 @sched_setscheduler(i32 %204, i32 %205, %struct.sched_param* %4)
store i32 %206, i32* %3
%207 = load i32, i32* %3
%208 = icmp eq i32 %207, 0
br i1 %208, label %213, label %209
209: ; preds = %198
%210 = load i64, i64* @errno
%211 = load i64, i64* @EINVAL
%212 = icmp ne i64 %210, %211
br i1 %212, label %213, label %217
213: ; preds = %209, %198
%214 = load i32, i32* @stdout
%215 = call i32 @fflush(i32 %214)
%216 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
217: ; preds = %209
store i64 0, i64* @errno
%218 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %219
219: ; preds = %217
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%221 = load i32, i32* @SCHED_OTHER
%222 = call i32 @sched_get_priority_max(i32 %221)
%223 = add nsw i32 %222, 1
%224 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %223, i32* %224
%225 = call i32 (...) @getpid()
%226 = load i32, i32* @SCHED_OTHER
%227 = call i32 @sched_setscheduler(i32 %225, i32 %226, %struct.sched_param* %4)
store i32 %227, i32* %3
%228 = load i32, i32* %3
%229 = icmp eq i32 %228, 0
br i1 %229, label %234, label %230
230: ; preds = %219
%231 = load i64, i64* @errno
%232 = load i64, i64* @EINVAL
%233 = icmp ne i64 %231, %232
br i1 %233, label %234, label %238
234: ; preds = %230, %219
%235 = load i32, i32* @stdout
%236 = call i32 @fflush(i32 %235)
%237 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
238: ; preds = %230
store i64 0, i64* @errno
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %240
240: ; preds = %238
%241 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.16, i64 0, i64 0))
%242 = call i32 @sched_getscheduler(i32 -1)
store i32 %242, i32* %3
%243 = load i32, i32* %3
%244 = icmp eq i32 %243, 0
br i1 %244, label %249, label %245
245: ; preds = %240
%246 = load i64, i64* @errno
%247 = load i64, i64* @ESRCH
%248 = icmp ne i64 %246, %247
br i1 %248, label %249, label %253
249: ; preds = %245, %240
%250 = load i32, i32* @stdout
%251 = call i32 @fflush(i32 %250)
%252 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
store i32 -1, i32* %1
br label %256
253: ; preds = %245
store i64 0, i64* @errno
%254 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %255
255: ; preds = %253
store i32 0, i32* %1
br label %256
256: ; preds = %255, %249, %234, %213, %192, %171, %155, %142, %132, %117, %96, %86, %71, %50, %40, %25
%257 = load i32, i32* %1
ret i32 %257
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [42 x i8] c"Test sched_setscheduler() (SCHED_FIFO)...\00"
@SCHED_FIFO = global i32 0
@stdout = global i32 0
@.str.1 = [7 x i8] c"failed\00"
@.str.3 = [42 x i8] c"Test sched_getscheduler() (SCHED_FIFO)...\00"
@.str.4 = [43 x i8] c"failed policy should be SCHED_FIFO not %d\0A\00"
@.str.5 = [40 x i8] c"Test sched_setscheduler() (SCHED_RR)...\00"
@SCHED_RR = global i32 0
@.str.6 = [40 x i8] c"Test sched_getscheduler() (SCHED_RR)...\00"
@.str.7 = [41 x i8] c"failed policy should be SCHED_RR not %d\0A\00"
@.str.8 = [43 x i8] c"Test sched_setscheduler() (SCHED_OTHER)...\00"
@SCHED_OTHER = global i32 0
@.str.9 = [43 x i8] c"Test sched_getscheduler() (SCHED_OTHER)...\00"
@.str.10 = [44 x i8] c"failed policy should be SCHED_OTHER not %d\0A\00"
@.str.11 = [37 x i8] c"Test sched_setscheduler() (ESRCH)...\00"
@errno = global i64 0
@ESRCH = global i64 0
@.str.12 = [30 x i8] c"should have failed with ESRCH\00"
@.str.13 = [45 x i8] c"Test sched_setscheduler() (EINVAL:policy)...\00"
@EINVAL = global i64 0
@.str.14 = [31 x i8] c"should have failed with EINVAL\00"
@.str.15 = [47 x i8] c"Test sched_setscheduler() (EINVAL:priority)...\00"
@.str.16 = [37 x i8] c"Test sched_getscheduler() (ESRCH)...\00"
@str.27 = [7 x i8] c"passed\00"
define i32 @test_scheduler() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SCHED_FIFO
%5 = tail call i32 @sched_get_priority_min(i32 %4)
%6 = load i32, i32* @SCHED_FIFO
%7 = tail call i32 @sched_get_priority_max(i32 %6)
%8 = icmp sgt i32 %5, %7
br i1 %8, label %24, label %9
9: ; preds = %0
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
br label %14
11: ; preds = %14
%12 = add i32 %15, 1
%13 = icmp eq i32 %15, %7
br i1 %13, label %24, label %14
14: ; preds = %9, %11
%15 = phi i32 [ %5, %9 ], [ %12, %11 ]
store i32 %15, i32* %10
%16 = call i32 (...) @getpid()
%17 = load i32, i32* @SCHED_FIFO
%18 = call i32 @sched_setscheduler(i32 %16, i32 %17, %struct.sched_param* %1)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %11
20: ; preds = %14
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %213
24: ; preds = %11, %0
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (...) @getpid()
%28 = call i32 @sched_getscheduler(i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %213
34: ; preds = %24
%35 = load i32, i32* @SCHED_FIFO
%36 = icmp eq i32 %28, %35
br i1 %36, label %37, label %47
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @SCHED_RR
%41 = call i32 @sched_get_priority_min(i32 %40)
%42 = load i32, i32* @SCHED_RR
%43 = call i32 @sched_get_priority_max(i32 %42)
%44 = icmp sgt i32 %41, %43
br i1 %44, label %62, label %45
45: ; preds = %37
%46 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
br label %52
47: ; preds = %34
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %213
49: ; preds = %52
%50 = add i32 %53, 1
%51 = icmp eq i32 %53, %43
br i1 %51, label %62, label %52
52: ; preds = %45, %49
%53 = phi i32 [ %41, %45 ], [ %50, %49 ]
store i32 %53, i32* %46
%54 = call i32 (...) @getpid()
%55 = load i32, i32* @SCHED_RR
%56 = call i32 @sched_setscheduler(i32 %54, i32 %55, %struct.sched_param* %1)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %49
58: ; preds = %52
%59 = load i32, i32* @stdout
%60 = call i32 @fflush(i32 %59)
%61 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %213
62: ; preds = %49, %37
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%65 = call i32 (...) @getpid()
%66 = call i32 @sched_getscheduler(i32 %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %62
%69 = load i32, i32* @stdout
%70 = call i32 @fflush(i32 %69)
%71 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %213
72: ; preds = %62
%73 = load i32, i32* @SCHED_RR
%74 = icmp eq i32 %66, %73
br i1 %74, label %75, label %85
75: ; preds = %72
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%78 = load i32, i32* @SCHED_OTHER
%79 = call i32 @sched_get_priority_min(i32 %78)
%80 = load i32, i32* @SCHED_OTHER
%81 = call i32 @sched_get_priority_max(i32 %80)
%82 = icmp sgt i32 %79, %81
br i1 %82, label %100, label %83
83: ; preds = %75
%84 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
br label %90
85: ; preds = %72
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %66)
br label %213
87: ; preds = %90
%88 = add i32 %91, 1
%89 = icmp eq i32 %91, %81
br i1 %89, label %100, label %90
90: ; preds = %83, %87
%91 = phi i32 [ %79, %83 ], [ %88, %87 ]
store i32 %91, i32* %84
%92 = call i32 (...) @getpid()
%93 = load i32, i32* @SCHED_OTHER
%94 = call i32 @sched_setscheduler(i32 %92, i32 %93, %struct.sched_param* %1)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %87
96: ; preds = %90
%97 = load i32, i32* @stdout
%98 = call i32 @fflush(i32 %97)
%99 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %213
100: ; preds = %87, %75
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
%103 = call i32 (...) @getpid()
%104 = call i32 @sched_getscheduler(i32 %103)
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %110
106: ; preds = %100
%107 = load i32, i32* @stdout
%108 = call i32 @fflush(i32 %107)
%109 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %213
110: ; preds = %100
%111 = load i32, i32* @SCHED_OTHER
%112 = icmp eq i32 %104, %111
br i1 %112, label %113, label %119
113: ; preds = %110
%114 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
%116 = load i32, i32* @SCHED_OTHER
%117 = call i32 @sched_setscheduler(i32 -1, i32 %116, %struct.sched_param* %1)
%118 = icmp eq i32 %117, 0
br i1 %118, label %125, label %121
119: ; preds = %110
%120 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0), i32 %104)
br label %213
121: ; preds = %113
%122 = load i64, i64* @errno
%123 = load i64, i64* @ESRCH
%124 = icmp eq i64 %122, %123
br i1 %124, label %129, label %125
125: ; preds = %121, %113
%126 = load i32, i32* @stdout
%127 = call i32 @fflush(i32 %126)
%128 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
br label %213
129: ; preds = %121
store i64 0, i64* @errno
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0))
%132 = call i32 (...) @getpid()
%133 = call i32 @sched_setscheduler(i32 %132, i32 500, %struct.sched_param* %1)
%134 = icmp eq i32 %133, 0
br i1 %134, label %139, label %135
135: ; preds = %129
%136 = load i64, i64* @errno
%137 = load i64, i64* @EINVAL
%138 = icmp eq i64 %136, %137
br i1 %138, label %143, label %139
139: ; preds = %135, %129
%140 = load i32, i32* @stdout
%141 = call i32 @fflush(i32 %140)
%142 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
br label %213
143: ; preds = %135
store i64 0, i64* @errno
%144 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%145 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%146 = load i32, i32* @SCHED_FIFO
%147 = call i32 @sched_get_priority_max(i32 %146)
%148 = add nsw i32 %147, 1
%149 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %148, i32* %149
%150 = call i32 (...) @getpid()
%151 = load i32, i32* @SCHED_FIFO
%152 = call i32 @sched_setscheduler(i32 %150, i32 %151, %struct.sched_param* %1)
%153 = icmp eq i32 %152, 0
br i1 %153, label %158, label %154
154: ; preds = %143
%155 = load i64, i64* @errno
%156 = load i64, i64* @EINVAL
%157 = icmp eq i64 %155, %156
br i1 %157, label %162, label %158
158: ; preds = %154, %143
%159 = load i32, i32* @stdout
%160 = call i32 @fflush(i32 %159)
%161 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
br label %213
162: ; preds = %154
store i64 0, i64* @errno
%163 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%164 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%165 = load i32, i32* @SCHED_RR
%166 = call i32 @sched_get_priority_max(i32 %165)
%167 = add nsw i32 %166, 1
store i32 %167, i32* %149
%168 = call i32 (...) @getpid()
%169 = load i32, i32* @SCHED_RR
%170 = call i32 @sched_setscheduler(i32 %168, i32 %169, %struct.sched_param* %1)
%171 = icmp eq i32 %170, 0
br i1 %171, label %176, label %172
172: ; preds = %162
%173 = load i64, i64* @errno
%174 = load i64, i64* @EINVAL
%175 = icmp eq i64 %173, %174
br i1 %175, label %180, label %176
176: ; preds = %172, %162
%177 = load i32, i32* @stdout
%178 = call i32 @fflush(i32 %177)
%179 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
br label %213
180: ; preds = %172
store i64 0, i64* @errno
%181 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%182 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%183 = load i32, i32* @SCHED_OTHER
%184 = call i32 @sched_get_priority_max(i32 %183)
%185 = add nsw i32 %184, 1
store i32 %185, i32* %149
%186 = call i32 (...) @getpid()
%187 = load i32, i32* @SCHED_OTHER
%188 = call i32 @sched_setscheduler(i32 %186, i32 %187, %struct.sched_param* %1)
%189 = icmp eq i32 %188, 0
br i1 %189, label %194, label %190
190: ; preds = %180
%191 = load i64, i64* @errno
%192 = load i64, i64* @EINVAL
%193 = icmp eq i64 %191, %192
br i1 %193, label %198, label %194
194: ; preds = %190, %180
%195 = load i32, i32* @stdout
%196 = call i32 @fflush(i32 %195)
%197 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
br label %213
198: ; preds = %190
store i64 0, i64* @errno
%199 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%200 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.16, i64 0, i64 0))
%201 = call i32 @sched_getscheduler(i32 -1)
%202 = icmp eq i32 %201, 0
br i1 %202, label %207, label %203
203: ; preds = %198
%204 = load i64, i64* @errno
%205 = load i64, i64* @ESRCH
%206 = icmp eq i64 %204, %205
br i1 %206, label %211, label %207
207: ; preds = %203, %198
%208 = load i32, i32* @stdout
%209 = call i32 @fflush(i32 %208)
%210 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
br label %213
211: ; preds = %203
store i64 0, i64* @errno
%212 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
br label %213
213: ; preds = %211, %207, %194, %176, %158, %139, %125, %119, %106, %96, %85, %68, %58, %47, %30, %20
%214 = phi i32 [ -1, %20 ], [ -1, %30 ], [ -1, %58 ], [ -1, %68 ], [ -1, %96 ], [ -1, %106 ], [ -1, %125 ], [ -1, %139 ], [ -1, %158 ], [ -1, %176 ], [ -1, %194 ], [ -1, %207 ], [ 0, %211 ], [ -1, %119 ], [ -1, %85 ], [ -1, %47 ]
ret i32 %214
}