#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 /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int err;
  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 -1;
  if (check_itimer(ITIMER_PROF) < 0)
    return -1;
  if (check_itimer(ITIMER_REAL) < 0)
    return -1;
  if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0)
    return -1;
  if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1050 <check_itimer@plt>
cmp    $0x0,%rax
jge    1182 <main+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <main+0xe9>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <check_itimer@plt>
cmp    $0x0,%rax
jge    11a6 <main+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <main+0xe9>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1050 <check_itimer@plt>
cmp    $0x0,%rax
jge    11ca <main+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <main+0xe9>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
cmp    $0x0,%rax
jge    11ee <main+0xbe>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <main+0xe9>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
cmp    $0x0,%rax
jge    1212 <main+0xe2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <main+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
lea    0xefe(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
call   1050 <check_itimer@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11af <main+0x7f>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <check_itimer@plt>
test   %rax,%rax
js     11af <main+0x7f>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <check_itimer@plt>
test   %rax,%rax
js     11af <main+0x7f>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
test   %rax,%rax
js     11af <main+0x7f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1030 <check_timer_create@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
mov    %ebx,%eax
pop    %rbx
ret

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**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @ITIMER_VIRTUAL
%10 = call i64 @check_itimer(i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %34
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 %18
17: ; preds = %13
store i32 -1, i32* %3
br label %34
18: ; preds = %13
%19 = load i32, i32* @ITIMER_REAL
%20 = call i64 @check_itimer(i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %3
br label %34
23: ; preds = %18
%24 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%25 = call i64 @check_timer_create(i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %3
br label %34
28: ; preds = %23
%29 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%30 = call i64 @check_timer_create(i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %3
br label %34
33: ; preds = %28
store i32 0, i32* %3
br label %34
34: ; preds = %33, %32, %27, %22, %17, %12
%35 = load i32, i32* %3
ret i32 %35
}

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 %25, label %8
8: ; preds = %2
%9 = load i32, i32* @ITIMER_PROF
%10 = tail call i64 @check_itimer(i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %8
%13 = load i32, i32* @ITIMER_REAL
%14 = tail call i64 @check_itimer(i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%18 = tail call i64 @check_timer_create(i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%22 = tail call i64 @check_timer_create(i32 %21)
%23 = ashr i64 %22, 63
%24 = trunc i64 %23 to i32
br label %25
25: ; preds = %20, %16, %12, %8, %2
%26 = phi i32 [ -1, %2 ], [ -1, %8 ], [ -1, %12 ], [ -1, %16 ], [ %24, %20 ]
ret i32 %26
}