#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int snprintf(char *, int, char *, char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void filt_b_message(char *msg, char *keycat) {
  char *p1, *p2, *p3;
  char dst[512];
  char *cur = &dst[0], *pcur;
  int n, offset3;
  int check_EZP = 0;
  p1 = strchr(msg, '>') + 1;
  p2 = strchr(msg, '<');
  p3 = strstr(msg, "]: ");
  offset3 = strlen("]: ");
  if (!p3) {
    p3 = strstr(msg, ": ");
    offset3 = strlen(": ");
  }
  p3 += offset3;
  n = snprintf(cur, 512, "<%s>\t", keycat);
  cur = cur + n;
  memcpy(cur, p1, sizeof("Dec  8 11:12:58 ") - 1);
  cur = cur + (sizeof("Dec  8 11:12:58 ") - 1);
  n = snprintf(cur, 512 - (cur - &dst[0]), "%s", p3);
  strncpy(msg, dst, 512);
  printf("msg:%s\n", msg);
}


x86 assembly (clang, -O0):
<filt_b_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x238(%rbp)
movl   $0x0,-0x24c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1050 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
lea    0xe22(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x248(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121a <filt_b_message+0xaa>
mov    -0x8(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
lea    0xdf2(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x248(%rbp)
mov    -0x248(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x238(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x200,%esi
lea    0xdbf(%rip),%rdx
call   1070 <snprintf@plt>
mov    %eax,-0x244(%rbp)
mov    -0x238(%rbp),%rax
movslq -0x244(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
mov    -0x238(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rdi
mov    -0x238(%rbp),%rcx
lea    -0x230(%rbp),%rax
sub    %rax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
lea    0xd4e(%rip),%rdx
call   1070 <snprintf@plt>
mov    %eax,-0x244(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rsi
lea    0xd26(%rip),%rdi
call   1060 <printf@plt>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_b_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
lea    0xe65(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %r13,%r13
jne    11d3 <filt_b_message+0x63>
lea    0xe44(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x1,%r12
movslq %eax,%rbp
add    %r13,%rbp
lea    0xe20(%rip),%rdx
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x200,%esi
mov    %r15,%rcx
call   1070 <snprintf@plt>
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    %r13d,%esi
sub    %edi,%esi
add    $0x200,%esi
lea    0xde5(%rip),%rdx
mov    %rbp,%rcx
call   1070 <snprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    0xdc9(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"]: \00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [6 x i8] c"<%s>\09\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [8 x i8] c"msg:%s\0A\00"
define void @filt_b_message(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [512 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
store i8* %14, i8** %9
store i32 0, i32* %13
%15 = load i8*, i8** %3
%16 = call i8* @strchr(i8* %15, i8 signext 62)
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %5
%18 = load i8*, i8** %3
%19 = call i8* @strchr(i8* %18, i8 signext 60)
store i8* %19, i8** %6
%20 = load i8*, i8** %3
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %7
%22 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %12
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %29, label %25
25: ; preds = %2
%26 = load i8*, i8** %3
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %7
%28 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %28, i32* %12
br label %29
29: ; preds = %25, %2
%30 = load i32, i32* %12
%31 = load i8*, i8** %7
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %7
%34 = load i8*, i8** %9
%35 = load i8*, i8** %4
%36 = call i32 @snprintf(i8* %34, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %35)
store i32 %36, i32* %11
%37 = load i8*, i8** %9
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = load i8*, i8** %5
%43 = call i32 @memcpy(i8* %41, i8* %42, i32 16)
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i64 16
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = load i8*, i8** %9
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%49 = ptrtoint i8* %47 to i64
%50 = ptrtoint i8* %48 to i64
%51 = sub i64 %49, %50
%52 = sub nsw i64 512, %51
%53 = trunc i64 %52 to i32
%54 = load i8*, i8** %7
%55 = call i32 @snprintf(i8* %46, i32 %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %54)
store i32 %55, i32* %11
%56 = load i8*, i8** %3
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%58 = call i32 @strncpy(i8* %56, i8* %57, i32 512)
%59 = load i8*, i8** %3
%60 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"]: \00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [6 x i8] c"<%s>\09\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [8 x i8] c"msg:%s\0A\00"
define void @filt_b_message(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 62)
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %6, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %9, %2
%13 = phi i32 [ %7, %2 ], [ %11, %9 ]
%14 = phi i8* [ %6, %2 ], [ %10, %9 ]
%15 = getelementptr inbounds i8, i8* %5, i64 1
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = call i32 @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %19
%21 = call i32 @memcpy(i8* %20, i8* %15, i32 16)
%22 = getelementptr inbounds i8, i8* %20, i64 16
%23 = ptrtoint i8* %22 to i64
%24 = ptrtoint [512 x i8]* %3 to i64
%25 = sub i64 %24, %23
%26 = trunc i64 %25 to i32
%27 = add i32 %26, 512
%28 = call i32 @snprintf(i8* %22, i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%29 = call i32 @strncpy(i8* %0, i8* %4, i32 512)
%30 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %0)
ret void
}