#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[256];
  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;
  }
  strncpy(cur, msg, p1 - p2 + 1);
  cur = cur + (p1 - p2 + 1);
  snprintf(cur, strlen(keycat) + 5, "\t<%s>\t", keycat);
  cur = cur + (strlen(keycat) + 4);
  p1 += 1;
  n = snprintf(cur, p3 - p1, "%s", 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, 256 - (cur - &dst[0]), "%s", p3);
  strncpy(msg, dst, 256);
}


x86 assembly (clang, -O0):
<filt_f_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
movl   $0x0,-0x140(%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,-0x140(%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,-0x140(%rbp)
jmp    1256 <filt_f_message+0xf6>
cmpq   $0x0,-0x28(%rbp)
jne    1295 <filt_f_message+0x135>
mov    -0x8(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    0xd98(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x148(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x3,-0x140(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%eax
sub    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x138(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdx
sub    %rdx,%rax
lea    0x1(%rax,%rcx,1),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    %eax,%esi
add    $0x5,%esi
mov    -0x10(%rbp),%rcx
lea    0xd23(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x138(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x158(%rbp),%rcx
cltq
lea    0x4(%rax,%rcx,1),%rax
mov    %rax,-0x138(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    %ecx,%eax
sub    %eax,%esi
lea    0xcd4(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x138(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
lea    -0x1(%rax,%rcx,1),%rax
mov    %rax,-0x138(%rbp)
mov    -0x140(%rbp),%eax
mov    %eax,-0x14c(%rbp)
test   %eax,%eax
je     13ab <filt_f_message+0x24b>
jmp    1394 <filt_f_message+0x234>
mov    -0x14c(%rbp),%eax
add    $0xffffffff,%eax
sub    $0x2,%eax
jb     13cc <filt_f_message+0x26c>
jmp    13d1 <filt_f_message+0x271>
lea    0xc77(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    13e3 <filt_f_message+0x283>
jmp    13d1 <filt_f_message+0x271>
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x138(%rbp),%rcx
lea    -0x130(%rbp),%rax
sub    %rax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
lea    0xc16(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_f_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r15
mov    %rdi,%rbp
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    $0x3c,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
lea    0xe65(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     11b3 <filt_f_message+0x53>
mov    %rax,%r14
mov    $0x1,%al
mov    %eax,0x4(%rsp)
jmp    1212 <filt_f_message+0xb2>
mov    %rbp,%rdi
mov    $0x28,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1207 <filt_f_message+0xa7>
lea    0xe39(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
jne    11f1 <filt_f_message+0x91>
lea    0xe26(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     1300 <filt_f_message+0x1a0>
mov    %rax,%rdi
mov    $0x20,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     1300 <filt_f_message+0x1a0>
mov    %rax,%r14
movl   $0x0,0x4(%rsp)
mov    %r13,%r12
sub    %rbx,%r12
lea    0x1(%r12),%rdx
lea    0x10(%rsp),%rdi
mov    %rbp,0x8(%rsp)
mov    %rbp,%rsi
call   1030 <strncpy@plt>
lea    (%rsp,%r12,1),%rbx
add    $0x11,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x5(%rax),%esi
lea    0xdd4(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rcx
call   1060 <snprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rbp
lea    (%rax,%rbx,1),%rdi
add    $0x4,%rdi
add    $0x1,%r13
mov    %r14,%rbx
sub    %r13,%rbx
lea    0xda9(%rip),%rdx
mov    %ebx,%esi
mov    %r13,%rcx
call   1060 <snprintf@plt>
lea    (%rbx,%rbp,1),%r15
add    $0x3,%r15
cmpb   $0x0,0x4(%rsp)
je     12a7 <filt_f_message+0x147>
lea    0xd8c(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r14
jmp    12b7 <filt_f_message+0x157>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rbp
lea    0x10(%rsp),%rbx
mov    %ebx,%esi
sub    %r15d,%esi
add    $0x100,%esi
lea    0xd51(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rcx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd02(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
add    %rbp,%r14
jmp    120a <filt_f_message+0xaa>

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