#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 timespec {
  int tv_sec;
  int tv_nsec;
};
struct sched_param {
  int /*<<< orphan*/ sched_priority;
};

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
int errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sched_get_priority_min(int /*<<< orphan*/);
int sched_rr_get_interval(int /*<<< orphan*/, struct timespec *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
char *strerror(int);
int main(void) {
  struct timespec interval;
  int result = -2;
  struct sched_param param;
  param.sched_priority = sched_get_priority_min(SCHED_RR);
  if (sched_setscheduler(0, SCHED_RR, &param) == -1) {
    printf("sched_setscheduler failed: %d (%s)\n", errno, strerror(errno));
    return 2;
  }
  interval.tv_sec = -1;
  interval.tv_nsec = -1;
  result = sched_rr_get_interval(0, &interval);
  if (result == 0 && interval.tv_sec >= 0 && interval.tv_nsec >= 0 &&
      errno == 0) {
    printf("Test PASSED\n");
    return 0;
  }
  if (interval.tv_sec == -1) {
    printf("interval.tv_sec  not updated.\n");
    return 1;
  }
  if (interval.tv_nsec == -1) {
    printf("interval.tv_nsec  not updated.\n");
    return 1;
  }
  if (result != 0) {
    printf("Returned code != 0.\n");
    return 1;
  }
  if (errno != 0) {
    perror("Unexpected error");
    return 1;
  } else {
    perror("Unresolved test error");
    return 2;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xfffffffe,-0x14(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_min@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x7e>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12e9 <main+0x189>
movl   $0xffffffff,-0x10(%rbp)
movl   $0xffffffff,-0xc(%rbp)
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1060 <sched_rr_get_interval@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1242 <main+0xe2>
cmpl   $0x0,-0x10(%rbp)
jl     1242 <main+0xe2>
cmpl   $0x0,-0xc(%rbp)
jl     1242 <main+0xe2>
mov    0x2dc1(%rip),%rax
cmpl   $0x0,(%rax)
jne    1242 <main+0xe2>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <main+0x189>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1266 <main+0x106>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e9 <main+0x189>
cmpl   $0xffffffff,-0xc(%rbp)
jne    128a <main+0x12a>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e9 <main+0x189>
cmpl   $0x0,-0x14(%rbp)
je     12ae <main+0x14e>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e9 <main+0x189>
mov    0x2d2b(%rip),%rax
cmpl   $0x0,(%rax)
je     12d6 <main+0x176>
lea    0xdc0(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e9 <main+0x189>
lea    0xdb9(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e54(%rip),%rbx
mov    (%rbx),%edi
call   1060 <sched_get_priority_min@plt>
mov    %eax,(%rsp)
mov    (%rbx),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1050 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     11dd <main+0x6d>
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1070 <sched_rr_get_interval@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x2e25(%rip),%rcx
mov    (%rcx),%ecx
test   %eax,%eax
jne    1207 <main+0x97>
test   %esi,%esi
js     1207 <main+0x97>
test   %edx,%edx
js     1207 <main+0x97>
test   %ecx,%ecx
jne    1207 <main+0x97>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1238 <main+0xc8>
mov    0x2dfc(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe0c(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%eax
jmp    1238 <main+0xc8>
cmp    $0xffffffff,%esi
je     121e <main+0xae>
cmp    $0xffffffff,%edx
je     1227 <main+0xb7>
test   %eax,%eax
je     123e <main+0xce>
lea    0xe2f(%rip),%rdi
jmp    122e <main+0xbe>
lea    0xe59(%rip),%rdi
jmp    122e <main+0xbe>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
test   %ecx,%ecx
jne    1250 <main+0xe0>
lea    0xdec(%rip),%rdi
call   1080 <perror@plt>
jmp    1200 <main+0x90>
lea    0xdcd(%rip),%rdi
call   1080 <perror@plt>
jmp    1233 <main+0xc3>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [36 x i8] c"sched_setscheduler failed: %d (%s)\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [31 x i8] c"interval.tv_sec not updated.\0A\00"
@.str.3 = [32 x i8] c"interval.tv_nsec not updated.\0A\00"
@.str.4 = [21 x i8] c"Returned code != 0.\0A\00"
@.str.5 = [17 x i8] c"Unexpected error\00"
@.str.6 = [22 x i8] c"Unresolved test error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = alloca %struct.sched_param
store i32 0, i32* %1
store i32 -2, i32* %3
%5 = load i32, i32* @SCHED_RR
%6 = call i32 @sched_get_priority_min(i32 %5)
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @SCHED_RR
%9 = call i32 @sched_setscheduler(i32 0, i32 %8, %struct.sched_param* %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %14)
store i32 2, i32* %1
br label %59
16: ; preds = %0
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 -1, i32* %17
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 -1, i32* %18
%19 = call i32 @sched_rr_get_interval(i32 0, %struct.timespec* %2)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %16
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%28 = load i32, i32* %27
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* @errno
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %59
35: ; preds = %30, %26, %22, %16
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %59
41: ; preds = %35
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %59
47: ; preds = %41
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %59
52: ; preds = %47
%53 = load i32, i32* @errno
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %59
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %1
br label %59
59: ; preds = %57, %55, %50, %45, %39, %33, %11
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [36 x i8] c"sched_setscheduler failed: %d (%s)\0A\00"
@errno = global i32 0
@.str.5 = [17 x i8] c"Unexpected error\00"
@.str.6 = [22 x i8] c"Unresolved test error\00"
@str = [20 x i8] c"Returned code != 0.\00"
@str.7 = [31 x i8] c"interval.tv_nsec not updated.\00"
@str.8 = [30 x i8] c"interval.tv_sec not updated.\00"
@str.9 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.sched_param
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = load i32, i32* @SCHED_RR
%6 = tail call i32 @sched_get_priority_min(i32 %5)
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @SCHED_RR
%9 = call i32 @sched_setscheduler(i32 0, i32 %8, %struct.sched_param* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %13)
br label %47
15: ; preds = %0
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 -1, i32* %16
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 -1, i32* %17
%18 = call i32 @sched_rr_get_interval(i32 0, %struct.timespec* %1)
%19 = icmp eq i32 %18, 0
%20 = load i32, i32* %16
%21 = icmp sgt i32 %20, -1
%22 = select i1 %19, i1 %21, i1 false
%23 = load i32, i32* %17
%24 = icmp sgt i32 %23, -1
%25 = select i1 %22, i1 %24, i1 false
%26 = load i32, i32* @errno
%27 = icmp eq i32 %26, 0
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %31
29: ; preds = %15
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %47
31: ; preds = %15
%32 = icmp eq i32 %20, -1
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.8, i64 0, i64 0))
br label %47
35: ; preds = %31
%36 = icmp eq i32 %23, -1
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0))
br label %47
39: ; preds = %35
br i1 %19, label %42, label %40
40: ; preds = %39
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %47
42: ; preds = %39
br i1 %27, label %45, label %43
43: ; preds = %42
%44 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %47
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %45, %43, %40, %37, %33, %29, %11
%48 = phi i32 [ 2, %11 ], [ 0, %29 ], [ 1, %33 ], [ 1, %37 ], [ 1, %40 ], [ 1, %43 ], [ 2, %45 ]
ret i32 %48
}