#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ read_int(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ verbose_printf(int, char *, int);
scalar_t__ write_int(char *, int);
int idlestat_init_trace(unsigned int percpu_bufsize) {
  int bufsize = (int)percpu_bufsize;
  if (write_int("/sys/kernel/debug/tracing"
                "/buffer_size_kb",
                bufsize)) {
    fprintf(stderr, "Failed to set trace buffer to desired size. If the "
                    "error was caused by failure in memory allocation, "
                    "try to increase buffer size (-S, --buffer-size) "
                    "or decrease polling interval "
                    "(-I, --polling-interval).\n"
                    "Increase verbosity (-v) to see current values\n");
    return -1;
  }
  if (read_int("/sys/kernel/debug/tracing"
               "/buffer_total_size_kb",
               &bufsize))
    return -1;
  verbose_printf(1, "Total trace buffer:   %d kB\n", bufsize);
  if (write_int("/sys/kernel/debug/tracing"
                "/events/enable",
                0))
    return -1;
  if (write_int("/sys/kernel/debug/tracing"
                "/events/power/cpu_idle/enable",
                1))
    return -1;
  if (write_int("/sys/kernel/debug/tracing"
                "/events/power/cpu_frequency/enable",
                1))
    return -1;
  if (write_int("/sys/kernel/debug/tracing"
                "/events/irq/irq_handler_entry/enable",
                1))
    return -1;
  write_int("/sys/kernel/debug/tracing"
            "/events/ipi/ipi_entry/enable",
            1);
  return 0;
}


x86 assembly (clang, -O0):
<idlestat_init_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea5(%rip),%rdi
call   1040 <write_int@plt>
cmp    $0x0,%rax
je     118b <idlestat_init_trace+0x4b>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <idlestat_init_trace+0x136>
lea    0xf92(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <read_int@plt>
cmp    $0x0,%rax
je     11b1 <idlestat_init_trace+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <idlestat_init_trace+0x136>
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
lea    0xf93(%rip),%rsi
call   1030 <verbose_printf@plt>
lea    0xfa4(%rip),%rdi
xor    %esi,%esi
call   1040 <write_int@plt>
cmp    $0x0,%rax
je     11e9 <idlestat_init_trace+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <idlestat_init_trace+0x136>
lea    0xfa8(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
cmp    $0x0,%rax
je     1210 <idlestat_init_trace+0xd0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <idlestat_init_trace+0x136>
lea    0xfb8(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
cmp    $0x0,%rax
je     1237 <idlestat_init_trace+0xf7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <idlestat_init_trace+0x136>
lea    0xfcd(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
cmp    $0x0,%rax
je     125e <idlestat_init_trace+0x11e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <idlestat_init_trace+0x136>
lea    0xfe4(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idlestat_init_trace>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%esi
mov    %edi,0xc(%rsp)
lea    0xeae(%rip),%rdi
call   1040 <write_int@plt>
test   %rax,%rax
je     117b <idlestat_init_trace+0x3b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1213 <idlestat_init_trace+0xd3>
lea    0xfa2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <read_int@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1213 <idlestat_init_trace+0xd3>
mov    0xc(%rsp),%edx
lea    0xfb2(%rip),%rsi
mov    $0x1,%edi
call   1030 <verbose_printf@plt>
lea    0xfbe(%rip),%rdi
xor    %esi,%esi
call   1040 <write_int@plt>
test   %rax,%rax
jne    1213 <idlestat_init_trace+0xd3>
lea    0xfd3(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
test   %rax,%rax
jne    1213 <idlestat_init_trace+0xd3>
lea    0xff4(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
test   %rax,%rax
jne    1213 <idlestat_init_trace+0xd3>
lea    0x101a(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
test   %rax,%rax
jne    1213 <idlestat_init_trace+0xd3>
lea    0x1042(%rip),%rdi
mov    $0x1,%esi
call   1040 <write_int@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/kernel/debug/tracing/buffer_size_kb\00"
@stderr = global i32 0
@.str.1 = [251 x i8] c"Failed to set trace buffer to desired size. If the error was caused by failure in memory allocation, try to increase buffer size (-S, --buffer-size) or decrease polling interval (-I, --polling-interval).\0AIncrease verbosity (-v) to see current values\0A\00"
@.str.2 = [47 x i8] c"/sys/kernel/debug/tracing/buffer_total_size_kb\00"
@.str.3 = [29 x i8] c"Total trace buffer: %d kB\0A\00"
@.str.4 = [40 x i8] c"/sys/kernel/debug/tracing/events/enable\00"
@.str.5 = [55 x i8] c"/sys/kernel/debug/tracing/events/power/cpu_idle/enable\00"
@.str.6 = [60 x i8] c"/sys/kernel/debug/tracing/events/power/cpu_frequency/enable\00"
@.str.7 = [62 x i8] c"/sys/kernel/debug/tracing/events/irq/irq_handler_entry/enable\00"
@.str.8 = [54 x i8] c"/sys/kernel/debug/tracing/events/ipi/ipi_entry/enable\00"
define i32 @idlestat_init_trace(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = call i64 @write_int(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %36
12: ; preds = %1
%13 = call i64 @read_int(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %2
br label %36
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @verbose_printf(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i64 @write_int(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 0)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %2
br label %36
22: ; preds = %16
%23 = call i64 @write_int(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i32 1)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 -1, i32* %2
br label %36
26: ; preds = %22
%27 = call i64 @write_int(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i32 1)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %2
br label %36
30: ; preds = %26
%31 = call i64 @write_int(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.7, i64 0, i64 0), i32 1)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 -1, i32* %2
br label %36
34: ; preds = %30
%35 = call i64 @write_int(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i32 1)
store i32 0, i32* %2
br label %36
36: ; preds = %34, %33, %29, %25, %21, %15, %9
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/kernel/debug/tracing/buffer_size_kb\00"
@stderr = global i32 0
@.str.1 = [251 x i8] c"Failed to set trace buffer to desired size. If the error was caused by failure in memory allocation, try to increase buffer size (-S, --buffer-size) or decrease polling interval (-I, --polling-interval).\0AIncrease verbosity (-v) to see current values\0A\00"
@.str.2 = [47 x i8] c"/sys/kernel/debug/tracing/buffer_total_size_kb\00"
@.str.3 = [29 x i8] c"Total trace buffer: %d kB\0A\00"
@.str.4 = [40 x i8] c"/sys/kernel/debug/tracing/events/enable\00"
@.str.5 = [55 x i8] c"/sys/kernel/debug/tracing/events/power/cpu_idle/enable\00"
@.str.6 = [60 x i8] c"/sys/kernel/debug/tracing/events/power/cpu_frequency/enable\00"
@.str.7 = [62 x i8] c"/sys/kernel/debug/tracing/events/irq/irq_handler_entry/enable\00"
@.str.8 = [54 x i8] c"/sys/kernel/debug/tracing/events/ipi/ipi_entry/enable\00"
define i32 @idlestat_init_trace(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 %0, i32* %2
%4 = tail call i64 @write_int(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str.1, i64 0, i64 0))
br label %28
9: ; preds = %1
%10 = call i64 @read_int(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i32 @verbose_printf(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i64 @write_int(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = call i64 @write_int(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = call i64 @write_int(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = call i64 @write_int(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.7, i64 0, i64 0), i32 1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i64 @write_int(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %28
28: ; preds = %23, %20, %17, %12, %9, %26, %6
%29 = phi i32 [ -1, %6 ], [ 0, %26 ], [ -1, %9 ], [ -1, %12 ], [ -1, %17 ], [ -1, %20 ], [ -1, %23 ]
ret i32 %29
}