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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ SIGABRT;
int TIMER_ABSTIME;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ clock_nanosleep(int /*<<< orphan*/, int, struct timespec *,
                                   int /*<<< orphan*/ *);
int fork();
scalar_t__ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ tst_process_state_wait3(int, char, int);
int wait(int *);
int main(void) {
  struct timespec tssleep, tsbefore, tsafter;
  int pid;
  time_t sleepuntilsec;
  if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) {
    perror("clock_gettime() did not return success\n");
    return 2;
  }
  sleepuntilsec = tsbefore.tv_sec + 30;
  if ((pid = fork()) == 0) {
    int flags = 0;
    tssleep.tv_sec = sleepuntilsec;
    tssleep.tv_nsec = tsbefore.tv_nsec;
    flags |= TIMER_ABSTIME;
    clock_nanosleep(CLOCK_REALTIME, flags, &tssleep, NULL);
  } else {
    int i;
    tst_process_state_wait3(pid, 'S', 1);
    if (kill(pid, SIGABRT) != 0) {
      printf("Could not raise signal being tested\n");
      return 2;
    }
    if (wait(&i) == -1) {
      perror("Error waiting for child to exit\n");
      return 2;
    }
    if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) {
      perror("clock_gettime() did not return success\n");
      return 2;
    }
    if (tsafter.tv_sec < sleepuntilsec) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("Slept for too long: %lld >= %lld\n",
             (long long int)tsafter.tv_sec, (long long int)sleepuntilsec);
      printf("Test FAILED\n");
      return 1;
    }
  }
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     11c3 <main+0x43>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1328 <main+0x1a8>
mov    -0x28(%rbp),%rax
add    $0x1e,%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jne    1224 <main+0xa4>
movl   $0x0,-0x4c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
or     -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    -0x4c(%rbp),%esi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <clock_nanosleep@plt>
jmp    1321 <main+0x1a1>
mov    -0x3c(%rbp),%edi
mov    $0x53,%esi
mov    $0x1,%edx
call   1050 <tst_process_state_wait3@plt>
mov    -0x3c(%rbp),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0x0,%rax
je     126b <main+0xeb>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1328 <main+0x1a8>
lea    -0x50(%rbp),%rdi
call   1090 <wait@plt>
cmp    $0xffffffff,%eax
jne    1295 <main+0x115>
lea    0xdc9(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1328 <main+0x1a8>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     12c9 <main+0x149>
lea    0xd48(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1328 <main+0x1a8>
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jge    12f1 <main+0x171>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1328 <main+0x1a8>
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1328 <main+0x1a8>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e39(%rip),%r14
mov    (%r14),%edi
lea    0x20(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
jne    1291 <main+0x101>
mov    0x20(%rsp),%rbx
add    $0x1e,%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     11ff <main+0x6f>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x53,%esi
mov    $0x1,%edx
call   1060 <tst_process_state_wait3@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <kill@plt>
test   %rax,%rax
je     1232 <main+0xa2>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
jmp    1224 <main+0x94>
mov    %rbx,0x8(%rsp)
mov    0x28(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    (%r14),%edi
lea    0x8(%rsp),%rdx
xor    %ecx,%ecx
call   1090 <clock_nanosleep@plt>
mov    $0x2,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x1c(%rsp),%rdi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x10f>
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
jne    1291 <main+0x101>
mov    0x8(%rsp),%rsi
cmp    %rbx,%rsi
jge    126d <main+0xdd>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1229 <main+0x99>
lea    0xdd5(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1229 <main+0x99>
lea    0xd68(%rip),%rdi
call   1080 <perror@plt>
jmp    1224 <main+0x94>
lea    0xd82(%rip),%rdi
jmp    1298 <main+0x108>

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
@CLOCK_REALTIME = global i32 0
@.str = [40 x i8] c"clock_gettime() did not return success\0A\00"
@TIMER_ABSTIME = global i32 0
@SIGABRT = global i32 0
@.str.1 = [37 x i8] c"Could not raise signal being tested\0A\00"
@.str.2 = [33 x i8] c"Error waiting for child to exit\0A\00"
@.str.3 = [13 x i8] c"Test PASSED\0A\00"
@.str.4 = [34 x i8] c"Slept for too long: %lld >= %lld\0A\00"
@.str.5 = [13 x i8] c"Test FAILED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @CLOCK_REALTIME
%10 = call i64 @clock_gettime(i32 %9, %struct.timespec* %3)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %66
14: ; preds = %0
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%16 = load i64, i64* %15
%17 = add nsw i64 %16, 30
store i64 %17, i64* %6
%18 = call i32 (...) @fork()
store i32 %18, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %14
store i32 0, i32* %7
%21 = load i64, i64* %6
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i64 %21, i64* %22
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @TIMER_ABSTIME
%27 = load i32, i32* %7
%28 = or i32 %27, %26
store i32 %28, i32* %7
%29 = load i32, i32* @CLOCK_REALTIME
%30 = load i32, i32* %7
%31 = call i32 @clock_nanosleep(i32 %29, i32 %30, %struct.timespec* %2, i32* null)
br label %65
32: ; preds = %14
%33 = load i32, i32* %5
%34 = call i32 @tst_process_state_wait3(i32 %33, i8 signext 83, i32 1)
%35 = load i32, i32* %5
%36 = load i32, i32* @SIGABRT
%37 = call i64 @kill(i32 %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %66
41: ; preds = %32
%42 = call i32 @wait(i32* %8)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %66
46: ; preds = %41
%47 = load i32, i32* @CLOCK_REALTIME
%48 = call i64 @clock_gettime(i32 %47, %struct.timespec* %4)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %66
52: ; preds = %46
%53 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%54 = load i64, i64* %53
%55 = load i64, i64* %6
%56 = icmp slt i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %66
59: ; preds = %52
%60 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%61 = load i64, i64* %60
%62 = load i64, i64* %6
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %61, i64 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %66
65: ; preds = %20
store i32 2, i32* %1
br label %66
66: ; preds = %65, %59, %57, %50, %44, %39, %12
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
@CLOCK_REALTIME = global i32 0
@.str = [40 x i8] c"clock_gettime() did not return success\0A\00"
@TIMER_ABSTIME = global i32 0
@SIGABRT = global i32 0
@.str.2 = [33 x i8] c"Error waiting for child to exit\0A\00"
@.str.4 = [34 x i8] c"Slept for too long: %lld >= %lld\0A\00"
@str = [12 x i8] c"Test FAILED\00"
@str.6 = [12 x i8] c"Test PASSED\00"
@str.7 = [36 x i8] c"Could not raise signal being tested\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = bitcast %struct.timespec* %1 to i8*
%6 = bitcast %struct.timespec* %2 to i8*
%7 = bitcast %struct.timespec* %3 to i8*
%8 = load i32, i32* @CLOCK_REALTIME
%9 = call i64 @clock_gettime(i32 %8, %struct.timespec* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %57
13: ; preds = %0
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%15 = load i64, i64* %14
%16 = add nsw i64 %15, 30
%17 = call i32 (...) @fork()
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %13
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i64 %16, i64* %20
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @TIMER_ABSTIME
%25 = load i32, i32* @CLOCK_REALTIME
%26 = call i32 @clock_nanosleep(i32 %25, i32 %24, %struct.timespec* %1, i32* null)
br label %57
27: ; preds = %13
%28 = bitcast i32* %4 to i8*
%29 = call i32 @tst_process_state_wait3(i32 %17, i8 signext 83, i32 1)
%30 = load i32, i32* @SIGABRT
%31 = call i64 @kill(i32 %17, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %27
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.7, i64 0, i64 0))
br label %55
35: ; preds = %27
%36 = call i32 @wait(i32* %4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %55
40: ; preds = %35
%41 = load i32, i32* @CLOCK_REALTIME
%42 = call i64 @clock_gettime(i32 %41, %struct.timespec* %3)
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %55
46: ; preds = %40
%47 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%48 = load i64, i64* %47
%49 = icmp slt i64 %48, %16
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %55
52: ; preds = %46
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %48, i64 %16)
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %52, %50, %44, %38, %33
%56 = phi i32 [ 2, %33 ], [ 2, %38 ], [ 2, %44 ], [ 0, %50 ], [ 1, %52 ]
br label %57
57: ; preds = %19, %55, %11
%58 = phi i32 [ 2, %11 ], [ 2, %19 ], [ %56, %55 ]
ret i32 %58
}