#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getuid();
scalar_t__ prctl(int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int system(char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int ret;
  if (getuid() != 0) {
    fprintf(stderr, "needs to run as root.\n");
    exit(1);
  }
  ret = system("cat /proc/sys/kernel/mcount_enabled >/dev/null 2>/dev/null");
  if (ret) {
    fprintf(stderr, "CONFIG_LATENCY_TRACING not enabled?\n");
    exit(1);
  }
  system("echo 1 > /proc/sys/kernel/trace_user_triggered");
  system("[ -e /proc/sys/kernel/wakeup_timing ] && echo 0 > "
         "/proc/sys/kernel/wakeup_timing");
  system("echo 1 > /proc/sys/kernel/trace_enabled");
  system("echo 1 > /proc/sys/kernel/mcount_enabled");
  system("echo 0 > /proc/sys/kernel/trace_freerunning");
  system("echo 0 > /proc/sys/kernel/trace_print_on_crash");
  system("echo 0 > /proc/sys/kernel/trace_verbose");
  system("echo 0 > /proc/sys/kernel/preempt_thresh 2>/dev/null");
  system("echo 0 > /proc/sys/kernel/preempt_max_latency 2>/dev/null");
  if (prctl(0, 1)) {
    fprintf(stderr, "trace-it: couldnt start tracing!\n");
    return 1;
  }
  usleep(10000000);
  if (prctl(0, 0)) {
    fprintf(stderr, "trace-it: couldnt stop tracing!\n");
    return 1;
  }
  system("echo 0 > /proc/sys/kernel/trace_user_triggered");
  system("echo 0 > /proc/sys/kernel/trace_enabled");
  system("cat /proc/latency_trace");
  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)
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
je     11a6 <main+0x46>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe6a(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11de <main+0x7e>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe92(%rip),%rdi
call   1040 <system@plt>
lea    0xeb5(%rip),%rdi
call   1040 <system@plt>
lea    0xefa(%rip),%rdi
call   1040 <system@plt>
lea    0xf16(%rip),%rdi
call   1040 <system@plt>
lea    0xf33(%rip),%rdi
call   1040 <system@plt>
lea    0xf53(%rip),%rdi
call   1040 <system@plt>
lea    0xf76(%rip),%rdi
call   1040 <system@plt>
lea    0xf92(%rip),%rdi
call   1040 <system@plt>
lea    0xfbb(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <prctl@plt>
cmp    $0x0,%rax
je     1281 <main+0x121>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xfca(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ea <main+0x18a>
mov    $0x989680,%edi
call   1080 <usleep@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1060 <prctl@plt>
cmp    $0x0,%rax
je     12bf <main+0x15f>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xfae(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ea <main+0x18a>
lea    0xfb7(%rip),%rdi
call   1040 <system@plt>
lea    0xfda(%rip),%rdi
call   1040 <system@plt>
lea    0xff6(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
jne    1277 <main+0x117>
lea    0xe9f(%rip),%rdi
call   1040 <system@plt>
test   %eax,%eax
jne    1289 <main+0x129>
lea    0xeeb(%rip),%rdi
call   1040 <system@plt>
lea    0xf0e(%rip),%rdi
call   1040 <system@plt>
lea    0xf53(%rip),%rdi
call   1040 <system@plt>
lea    0xf6f(%rip),%rdi
call   1040 <system@plt>
lea    0xf8c(%rip),%rdi
call   1040 <system@plt>
lea    0xfac(%rip),%rdi
call   1040 <system@plt>
lea    0xfcf(%rip),%rdi
call   1040 <system@plt>
lea    0xfeb(%rip),%rdi
call   1040 <system@plt>
lea    0x1014(%rip),%rdi
call   1040 <system@plt>
mov    $0x1,%ebx
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <prctl@plt>
test   %rax,%rax
je     121e <main+0xbe>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0x1023(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1273 <main+0x113>
mov    $0x989680,%edi
call   1080 <usleep@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1060 <prctl@plt>
test   %rax,%rax
je     124d <main+0xed>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0x1016(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1273 <main+0x113>
lea    0x1029(%rip),%rdi
call   1040 <system@plt>
lea    0x104c(%rip),%rdi
call   1040 <system@plt>
lea    0x1068(%rip),%rdi
call   1040 <system@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
jmp    1299 <main+0x139>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"needs to run as root.\0A\00"
@.str.1 = [59 x i8] c"cat /proc/sys/kernel/mcount_enabled >/dev/null 2>/dev/null\00"
@.str.2 = [37 x i8] c"CONFIG_LATENCY_TRACING not enabled?\0A\00"
@.str.3 = [47 x i8] c"echo 1 > /proc/sys/kernel/trace_user_triggered\00"
@.str.4 = [81 x i8] c"[ -e /proc/sys/kernel/wakeup_timing ] && echo 0 > /proc/sys/kernel/wakeup_timing\00"
@.str.5 = [40 x i8] c"echo 1 > /proc/sys/kernel/trace_enabled\00"
@.str.6 = [41 x i8] c"echo 1 > /proc/sys/kernel/mcount_enabled\00"
@.str.7 = [44 x i8] c"echo 0 > /proc/sys/kernel/trace_freerunning\00"
@.str.8 = [47 x i8] c"echo 0 > /proc/sys/kernel/trace_print_on_crash\00"
@.str.9 = [40 x i8] c"echo 0 > /proc/sys/kernel/trace_verbose\00"
@.str.10 = [53 x i8] c"echo 0 > /proc/sys/kernel/preempt_thresh 2>/dev/null\00"
@.str.11 = [58 x i8] c"echo 0 > /proc/sys/kernel/preempt_max_latency 2>/dev/null\00"
@.str.12 = [34 x i8] c"trace-it: couldnt start tracing!\0A\00"
@.str.13 = [33 x i8] c"trace-it: couldnt stop tracing!\0A\00"
@.str.14 = [47 x i8] c"echo 0 > /proc/sys/kernel/trace_user_triggered\00"
@.str.15 = [40 x i8] c"echo 0 > /proc/sys/kernel/trace_enabled\00"
@.str.16 = [24 x i8] c"cat /proc/latency_trace\00"
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 i64 (...) @getuid()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @system(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = call i32 @system(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @system(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @system(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 @system(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%27 = call i32 @system(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0))
%28 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%29 = call i32 @system(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%30 = call i32 @system(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.11, i64 0, i64 0))
%31 = call i64 @prctl(i32 0, i32 1)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %47
36: ; preds = %21
%37 = call i32 @usleep(i32 10000000)
%38 = call i64 @prctl(i32 0, i32 0)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %47
43: ; preds = %36
%44 = call i32 @system(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.14, i64 0, i64 0))
%45 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.15, i64 0, i64 0))
%46 = call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %3
br label %47
47: ; preds = %43, %40, %33
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"needs to run as root.\0A\00"
@.str.1 = [59 x i8] c"cat /proc/sys/kernel/mcount_enabled >/dev/null 2>/dev/null\00"
@.str.2 = [37 x i8] c"CONFIG_LATENCY_TRACING not enabled?\0A\00"
@.str.3 = [47 x i8] c"echo 1 > /proc/sys/kernel/trace_user_triggered\00"
@.str.4 = [81 x i8] c"[ -e /proc/sys/kernel/wakeup_timing ] && echo 0 > /proc/sys/kernel/wakeup_timing\00"
@.str.5 = [40 x i8] c"echo 1 > /proc/sys/kernel/trace_enabled\00"
@.str.6 = [41 x i8] c"echo 1 > /proc/sys/kernel/mcount_enabled\00"
@.str.7 = [44 x i8] c"echo 0 > /proc/sys/kernel/trace_freerunning\00"
@.str.8 = [47 x i8] c"echo 0 > /proc/sys/kernel/trace_print_on_crash\00"
@.str.9 = [40 x i8] c"echo 0 > /proc/sys/kernel/trace_verbose\00"
@.str.10 = [53 x i8] c"echo 0 > /proc/sys/kernel/preempt_thresh 2>/dev/null\00"
@.str.11 = [58 x i8] c"echo 0 > /proc/sys/kernel/preempt_max_latency 2>/dev/null\00"
@.str.12 = [34 x i8] c"trace-it: couldnt start tracing!\0A\00"
@.str.13 = [33 x i8] c"trace-it: couldnt stop tracing!\0A\00"
@.str.14 = [47 x i8] c"echo 0 > /proc/sys/kernel/trace_user_triggered\00"
@.str.15 = [40 x i8] c"echo 0 > /proc/sys/kernel/trace_enabled\00"
@.str.16 = [24 x i8] c"cat /proc/latency_trace\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @getuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 @system(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = tail call i32 @system(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @system(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%20 = tail call i32 @system(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%21 = tail call i32 @system(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%22 = tail call i32 @system(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0))
%23 = tail call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%24 = tail call i32 @system(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%25 = tail call i32 @system(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.11, i64 0, i64 0))
%26 = tail call i64 @prctl(i32 0, i32 1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0))
br label %42
31: ; preds = %16
%32 = tail call i32 @usleep(i32 10000000)
%33 = tail call i64 @prctl(i32 0, i32 0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0))
br label %42
38: ; preds = %31
%39 = tail call i32 @system(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.14, i64 0, i64 0))
%40 = tail call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.15, i64 0, i64 0))
%41 = tail call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0))
br label %42
42: ; preds = %38, %35, %28
%43 = phi i32 [ 1, %28 ], [ 1, %35 ], [ 0, %38 ]
ret i32 %43
}