#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*/ snprintf(char *, int, char *, ...);
char *strchr(char *, char);
int strlen(char *);
void filt_p_message(char *msg, char *keycat) {
  char *cur = msg;
  char *p1, *p2, *p3;
  p1 = strchr(cur, '>');
  if (!p1)
    return;
  p1 += 1;
  p2 = p1 + strlen("Jul 27 14:50:37 ");
  snprintf(cur, p2 - p1, "%s", p1);
  cur += p2 - p1;
  snprintf(cur - 1, msg + 256 - cur, " PPPoE Password Error\n");
}


x86 assembly (clang, -O0):
<filt_p_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116a <filt_p_message+0x3a>
jmp    11f9 <filt_p_message+0xc9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe7b(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
lea    0xe5b(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x8(%rbp),%rax
add    $0x100,%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe22(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_p_message>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x3e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1197 <filt_p_message+0x67>
mov    %rax,%rbx
add    $0x1,%rbx
lea    0xeab(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
lea    0xead(%rip),%rdx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    (%r14,%r15,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    $0x100,%esi
sub    %r15d,%esi
lea    0xe89(%rip),%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <snprintf@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Jul 27 14:50:37 \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [23 x i8] c" PPPoE Password Error\0A\00"
define void @filt_p_message(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i8* @strchr(i8* %10, i8 signext 62)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
br label %48
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8* %21, i8** %7
%22 = load i8*, i8** %5
%23 = load i8*, i8** %7
%24 = load i8*, i8** %6
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = load i8*, i8** %6
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %22, i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %7
%32 = load i8*, i8** %6
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 %35
store i8* %37, i8** %5
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 -1
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i64 256
%42 = load i8*, i8** %5
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = trunc i64 %45 to i32
%47 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %39, i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Jul 27 14:50:37 \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [23 x i8] c" PPPoE Password Error\0A\00"
define void @filt_p_message(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 62)
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = sub i32 256, %7
%13 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %2, %5
ret void
}