#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 */

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ CLOCK_THREAD_CPUTIME_ID;
int /*<<< orphan*/ ITIMER_PROF;
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ ITIMER_VIRTUAL;
scalar_t__ check_itimer(int /*<<< orphan*/);
scalar_t__ check_timer_create(int /*<<< orphan*/);
int ksft_exit_fail();
int ksft_exit_pass();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  printf("Testing posix timers. False negative may happen on CPU execution \n");
  printf("based timers if other threads run on the CPU...\n");
  if (check_itimer(ITIMER_VIRTUAL) < 0) {
    return ksft_exit_fail();
  }
  if (check_itimer(ITIMER_PROF) < 0) {
    return ksft_exit_fail();
  }
  if (check_itimer(ITIMER_REAL) < 0) {
    return ksft_exit_fail();
  }
  if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0) {
    return ksft_exit_fail();
  }
  if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) {
    return ksft_exit_fail();
  }
  return ksft_exit_pass();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
call   1060 <printf@plt>
lea    0xeca(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <check_itimer@plt>
cmp    $0x0,%rax
jge    11a5 <main+0x55>
mov    $0x0,%al
call   1050 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    124b <main+0xfb>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1070 <check_itimer@plt>
cmp    $0x0,%rax
jge    11cc <main+0x7c>
mov    $0x0,%al
call   1050 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    124b <main+0xfb>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <check_itimer@plt>
cmp    $0x0,%rax
jge    11f3 <main+0xa3>
mov    $0x0,%al
call   1050 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    124b <main+0xfb>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
cmp    $0x0,%rax
jge    121a <main+0xca>
mov    $0x0,%al
call   1050 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    124b <main+0xfb>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
cmp    $0x0,%rax
jge    1241 <main+0xf1>
mov    $0x0,%al
call   1050 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    124b <main+0xfb>
mov    $0x0,%al
call   1040 <ksft_exit_pass@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
lea    0xede(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1070 <check_itimer@plt>
test   %rax,%rax
js     11d0 <main+0x80>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <check_itimer@plt>
test   %rax,%rax
js     11d0 <main+0x80>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <check_itimer@plt>
test   %rax,%rax
js     11d0 <main+0x80>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
test   %rax,%rax
js     11d0 <main+0x80>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
test   %rax,%rax
js     11d0 <main+0x80>
xor    %eax,%eax
pop    %rcx
jmp    1050 <ksft_exit_pass@plt>
xor    %eax,%eax
pop    %rcx
jmp    1060 <ksft_exit_fail@plt>

LLVM IR (-O0):
@.str = [67 x i8] c"Testing posix timers. False negative may happen on CPU execution \0A\00"
@.str.1 = [49 x i8] c"based timers if other threads run on the CPU...\0A\00"
@ITIMER_VIRTUAL = global i32 0
@ITIMER_PROF = global i32 0
@ITIMER_REAL = global i32 0
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @ITIMER_VIRTUAL
%9 = call i64 @check_itimer(i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @ksft_exit_fail()
store i32 %12, i32* %3
br label %39
13: ; preds = %2
%14 = load i32, i32* @ITIMER_PROF
%15 = call i64 @check_itimer(i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (...) @ksft_exit_fail()
store i32 %18, i32* %3
br label %39
19: ; preds = %13
%20 = load i32, i32* @ITIMER_REAL
%21 = call i64 @check_itimer(i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (...) @ksft_exit_fail()
store i32 %24, i32* %3
br label %39
25: ; preds = %19
%26 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%27 = call i64 @check_timer_create(i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (...) @ksft_exit_fail()
store i32 %30, i32* %3
br label %39
31: ; preds = %25
%32 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%33 = call i64 @check_timer_create(i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (...) @ksft_exit_fail()
store i32 %36, i32* %3
br label %39
37: ; preds = %31
%38 = call i32 (...) @ksft_exit_pass()
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %35, %29, %23, %17, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@ITIMER_VIRTUAL = global i32 0
@ITIMER_PROF = global i32 0
@ITIMER_REAL = global i32 0
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@str = [66 x i8] c"Testing posix timers. False negative may happen on CPU execution \00"
@str.2 = [48 x i8] c"based timers if other threads run on the CPU...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.2, i64 0, i64 0))
%5 = load i32, i32* @ITIMER_VIRTUAL
%6 = tail call i64 @check_itimer(i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @ksft_exit_fail()
br label %36
10: ; preds = %2
%11 = load i32, i32* @ITIMER_PROF
%12 = tail call i64 @check_itimer(i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 (...) @ksft_exit_fail()
br label %36
16: ; preds = %10
%17 = load i32, i32* @ITIMER_REAL
%18 = tail call i64 @check_itimer(i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 (...) @ksft_exit_fail()
br label %36
22: ; preds = %16
%23 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%24 = tail call i64 @check_timer_create(i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 (...) @ksft_exit_fail()
br label %36
28: ; preds = %22
%29 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%30 = tail call i64 @check_timer_create(i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 (...) @ksft_exit_fail()
br label %36
34: ; preds = %28
%35 = tail call i32 (...) @ksft_exit_pass()
br label %36
36: ; preds = %34, %32, %26, %20, %14, %8
%37 = phi i32 [ %9, %8 ], [ %15, %14 ], [ %21, %20 ], [ %27, %26 ], [ %33, %32 ], [ %35, %34 ]
ret i32 %37
}