#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;
};

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_rr_get_interval(int /*<<< orphan*/, struct timespec *);
int main(void) {
  struct timespec interval;
  int result = -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)
movl   $0xffffffff,-0x10(%rbp)
movl   $0xffffffff,-0xc(%rbp)
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1040 <sched_rr_get_interval@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a9 <main+0x79>
cmpl   $0x0,-0x10(%rbp)
jl     11a9 <main+0x79>
cmpl   $0x0,-0xc(%rbp)
jl     11a9 <main+0x79>
mov    0x2e59(%rip),%rax
cmpq   $0x0,(%rax)
jne    11a9 <main+0x79>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124b <main+0x11b>
cmpl   $0xffffffff,-0x10(%rbp)
jne    11cb <main+0x9b>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0x11b>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ed <main+0xbd>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0x11b>
cmpl   $0x0,-0x14(%rbp)
je     120f <main+0xdf>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0x11b>
mov    0x2dca(%rip),%rax
cmpq   $0x0,(%rax)
je     1238 <main+0x108>
lea    0xe3a(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0x11b>
lea    0xe33(%rip),%rdi
call   1050 <perror@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movq   $0xffffffffffffffff,(%rsp)
ff
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <sched_rr_get_interval@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%rcx
test   %eax,%eax
jne    1175 <main+0x45>
test   %esi,%esi
js     1175 <main+0x45>
test   %edx,%edx
js     1175 <main+0x45>
test   %rcx,%rcx
jne    1175 <main+0x45>
lea    0xf0c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
cmp    $0xffffffff,%esi
je     118c <main+0x5c>
cmp    $0xffffffff,%edx
je     1195 <main+0x65>
test   %eax,%eax
je     11a8 <main+0x78>
lea    0xe9d(%rip),%rdi
jmp    119c <main+0x6c>
lea    0xec7(%rip),%rdi
jmp    119c <main+0x6c>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
test   %rcx,%rcx
jne    11c0 <main+0x90>
lea    0xe5d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret
lea    0xe39(%rip),%rdi
call   1050 <perror@plt>
jmp    11a1 <main+0x71>

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

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