#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 trace_seq {
  int dummy;
};
struct record {
  int dummy;
};
struct format_field {
  int dummy;
};
struct event_format {
  int dummy;
};

/* Variables and functions */
struct format_field *pevent_find_any_field(struct event_format *, char *);
scalar_t__ pevent_get_field_val(struct trace_seq *, struct event_format *,
                                char *, struct record *, unsigned long long *,
                                int);
int /*<<< orphan*/ trace_seq_printf(struct trace_seq *, char *,
                                    unsigned long long);
int trace_seq_putc(struct trace_seq *, char);
int /*<<< orphan*/ write_and_save_comm(struct format_field *, struct record *,
                                       struct trace_seq *, unsigned long long);
int sched_wakeup_handler(struct trace_seq *s, struct record *record,
                         struct event_format *event, void *context) {
  struct format_field *field;
  unsigned long long val;
  if (pevent_get_field_val(s, event, "pid", record, &val, 1))
    return trace_seq_putc(s, '!');
  field = pevent_find_any_field(event, "comm");
  if (field) {
    write_and_save_comm(field, record, s, val);
    trace_seq_putc(s, ':');
  }
  trace_seq_printf(s, "%lld", val);
  if (pevent_get_field_val(s, event, "prio", record, &val, 0) == 0)
    trace_seq_printf(s, " [%lld]", val);
  if (pevent_get_field_val(s, event, "success", record, &val, 1) == 0)
    trace_seq_printf(s, " success=%lld", val);
  if (pevent_get_field_val(s, event, "target_cpu", record, &val, 0) == 0)
    trace_seq_printf(s, " CPU:%03llu", val);
  return 0;
}


x86 assembly (clang, -O0):
<sched_wakeup_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe85(%rip),%rdx
lea    -0x38(%rbp),%r8
mov    $0x1,%r9d
call   1060 <pevent_get_field_val@plt>
cmp    $0x0,%rax
je     11aa <sched_wakeup_handler+0x5a>
mov    -0x10(%rbp),%rdi
mov    $0x21,%esi
call   1050 <trace_seq_putc@plt>
mov    %eax,-0x4(%rbp)
jmp    12c1 <sched_wakeup_handler+0x171>
mov    -0x20(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <pevent_find_any_field@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ec <sched_wakeup_handler+0x9c>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   1070 <write_and_save_comm@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <trace_seq_putc@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe2c(%rip),%rsi
call   1030 <trace_seq_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xdf6(%rip),%rdx
lea    -0x38(%rbp),%r8
xor    %r9d,%r9d
call   1060 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jne    123d <sched_wakeup_handler+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xdd6(%rip),%rsi
call   1030 <trace_seq_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xdc6(%rip),%rdx
lea    -0x38(%rbp),%r8
mov    $0x1,%r9d
call   1060 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jne    127d <sched_wakeup_handler+0x12d>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xda6(%rip),%rsi
call   1030 <trace_seq_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xd9c(%rip),%rdx
lea    -0x38(%rbp),%r8
xor    %r9d,%r9d
call   1060 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jne    12ba <sched_wakeup_handler+0x16a>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd82(%rip),%rsi
call   1030 <trace_seq_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sched_wakeup_handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe99(%rip),%rdx
mov    %rsp,%r8
mov    %r15,%rsi
mov    %r14,%rcx
mov    $0x1,%r9d
call   1060 <pevent_get_field_val@plt>
test   %rax,%rax
je     1194 <sched_wakeup_handler+0x44>
mov    %rbx,%rdi
mov    $0x21,%esi
call   1050 <trace_seq_putc@plt>
mov    %eax,%ebp
jmp    1278 <sched_wakeup_handler+0x128>
lea    0xe69(%rip),%rsi
mov    %r15,%rdi
call   1040 <pevent_find_any_field@plt>
test   %rax,%rax
je     11c7 <sched_wakeup_handler+0x77>
mov    (%rsp),%rcx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <write_and_save_comm@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <trace_seq_putc@plt>
mov    (%rsp),%rdx
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1030 <trace_seq_printf@plt>
lea    0xe28(%rip),%rdx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
xor    %r9d,%r9d
call   1060 <pevent_get_field_val@plt>
test   %rax,%rax
jne    120d <sched_wakeup_handler+0xbd>
mov    (%rsp),%rdx
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
call   1030 <trace_seq_printf@plt>
lea    0xe02(%rip),%rdx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    $0x1,%r9d
call   1060 <pevent_get_field_val@plt>
test   %rax,%rax
jne    1243 <sched_wakeup_handler+0xf3>
mov    (%rsp),%rdx
lea    0xde3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <trace_seq_printf@plt>
lea    0xde2(%rip),%rdx
mov    %rsp,%r8
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
xor    %r9d,%r9d
call   1060 <pevent_get_field_val@plt>
test   %rax,%rax
jne    1278 <sched_wakeup_handler+0x128>
mov    (%rsp),%rdx
lea    0xdc7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <trace_seq_printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
%struct.record = type { i32 }
%struct.event_format = type { i32 }
%struct.format_field = type { i32 }
@.str = [4 x i8] c"pid\00"
@.str.1 = [5 x i8] c"comm\00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [5 x i8] c"prio\00"
@.str.4 = [8 x i8] c" [%lld]\00"
@.str.5 = [8 x i8] c"success\00"
@.str.6 = [14 x i8] c" success=%lld\00"
@.str.7 = [11 x i8] c"target_cpu\00"
@.str.8 = [12 x i8] c" CPU:%03llu\00"
define i32 @sched_wakeup_handler(%struct.trace_seq* %0, %struct.record* %1, %struct.event_format* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.trace_seq*
%7 = alloca %struct.record*
%8 = alloca %struct.event_format*
%9 = alloca i8*
%10 = alloca %struct.format_field*
%11 = alloca i64
store %struct.trace_seq* %0, %struct.trace_seq** %6
store %struct.record* %1, %struct.record** %7
store %struct.event_format* %2, %struct.event_format** %8
store i8* %3, i8** %9
%12 = load %struct.trace_seq*, %struct.trace_seq** %6
%13 = load %struct.event_format*, %struct.event_format** %8
%14 = load %struct.record*, %struct.record** %7
%15 = call i64 @pevent_get_field_val(%struct.trace_seq* %12, %struct.event_format* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.record* %14, i64* %11, i32 1)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load %struct.trace_seq*, %struct.trace_seq** %6
%19 = call i32 @trace_seq_putc(%struct.trace_seq* %18, i8 signext 33)
store i32 %19, i32* %5
br label %67
20: ; preds = %4
%21 = load %struct.event_format*, %struct.event_format** %8
%22 = call %struct.format_field* @pevent_find_any_field(%struct.event_format* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store %struct.format_field* %22, %struct.format_field** %10
%23 = load %struct.format_field*, %struct.format_field** %10
%24 = icmp ne %struct.format_field* %23, null
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load %struct.format_field*, %struct.format_field** %10
%27 = load %struct.record*, %struct.record** %7
%28 = load %struct.trace_seq*, %struct.trace_seq** %6
%29 = load i64, i64* %11
%30 = call i32 @write_and_save_comm(%struct.format_field* %26, %struct.record* %27, %struct.trace_seq* %28, i64 %29)
%31 = load %struct.trace_seq*, %struct.trace_seq** %6
%32 = call i32 @trace_seq_putc(%struct.trace_seq* %31, i8 signext 58)
br label %33
33: ; preds = %25, %20
%34 = load %struct.trace_seq*, %struct.trace_seq** %6
%35 = load i64, i64* %11
%36 = call i32 @trace_seq_printf(%struct.trace_seq* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %35)
%37 = load %struct.trace_seq*, %struct.trace_seq** %6
%38 = load %struct.event_format*, %struct.event_format** %8
%39 = load %struct.record*, %struct.record** %7
%40 = call i64 @pevent_get_field_val(%struct.trace_seq* %37, %struct.event_format* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.record* %39, i64* %11, i32 0)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %33
%43 = load %struct.trace_seq*, %struct.trace_seq** %6
%44 = load i64, i64* %11
%45 = call i32 @trace_seq_printf(%struct.trace_seq* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %44)
br label %46
46: ; preds = %42, %33
%47 = load %struct.trace_seq*, %struct.trace_seq** %6
%48 = load %struct.event_format*, %struct.event_format** %8
%49 = load %struct.record*, %struct.record** %7
%50 = call i64 @pevent_get_field_val(%struct.trace_seq* %47, %struct.event_format* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %struct.record* %49, i64* %11, i32 1)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %46
%53 = load %struct.trace_seq*, %struct.trace_seq** %6
%54 = load i64, i64* %11
%55 = call i32 @trace_seq_printf(%struct.trace_seq* %53, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 %54)
br label %56
56: ; preds = %52, %46
%57 = load %struct.trace_seq*, %struct.trace_seq** %6
%58 = load %struct.event_format*, %struct.event_format** %8
%59 = load %struct.record*, %struct.record** %7
%60 = call i64 @pevent_get_field_val(%struct.trace_seq* %57, %struct.event_format* %58, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %struct.record* %59, i64* %11, i32 0)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %56
%63 = load %struct.trace_seq*, %struct.trace_seq** %6
%64 = load i64, i64* %11
%65 = call i32 @trace_seq_printf(%struct.trace_seq* %63, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i64 %64)
br label %66
66: ; preds = %62, %56
store i32 0, i32* %5
br label %67
67: ; preds = %66, %17
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.record = type { i32 }
%struct.event_format = type { i32 }
%struct.format_field = type { i32 }
@.str = [4 x i8] c"pid\00"
@.str.1 = [5 x i8] c"comm\00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [5 x i8] c"prio\00"
@.str.4 = [8 x i8] c" [%lld]\00"
@.str.5 = [8 x i8] c"success\00"
@.str.6 = [14 x i8] c" success=%lld\00"
@.str.7 = [11 x i8] c"target_cpu\00"
@.str.8 = [12 x i8] c" CPU:%03llu\00"
define i32 @sched_wakeup_handler(%struct.trace_seq* %0, %struct.record* %1, %struct.event_format* %2, i8* nocapture readnone %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.record* %1, i64* %5, i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 33)
br label %38
11: ; preds = %4
%12 = call %struct.format_field* @pevent_find_any_field(%struct.event_format* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq %struct.format_field* %12, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i64, i64* %5
%16 = call i32 @write_and_save_comm(%struct.format_field* %12, %struct.record* %1, %struct.trace_seq* %0, i64 %15)
%17 = call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 58)
br label %18
18: ; preds = %14, %11
%19 = load i64, i64* %5
%20 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.record* %1, i64* %5, i32 0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i64, i64* %5
%25 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %24)
br label %26
26: ; preds = %23, %18
%27 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %struct.record* %1, i64* %5, i32 1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i64, i64* %5
%31 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %29, %26
%33 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %struct.record* %1, i64* %5, i32 0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i64, i64* %5
%37 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i64 %36)
br label %38
38: ; preds = %32, %35, %9
%39 = phi i32 [ %10, %9 ], [ 0, %35 ], [ 0, %32 ]
ret i32 %39
}