#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*/ dump_file_content(char *);
int /*<<< orphan*/ free(char *);
char *get_event_file(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int event_filter_write(char *buf, int len) {
  char *file;
  if (buf[len - 1] == '\n')
    buf[len - 1] = '\0';
  printf("%s\n", buf);
  file = get_event_file("filter", buf, len);
  dump_file_content(file);
  free(file);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<event_filter_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    117a <event_filter_write+0x3a>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe6a(%rip),%rdi
call   1040 <get_event_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <dump_file_content@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_filter_write>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movslq %esi,%rax
cmpb   $0xa,-0x1(%rax,%rdi,1)
jne    1167 <event_filter_write+0x17>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xe8a(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <get_event_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <dump_file_content@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [7 x i8] c"filter\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @event_filter_write(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %14, %2
%21 = load i8*, i8** %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = call i8* @get_event_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %24)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = call i32 @dump_file_content(i8* %26)
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"filter\00"
define i32 @event_filter_write(i8* %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 10
br i1 %7, label %8, label %9
8: ; preds = %2
store i8 0, i8* %5
br label %9
9: ; preds = %8, %2
%10 = tail call i32 @puts(i8* dereferenceable(1) %0)
%11 = tail call i8* @get_event_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1)
%12 = tail call i32 @dump_file_content(i8* %11)
%13 = tail call i32 @free(i8* %11)
%14 = tail call i32 @putchar(i32 10)
ret i32 0
}