#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*/ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_rr_get_interval(int /*<<< orphan*/, struct timespec *);
int main(void) {
  struct timespec interval0;
  struct timespec interval1;
  int result0 = -1;
  int result1 = -1;
  interval0.tv_sec = -1;
  interval0.tv_nsec = -1;
  interval1.tv_sec = -1;
  interval1.tv_nsec = -1;
  result0 = sched_rr_get_interval(0, &interval0);
  result1 = sched_rr_get_interval(getpid(), &interval1);
  if (result0 == result1 && interval0.tv_sec == interval1.tv_sec &&
      interval0.tv_nsec == interval1.tv_nsec && errno == 0) {
    printf("Test PASSED\n");
    return 0;
  } else if (errno != 0) {
    perror("Unexpected error");
    return 1;
  } else {
    printf("Different results between pid == 0 and pid == getpid().\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1050 <sched_rr_get_interval@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <sched_rr_get_interval@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11e9 <main+0xa9>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11e9 <main+0xa9>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11e9 <main+0xa9>
mov    0x2e19(%rip),%rax
cmpq   $0x0,(%rax)
jne    11e9 <main+0xa9>
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <main+0xe5>
mov    0x2df0(%rip),%rax
cmpq   $0x0,(%rax)
je     1212 <main+0xd2>
lea    0xe0c(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1225 <main+0xe5>
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
movq   $0xffffffffffffffff,(%rsp)
ff
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1050 <sched_rr_get_interval@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <sched_rr_get_interval@plt>
cmp    %eax,%ebx
jne    11ab <main+0x6b>
mov    0x8(%rsp),%eax
cmp    (%rsp),%eax
jne    11ab <main+0x6b>
mov    0xc(%rsp),%ecx
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
cmp    0x4(%rsp),%ecx
jne    11b5 <main+0x75>
test   %rax,%rax
jne    11b5 <main+0x75>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11cb <main+0x8b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
jne    11d1 <main+0x91>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe28(%rip),%rdi
call   1060 <perror@plt>
jmp    11c6 <main+0x86>

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

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