#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 *);
char *strchr(char *, char);
int strlen(char *);
char *strstr(char *, char *);
void filt_u_message(char *msg, char *keycat) {
  char *cur = msg;
  char *p1, *p2, *p3;
  p1 = strchr(cur, '>');
  p3 = strstr(cur, "Product:");
  if (!p1 || !p3)
    return;
  p1 += 1;
  p2 = p1 + strlen("Jul 27 14:50:37 ");
  snprintf(cur, p2 - p1, "%s", p1);
  cur += p2 - p1;
  p3 += strlen("Product:");
  snprintf(cur - 1, msg + 256 - cur, " Find USB device: %s", p3);
}


x86 assembly (clang, -O0):
<filt_u_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)
mov    -0x18(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1194 <filt_u_message+0x54>
cmpq   $0x0,-0x30(%rbp)
jne    1199 <filt_u_message+0x59>
jmp    1244 <filt_u_message+0x104>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe55(%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    0xe47(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xdfc(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%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
mov    -0x30(%rbp),%rcx
lea    0xddb(%rip),%rdx
call   1050 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_u_message>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x3e,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
lea    0xea1(%rip),%rsi
mov    %r15,%rdi
call   1060 <strstr@plt>
test   %rbx,%rbx
je     11d7 <filt_u_message+0x97>
mov    %rax,%r14
test   %rax,%rax
je     11d7 <filt_u_message+0x97>
add    $0x1,%rbx
lea    0xe8a(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%r12
lea    0xe9e(%rip),%rdx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
lea    0xe5d(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r14
lea    (%r15,%r12,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    $0x100,%esi
sub    %r12d,%esi
lea    0xe56(%rip),%rdx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <snprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Product:\00"
@.str.1 = [17 x i8] c"Jul 27 14:50:37 \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [21 x i8] c" Find USB device: %s\00"
define void @filt_u_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** %5
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16, %2
br label %58
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8* %26, i8** %7
%27 = load i8*, i8** %5
%28 = load i8*, i8** %7
%29 = load i8*, i8** %6
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = trunc i64 %32 to i32
%34 = load i8*, i8** %6
%35 = call i32 @snprintf(i8* %27, i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %7
%37 = load i8*, i8** %6
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 %40
store i8* %42, i8** %5
%43 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%44 = load i8*, i8** %8
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %8
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i64 -1
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 256
%51 = load i8*, i8** %5
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = trunc i64 %54 to i32
%56 = load i8*, i8** %8
%57 = call i32 @snprintf(i8* %48, i32 %55, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %20, %19
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"Product:\00"
@.str.1 = [17 x i8] c"Jul 27 14:50:37 \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [21 x i8] c" Find USB device: %s\00"
define void @filt_u_message(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 62)
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i8* %3, null
%6 = icmp ne i8* %4, null
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = tail call i32 @snprintf(i8* %0, i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
%17 = getelementptr inbounds i8, i8* %13, i64 -1
%18 = sub i32 256, %10
%19 = tail call i32 @snprintf(i8* %17, i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %20
20: ; preds = %2, %8
ret void
}