#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 {
  scalar_t__ tv_nsec;
};

/* Variables and functions */
scalar_t__ ESRCH;
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ memset(struct timespec *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sched_rr_get_interval(int, struct timespec *);
int /*<<< orphan*/ stdout;
int test_rr_interval(void) {
  struct timespec ts;
  int err;
  printf("Test sched_rr_get_interval()...");
  memset(&ts, 0, sizeof(struct timespec));
  err = sched_rr_get_interval(getpid(), &ts);
  if (err == 0) {
    if (ts.tv_nsec == 0) {
      printf("Failed:  RR time is zero\n");
      return -1;
    } else {
      printf("%ld ns...", ts.tv_nsec);
    }
  } else {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("passed\n");
  printf("Test sched_rr_get_interval() (ERSCH)...");
  memset(&ts, 0, sizeof(struct timespec));
  err = sched_rr_get_interval(-1, &ts);
  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_rr_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
call   1070 <sched_rr_get_interval@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e1 <test_rr_interval+0x81>
cmpq   $0x0,-0x10(%rbp)
jne    11ca <test_rr_interval+0x6a>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <test_rr_interval+0x151>
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1207 <test_rr_interval+0xa7>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe4e(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <test_rr_interval+0x151>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    $0xffffffff,%edi
lea    -0x10(%rbp),%rsi
call   1070 <sched_rr_get_interval@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1268 <test_rr_interval+0x108>
mov    0x2d8b(%rip),%rax
mov    (%rax),%rax
mov    0x2d69(%rip),%rcx
cmp    (%rcx),%rax
je     128e <test_rr_interval+0x12e>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <test_rr_interval+0x151>
mov    0x2d4b(%rip),%rax
movq   $0x0,(%rax)
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rr_interval>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <sched_rr_get_interval@plt>
test   %eax,%eax
jne    126a <test_rr_interval+0xfa>
mov    (%rsp),%rsi
test   %rsi,%rsi
je     1233 <test_rr_interval+0xc3>
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
mov    %r14,%rsi
call   1080 <sched_rr_get_interval@plt>
test   %eax,%eax
je     124e <test_rr_interval+0xde>
mov    0x2dd3(%rip),%rax
mov    (%rax),%rcx
mov    0x2db1(%rip),%rdx
cmp    (%rdx),%rcx
jne    124e <test_rr_interval+0xde>
movq   $0x0,(%rax)
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1244 <test_rr_interval+0xd4>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xdf6(%rip),%rdi
call   1090 <perror@plt>
jmp    1244 <test_rr_interval+0xd4>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xdab(%rip),%rdi
call   1090 <perror@plt>
jmp    123f <test_rr_interval+0xcf>

LLVM IR (-O0):
%struct.timespec = type { i64 }
@.str = [32 x i8] c"Test sched_rr_get_interval()...\00"
@.str.1 = [26 x i8] c"Failed: RR time is zero\0A\00"
@.str.2 = [10 x i8] c"%ld ns...\00"
@stdout = global i32 0
@.str.3 = [7 x i8] c"failed\00"
@.str.4 = [8 x i8] c"passed\0A\00"
@.str.5 = [40 x i8] c"Test sched_rr_get_interval() (ERSCH)...\00"
@errno = global i64 0
@ESRCH = global i64 0
@.str.6 = [30 x i8] c"should have failed with ESRCH\00"
define i32 @test_rr_interval() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @memset(%struct.timespec* %2, i32 0, i32 8)
%6 = call i32 (...) @getpid()
%7 = call i32 @sched_rr_get_interval(i32 %6, %struct.timespec* %2)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %43
16: ; preds = %10
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%18 = load i64, i64* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %16
br label %25
21: ; preds = %0
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %43
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @memset(%struct.timespec* %2, i32 0, i32 8)
%29 = call i32 @sched_rr_get_interval(i32 -1, %struct.timespec* %2)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %25
%33 = load i64, i64* @errno
%34 = load i64, i64* @ESRCH
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32, %25
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
%39 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %43
40: ; preds = %32
store i64 0, i64* @errno
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40
store i32 0, i32* %1
br label %43
43: ; preds = %42, %36, %21, %14
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
%struct.timespec = type { i64 }
@.str = [32 x i8] c"Test sched_rr_get_interval()...\00"
@.str.2 = [10 x i8] c"%ld ns...\00"
@stdout = global i32 0
@.str.3 = [7 x i8] c"failed\00"
@.str.5 = [40 x i8] c"Test sched_rr_get_interval() (ERSCH)...\00"
@errno = global i64 0
@ESRCH = global i64 0
@.str.6 = [30 x i8] c"should have failed with ESRCH\00"
@str.7 = [7 x i8] c"passed\00"
@str.8 = [25 x i8] c"Failed: RR time is zero\00"
define i32 @test_rr_interval() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @memset(%struct.timespec* %1, i32 0, i32 8)
%5 = call i32 (...) @getpid()
%6 = call i32 @sched_rr_get_interval(i32 %5, %struct.timespec* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
br label %35
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %10)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.7, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @memset(%struct.timespec* %1, i32 0, i32 8)
%19 = call i32 @sched_rr_get_interval(i32 -1, %struct.timespec* %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %29, label %25
21: ; preds = %0
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %35
25: ; preds = %14
%26 = load i64, i64* @errno
%27 = load i64, i64* @ESRCH
%28 = icmp eq i64 %26, %27
br i1 %28, label %33, label %29
29: ; preds = %25, %14
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %35
33: ; preds = %25
store i64 0, i64* @errno
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.7, i64 0, i64 0))
br label %35
35: ; preds = %33, %29, %21, %12
%36 = phi i32 [ -1, %12 ], [ -1, %29 ], [ 0, %33 ], [ -1, %21 ]
ret i32 %36
}