#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 dummy;
};
struct sched_param {
  int sched_priority;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ CLOCK_THREAD_CPUTIME_ID;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ do_stuff();
scalar_t__ errno;
unsigned long long getcputime(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long long);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
scalar_t__ setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  unsigned long long process_start, thread_start, real_start, mono_start;
  unsigned long long process_end, thread_end, real_end, mono_end;
  struct timespec cputime;
  struct sched_param pri;
  clockid_t thread = CLOCK_THREAD_CPUTIME_ID;
  clockid_t process = CLOCK_PROCESS_CPUTIME_ID;
  clockid_t real = CLOCK_REALTIME;
  clockid_t monotonic = CLOCK_MONOTONIC;
  pri.sched_priority = 99;
  if (sched_setscheduler(0, SCHED_FIFO, &pri))
    perror("sched_setscheduler() error:");
  errno = 0;
  if (setpriority(PRIO_PROCESS, 0, -20))
    perror("setpriority() error:");
  real_start = getcputime(real);
  mono_start = getcputime(monotonic);
  process_start = getcputime(process);
  thread_start = getcputime(thread);
  do_stuff();
  real_end = getcputime(real);
  mono_end = getcputime(monotonic);
  process_end = getcputime(process);
  thread_end = getcputime(thread);
  printf("Real: %llu\n", real_end - real_start);
  printf("Monotonic: %llu\n", mono_end - mono_start);
  printf("Process: %llu\n", process_end - process_start);
  printf("Thread: %llu\n", thread_end - thread_start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
movl   $0x63,-0x60(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x60(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     11d7 <main+0x77>
lea    0xe2e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dda(%rip),%rax
movq   $0x0,(%rax)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xffffffec,%edx
call   1050 <setpriority@plt>
cmp    $0x0,%rax
je     1210 <main+0xb0>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
mov    -0x6c(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x70(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x68(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x64(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1080 <do_stuff@plt>
mov    -0x6c(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x48(%rbp)
mov    -0x70(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x50(%rbp)
mov    -0x68(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x64(%rbp),%edi
call   1030 <getcputime@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rsi
sub    -0x28(%rbp),%rsi
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rsi
sub    -0x30(%rbp),%rsi
lea    0xda3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsi
sub    -0x20(%rbp),%rsi
lea    0xd9b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e73(%rip),%rax
mov    (%rax),%r13d
mov    0x2e61(%rip),%rax
mov    (%rax),%r15d
mov    0x2e27(%rip),%rax
mov    (%rax),%ebp
mov    0x2e46(%rip),%rax
mov    (%rax),%ebx
movl   $0x63,(%rsp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1060 <sched_setscheduler@plt>
test   %rax,%rax
jne    129f <main+0x13f>
mov    0x2dfa(%rip),%rax
movq   $0x0,(%rax)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xffffffec,%edx
call   1050 <setpriority@plt>
test   %rax,%rax
jne    12b0 <main+0x150>
mov    %ebp,%edi
call   1030 <getcputime@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1030 <getcputime@plt>
mov    %rax,%r14
mov    %r15d,%edi
call   1030 <getcputime@plt>
mov    %rax,0x8(%rsp)
mov    %r13d,%edi
call   1030 <getcputime@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1080 <do_stuff@plt>
mov    %ebp,%edi
call   1030 <getcputime@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1030 <getcputime@plt>
mov    %rax,%rbx
mov    %r15d,%edi
call   1030 <getcputime@plt>
mov    %rax,%r15
mov    %r13d,%edi
call   1030 <getcputime@plt>
mov    %rax,%r13
sub    %r12,%rbp
lea    0xde5(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
sub    %r14,%rbx
lea    0xddf(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
sub    0x8(%rsp),%r15
lea    0xddc(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
sub    0x10(%rsp),%r13
lea    0xdd7(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5a(%rip),%rdi
call   1070 <perror@plt>
jmp    11b7 <main+0x57>
lea    0xd65(%rip),%rdi
call   1070 <perror@plt>
jmp    11e3 <main+0x83>

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.sched_param = type { i32 }
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@CLOCK_REALTIME = global i32 0
@CLOCK_MONOTONIC = global i32 0
@SCHED_FIFO = global i32 0
@.str = [28 x i8] c"sched_setscheduler() error:\00"
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@.str.1 = [21 x i8] c"setpriority() error:\00"
@.str.2 = [12 x i8] c"Real: %llu\0A\00"
@.str.3 = [17 x i8] c"Monotonic: %llu\0A\00"
@.str.4 = [15 x i8] c"Process: %llu\0A\00"
@.str.5 = [14 x i8] c"Thread: %llu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca %struct.timespec
%15 = alloca %struct.sched_param
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
store i32 %20, i32* %16
%21 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
store i32 %21, i32* %17
%22 = load i32, i32* @CLOCK_REALTIME
store i32 %22, i32* %18
%23 = load i32, i32* @CLOCK_MONOTONIC
store i32 %23, i32* %19
%24 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %15, i32 0, i32 0
store i32 99, i32* %24
%25 = load i32, i32* @SCHED_FIFO
%26 = call i64 @sched_setscheduler(i32 0, i32 %25, %struct.sched_param* %15)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %2
store i64 0, i64* @errno
%31 = load i32, i32* @PRIO_PROCESS
%32 = call i64 @setpriority(i32 %31, i32 0, i32 -20)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = load i32, i32* %18
%38 = call i64 @getcputime(i32 %37)
store i64 %38, i64* %8
%39 = load i32, i32* %19
%40 = call i64 @getcputime(i32 %39)
store i64 %40, i64* %9
%41 = load i32, i32* %17
%42 = call i64 @getcputime(i32 %41)
store i64 %42, i64* %6
%43 = load i32, i32* %16
%44 = call i64 @getcputime(i32 %43)
store i64 %44, i64* %7
%45 = call i32 (...) @do_stuff()
%46 = load i32, i32* %18
%47 = call i64 @getcputime(i32 %46)
store i64 %47, i64* %12
%48 = load i32, i32* %19
%49 = call i64 @getcputime(i32 %48)
store i64 %49, i64* %13
%50 = load i32, i32* %17
%51 = call i64 @getcputime(i32 %50)
store i64 %51, i64* %10
%52 = load i32, i32* %16
%53 = call i64 @getcputime(i32 %52)
store i64 %53, i64* %11
%54 = load i64, i64* %12
%55 = load i64, i64* %8
%56 = sub i64 %54, %55
%57 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %56)
%58 = load i64, i64* %13
%59 = load i64, i64* %9
%60 = sub i64 %58, %59
%61 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %60)
%62 = load i64, i64* %10
%63 = load i64, i64* %6
%64 = sub i64 %62, %63
%65 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 %64)
%66 = load i64, i64* %11
%67 = load i64, i64* %7
%68 = sub i64 %66, %67
%69 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %68)
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@CLOCK_REALTIME = global i32 0
@CLOCK_MONOTONIC = global i32 0
@SCHED_FIFO = global i32 0
@.str = [28 x i8] c"sched_setscheduler() error:\00"
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@.str.1 = [21 x i8] c"setpriority() error:\00"
@.str.2 = [12 x i8] c"Real: %llu\0A\00"
@.str.3 = [17 x i8] c"Monotonic: %llu\0A\00"
@.str.4 = [15 x i8] c"Process: %llu\0A\00"
@.str.5 = [14 x i8] c"Thread: %llu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sched_param
%4 = bitcast %struct.sched_param* %3 to i8*
%5 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%6 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%7 = load i32, i32* @CLOCK_REALTIME
%8 = load i32, i32* @CLOCK_MONOTONIC
%9 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 99, i32* %9
%10 = load i32, i32* @SCHED_FIFO
%11 = call i64 @sched_setscheduler(i32 0, i32 %10, %struct.sched_param* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
store i64 0, i64* @errno
%16 = load i32, i32* @PRIO_PROCESS
%17 = call i64 @setpriority(i32 %16, i32 0, i32 -20)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = call i64 @getcputime(i32 %7)
%23 = call i64 @getcputime(i32 %8)
%24 = call i64 @getcputime(i32 %6)
%25 = call i64 @getcputime(i32 %5)
%26 = call i32 (...) @do_stuff()
%27 = call i64 @getcputime(i32 %7)
%28 = call i64 @getcputime(i32 %8)
%29 = call i64 @getcputime(i32 %6)
%30 = call i64 @getcputime(i32 %5)
%31 = sub i64 %27, %22
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %31)
%33 = sub i64 %28, %23
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %33)
%35 = sub i64 %29, %24
%36 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 %35)
%37 = sub i64 %30, %25
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %37)
ret i32 0
}