#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 snprintf(char *, int, char *, char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *strstr(char *, char *);
void filt_f_message(char *msg, char *keycat) {
  char *p1, *p2, *p3;
  char dst[512];
  char *cur = &dst[0];
  int n;
  int check_EZP = 0;
  p1 = strchr(msg, '>');
  p2 = strchr(msg, '<');
  p3 = strstr(msg, "EZP_");
  if (!p3) {
    p3 = strstr(msg, "(");
    check_EZP = 1;
  }
  if (!p3) {
    p3 = strstr(msg, "]: ");
    if (!p3) {
      p3 = strstr(msg, ": ");
    }
    if (p3) {
      p3 = strrchr(p3, ' ');
      check_EZP = 2;
    }
  }
  if (!p3) {
    p3 = msg + strlen("<13>Jul 27 11:27:46");
    check_EZP = 3;
  }
  if (!p1 || !p3)
    return;
  snprintf(cur, strlen(keycat) + 4, "<%s>\t", keycat);
  cur = cur + (strlen(keycat) + 3);
  p1 += 1;
  strncpy(cur, p1, p3 - p1);
  cur = cur + (p3 - p1) - 1;
  switch (check_EZP) {
  case 0:
    p3 += strlen("EZP_XXX");
    break;
  case 1:
  case 2:
  default:
    p3 = strchr(p3, ':');
    break;
  }
  n = snprintf(cur, 512 - (cur - &dst[0]), "%s", p3);
  strncpy(msg, dst, 512);
}


x86 assembly (clang, -O0):
<filt_f_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x238(%rbp)
movl   $0x0,-0x240(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ec <filt_f_message+0x8c>
mov    -0x8(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x240(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1256 <filt_f_message+0xf6>
mov    -0x8(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122a <filt_f_message+0xca>
mov    -0x8(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1251 <filt_f_message+0xf1>
mov    -0x28(%rbp),%rdi
mov    $0x20,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x240(%rbp)
jmp    1256 <filt_f_message+0xf6>
cmpq   $0x0,-0x28(%rbp)
jne    1295 <filt_f_message+0x135>
mov    -0x8(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    0xd98(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x248(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x3,-0x240(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12ab <filt_f_message+0x14b>
cmpq   $0x0,-0x28(%rbp)
jne    12b0 <filt_f_message+0x150>
jmp    1405 <filt_f_message+0x2a5>
mov    -0x238(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x260(%rbp),%rdi
mov    %eax,%esi
add    $0x4,%esi
mov    -0x10(%rbp),%rcx
lea    0xd41(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x238(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x258(%rbp),%rcx
cltq
lea    0x3(%rax,%rcx,1),%rax
mov    %rax,-0x238(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x238(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    %esi,%eax
sub    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x238(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
lea    -0x1(%rax,%rcx,1),%rax
mov    %rax,-0x238(%rbp)
mov    -0x240(%rbp),%eax
mov    %eax,-0x24c(%rbp)
test   %eax,%eax
je     1380 <filt_f_message+0x220>
jmp    1369 <filt_f_message+0x209>
mov    -0x24c(%rbp),%eax
add    $0xffffffff,%eax
sub    $0x2,%eax
jb     13a1 <filt_f_message+0x241>
jmp    13a6 <filt_f_message+0x246>
lea    0xc9e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    13b8 <filt_f_message+0x258>
jmp    13a6 <filt_f_message+0x246>
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%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    0xc48(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x23c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_f_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
lea    0xe75(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     11a7 <filt_f_message+0x47>
mov    %rax,%rbp
mov    $0x1,%al
test   %r12,%r12
jne    1209 <filt_f_message+0xa9>
jmp    12c5 <filt_f_message+0x165>
mov    %r14,%rdi
mov    $0x28,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    11fb <filt_f_message+0x9b>
lea    0xe45(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
jne    11e5 <filt_f_message+0x85>
lea    0xe32(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     12d7 <filt_f_message+0x177>
mov    %rax,%rdi
mov    $0x20,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     12d7 <filt_f_message+0x177>
mov    %rax,%rbp
xor    %eax,%eax
test   %r12,%r12
je     12c5 <filt_f_message+0x165>
test   %rbp,%rbp
je     12c5 <filt_f_message+0x165>
mov    %r15,%rdi
mov    %eax,0xc(%rsp)
call   1040 <strlen@plt>
lea    0x4(%rax),%esi
lea    0xdf5(%rip),%rdx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    %r15,%rcx
call   1060 <snprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r13,1),%r15
lea    (%rax,%r13,1),%rdi
add    $0x3,%rdi
add    $0x1,%r12
mov    %rbp,%rbx
sub    %r12,%rbx
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
add    %rbx,%r15
add    $0x2,%r15
cmpb   $0x0,0xc(%rsp)
je     1283 <filt_f_message+0x123>
lea    0xdac(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbp
jmp    1293 <filt_f_message+0x133>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
lea    0x10(%rsp),%rbx
mov    %ebx,%esi
sub    %r15d,%esi
add    $0x200,%esi
lea    0xd81(%rip),%rdx
mov    %r15,%rdi
mov    %rbp,%rcx
call   1060 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2b(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rbp
add    %r14,%rbp
jmp    11fe <filt_f_message+0x9e>

LLVM IR (-O0):
@.str = [5 x i8] c"EZP_\00"
@.str.1 = [2 x i8] c"(\00"
@.str.2 = [4 x i8] c"]: \00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [20 x i8] c"<13>Jul 27 11:27:46\00"
@.str.5 = [6 x i8] c"<%s>\09\00"
@.str.6 = [8 x i8] c"EZP_XXX\00"
@.str.7 = [3 x i8] c"%s\00"
define void @filt_f_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 i32
%11 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
store i8* %12, i8** %9
store i32 0, i32* %11
%13 = load i8*, i8** %3
%14 = call i8* @strchr(i8* %13, i8 signext 62)
store i8* %14, i8** %5
%15 = load i8*, i8** %3
%16 = call i8* @strchr(i8* %15, i8 signext 60)
store i8* %16, i8** %6
%17 = load i8*, i8** %3
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %7
store i32 1, i32* %11
br label %24
24: ; preds = %21, %2
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %42, label %27
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = call i8* @strstr(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i8*, i8** %3
%34 = call i8* @strstr(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %34, i8** %7
br label %35
35: ; preds = %32, %27
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %7
%40 = call i8* @strrchr(i8* %39, i8 signext 32)
store i8* %40, i8** %7
store i32 2, i32* %11
br label %41
41: ; preds = %38, %35
br label %42
42: ; preds = %41, %24
%43 = load i8*, i8** %7
%44 = icmp ne i8* %43, null
br i1 %44, label %50, label %45
45: ; preds = %42
%46 = load i8*, i8** %3
%47 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8* %49, i8** %7
store i32 3, i32* %11
br label %50
50: ; preds = %45, %42
%51 = load i8*, i8** %5
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8*, i8** %7
%55 = icmp ne i8* %54, null
br i1 %55, label %57, label %56
56: ; preds = %53, %50
br label %113
57: ; preds = %53
%58 = load i8*, i8** %9
%59 = load i8*, i8** %4
%60 = call i32 @strlen(i8* %59)
%61 = add nsw i32 %60, 4
%62 = load i8*, i8** %4
%63 = call i32 @snprintf(i8* %58, i32 %61, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %62)
%64 = load i8*, i8** %9
%65 = load i8*, i8** %4
%66 = call i32 @strlen(i8* %65)
%67 = add nsw i32 %66, 3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %64, i64 %68
store i8* %69, i8** %9
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8* %71, i8** %5
%72 = load i8*, i8** %9
%73 = load i8*, i8** %5
%74 = load i8*, i8** %7
%75 = load i8*, i8** %5
%76 = ptrtoint i8* %74 to i64
%77 = ptrtoint i8* %75 to i64
%78 = sub i64 %76, %77
%79 = trunc i64 %78 to i32
%80 = call i32 @strncpy(i8* %72, i8* %73, i32 %79)
%81 = load i8*, i8** %9
%82 = load i8*, i8** %7
%83 = load i8*, i8** %5
%84 = ptrtoint i8* %82 to i64
%85 = ptrtoint i8* %83 to i64
%86 = sub i64 %84, %85
%87 = getelementptr inbounds i8, i8* %81, i64 %86
%88 = getelementptr inbounds i8, i8* %87, i64 -1
store i8* %88, i8** %9
%89 = load i32, i32* %11
switch i32 %89, label %96 [
i32 0, label %90
i32 1, label %95
i32 2, label %95
]
90: ; preds = %57
%91 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%92 = load i8*, i8** %7
%93 = sext i32 %91 to i64
%94 = getelementptr inbounds i8, i8* %92, i64 %93
store i8* %94, i8** %7
br label %99
95: ; preds = %57, %57
br label %96
96: ; preds = %57, %95
%97 = load i8*, i8** %7
%98 = call i8* @strchr(i8* %97, i8 signext 58)
store i8* %98, i8** %7
br label %99
99: ; preds = %96, %90
%100 = load i8*, i8** %9
%101 = load i8*, i8** %9
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%103 = ptrtoint i8* %101 to i64
%104 = ptrtoint i8* %102 to i64
%105 = sub i64 %103, %104
%106 = sub nsw i64 512, %105
%107 = trunc i64 %106 to i32
%108 = load i8*, i8** %7
%109 = call i32 @snprintf(i8* %100, i32 %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %108)
store i32 %109, i32* %10
%110 = load i8*, i8** %3
%111 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%112 = call i32 @strncpy(i8* %110, i8* %111, i32 512)
br label %113
113: ; preds = %99, %56
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"EZP_\00"
@.str.2 = [4 x i8] c"]: \00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [20 x i8] c"<13>Jul 27 11:27:46\00"
@.str.5 = [6 x i8] c"<%s>\09\00"
@.str.6 = [8 x i8] c"EZP_XXX\00"
@.str.7 = [3 x i8] c"%s\00"
define void @filt_f_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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %25
8: ; preds = %2
%9 = tail call i8* bitcast (i8* (i8*, i8)* @strchr to i8* (i8*, i32)*)(i8* %0, i32 40)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %11, %14
%18 = phi i8* [ %15, %14 ], [ %12, %11 ]
%19 = tail call i8* @strrchr(i8* %18, i8 signext 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %14, %17
%22 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
br label %25
25: ; preds = %2, %8, %21, %17
%26 = phi i8* [ %19, %17 ], [ %24, %21 ], [ %9, %8 ], [ %6, %2 ]
%27 = phi i1 [ false, %17 ], [ false, %21 ], [ false, %8 ], [ true, %2 ]
%28 = icmp ne i8* %5, null
%29 = icmp ne i8* %26, null
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %31, label %62
31: ; preds = %25
%32 = tail call i32 @strlen(i8* %1)
%33 = add nsw i32 %32, 4
%34 = call i32 @snprintf(i8* %4, i32 %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%35 = call i32 @strlen(i8* %1)
%36 = add nsw i32 %35, 3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %37
%39 = getelementptr inbounds i8, i8* %5, i64 1
%40 = ptrtoint i8* %26 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
%44 = call i32 @strncpy(i8* %38, i8* %39, i32 %43)
%45 = getelementptr inbounds i8, i8* %38, i64 %42
%46 = getelementptr inbounds i8, i8* %45, i64 -1
br i1 %27, label %47, label %51
47: ; preds = %31
%48 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %26, i64 %49
br label %53
51: ; preds = %31
%52 = call i8* @strchr(i8* %26, i8 signext 58)
br label %53
53: ; preds = %51, %47
%54 = phi i8* [ %50, %47 ], [ %52, %51 ]
%55 = ptrtoint i8* %46 to i64
%56 = ptrtoint [512 x i8]* %3 to i64
%57 = sub i64 %56, %55
%58 = trunc i64 %57 to i32
%59 = add i32 %58, 512
%60 = call i32 @snprintf(i8* %46, i32 %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%61 = call i32 @strncpy(i8* %0, i8* %4, i32 512)
br label %62
62: ; preds = %25, %53
ret void
}