#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ cover_start();
int /*<<< orphan*/ cover_stop();
int /*<<< orphan*/ fail(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char const *, int);
void trace_filter(const char *data, long size) {
  int fd0 = open(
      "/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/enable", O_RDWR);
  if (fd0 == -1)
    fail("open enable failed");
  int fd1 = open(
      "/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/filter", O_RDWR);
  if (fd1 == -1)
    fail("open filter failed");
  int fd2 =
      open("/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger",
           O_RDWR);
  if (fd2 == -1)
    fail("open trigger failed");
  cover_start();
  char buf[256];
  buf[0] = '1';
  write(fd0, buf, 1);
  write(fd1, data, size);
  read(fd1, buf, sizeof(buf));
  buf[0] = '0';
  write(fd1, buf, 1);
  write(fd2, data, size);
  read(fd2, buf, sizeof(buf));
  buf[0] = '0';
  write(fd0, buf, 1);
  cover_stop();
  close(fd0);
  close(fd1);
  close(fd2);
}


x86 assembly (clang, -O0):
<trace_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b1 <trace_filter+0x41>
lea    0xe93(%rip),%rdi
call   1040 <fail@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11df <trace_filter+0x6f>
lea    0xeb7(%rip),%rdi
call   1040 <fail@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    120d <trace_filter+0x9d>
lea    0xedc(%rip),%rdi
call   1040 <fail@plt>
mov    $0x0,%al
call   1070 <cover_start@plt>
movb   $0x31,-0x120(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
movb   $0x30,-0x120(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
movb   $0x30,-0x120(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x0,%al
call   1090 <cover_stop@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_filter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e5a(%rip),%rbx
mov    (%rbx),%esi
lea    0xe69(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    11b0 <trace_filter+0x40>
lea    0xe94(%rip),%rdi
call   1040 <fail@plt>
mov    (%rbx),%esi
lea    0xe99(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11d1 <trace_filter+0x61>
lea    0xec5(%rip),%rdi
call   1040 <fail@plt>
mov    (%rbx),%esi
lea    0xeca(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11f2 <trace_filter+0x82>
lea    0xef7(%rip),%rdi
call   1040 <fail@plt>
xor    %eax,%eax
call   1070 <cover_start@plt>
movb   $0x31,(%rsp)
mov    %rsp,%r13
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
movb   $0x30,(%rsp)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
movb   $0x30,(%rsp)
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1090 <cover_stop@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/enable\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"open enable failed\00"
@.str.2 = [63 x i8] c"/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/filter\00"
@.str.3 = [19 x i8] c"open filter failed\00"
@.str.4 = [64 x i8] c"/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger\00"
@.str.5 = [20 x i8] c"open trigger failed\00"
define void @trace_filter(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [256 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @fail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @fail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i32, i32* @O_RDWR
%24 = call i32 @open(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0), i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @fail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = call i32 (...) @cover_start()
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8 49, i8* %31
%32 = load i32, i32* %5
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%34 = call i32 @write(i32 %32, i8* %33, i32 1)
%35 = load i32, i32* %6
%36 = load i8*, i8** %3
%37 = load i64, i64* %4
%38 = trunc i64 %37 to i32
%39 = call i32 @write(i32 %35, i8* %36, i32 %38)
%40 = load i32, i32* %6
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 256)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8 48, i8* %43
%44 = load i32, i32* %6
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%46 = call i32 @write(i32 %44, i8* %45, i32 1)
%47 = load i32, i32* %7
%48 = load i8*, i8** %3
%49 = load i64, i64* %4
%50 = trunc i64 %49 to i32
%51 = call i32 @write(i32 %47, i8* %48, i32 %50)
%52 = load i32, i32* %7
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 256)
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8 48, i8* %55
%56 = load i32, i32* %5
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%58 = call i32 @write(i32 %56, i8* %57, i32 1)
%59 = call i32 (...) @cover_stop()
%60 = load i32, i32* %5
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* %7
%65 = call i32 @close(i32 %64)
ret void
}

LLVM IR (-O2):
@.str = [63 x i8] c"/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/enable\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"open enable failed\00"
@.str.2 = [63 x i8] c"/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/filter\00"
@.str.3 = [19 x i8] c"open filter failed\00"
@.str.4 = [64 x i8] c"/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger\00"
@.str.5 = [20 x i8] c"open trigger failed\00"
define void @trace_filter(i8* nocapture %0, i64 %1) {
%3 = alloca [256 x i8]
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @fail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @fail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* @O_RDWR
%17 = tail call i32 @open(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @fail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = tail call i32 (...) @cover_start()
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8 49, i8* %23
%24 = call i32 @write(i32 %5, i8* %23, i32 1)
%25 = trunc i64 %1 to i32
%26 = tail call i32 @write(i32 %11, i8* %0, i32 %25)
%27 = call i32 @read(i32 %11, i8* %23, i32 256)
store i8 48, i8* %23
%28 = call i32 @write(i32 %11, i8* %23, i32 1)
%29 = tail call i32 @write(i32 %17, i8* %0, i32 %25)
%30 = call i32 @read(i32 %17, i8* %23, i32 256)
store i8 48, i8* %23
%31 = call i32 @write(i32 %5, i8* %23, i32 1)
%32 = tail call i32 (...) @cover_stop()
%33 = tail call i32 @close(i32 %5)
%34 = tail call i32 @close(i32 %11)
%35 = tail call i32 @close(i32 %17)
ret void
}