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


x86 assembly (clang, -O0):
<filt_U_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x220(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     11d9 <filt_U_message+0x69>
cmpq   $0x0,-0x228(%rbp)
jne    11de <filt_U_message+0x6e>
jmp    12ce <filt_U_message+0x15e>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
lea    0xe09(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x228(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rdi
mov    $0x200,%esi
lea    0xdf1(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x22c(%rbp)
mov    -0x218(%rbp),%rax
movslq -0x22c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
mov    -0x220(%rbp),%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
mov    -0x218(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    -0x210(%rbp),%rax
add    $0x200,%rax
mov    -0x218(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x228(%rbp),%rcx
lea    0xd7b(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rsi
lea    0xd69(%rip),%rdi
call   1060 <printf@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_U_message>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
test   %rbx,%rbx
je     1239 <filt_U_message+0xc9>
mov    %rax,%r15
test   %rax,%rax
je     1239 <filt_U_message+0xc9>
add    $0x1,%rbx
lea    0xe41(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r15
lea    0xe46(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
movslq %eax,%r13
lea    (%rsp,%r13,1),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
lea    (%rsp,%r13,1),%rdi
add    $0x10,%rdi
mov    %r12d,%esi
sub    %edi,%esi
add    $0x200,%esi
lea    0xe0d(%rip),%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    0xe01(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"New USB device found,\00"
@.str.1 = [7 x i8] c"<SYS>\09\00"
@.str.2 = [21 x i8] c" Find USB device: %s\00"
@.str.3 = [8 x i8] c"msg:%s\0A\00"
define void @filt_U_message(i8* %0, i8* nocapture readnone %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 ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i8* %5, null
%8 = icmp ne i8* %6, null
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %28
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %6, i64 %13
%15 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %16
%18 = call i32 @memcpy(i8* %17, i8* %11, i32 16)
%19 = getelementptr inbounds i8, i8* %17, i64 16
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 512
%21 = ptrtoint i8* %20 to i64
%22 = ptrtoint i8* %19 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %19, i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%26 = call i32 @strncpy(i8* %0, i8* %4, i32 512)
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %2, %10
ret void
}