#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 */
typedef int /*<<< orphan*/ wan_status;

/* Variables and functions */
int /*<<< orphan*/ ezplib_get_attr_val(char *, int /*<<< orphan*/, char *,
                                       char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ ezplib_replace_attr(char *, int /*<<< orphan*/, char *,
                                       char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int snprintf(char *, int, char *, ...);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void filt_w_message(char *msg, char *keycat) {
  char dst[512], wan_status[512];
  char *cur = &dst[0];
  char *p1, *p3;
  int n;
  p1 = strchr(msg, '>');
  p3 = strstr(msg, "WIFIConnect");
  if (!p1 || !p3)
    return;
  p1 += 1;
  p3 += strlen("WIFIConnect");
  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, "WIFI Connect: %s", p3);
  strncpy(msg, dst, 512);
  if (strstr(p3, "wrong") || strstr(p3, "encryption")) {
    ezplib_get_attr_val("wan_status_rule", 0, "state", wan_status,
                        sizeof(wan_status), 0);
    if (!strcmp(wan_status, "0") || !strcmp(wan_status, "1"))
      ezplib_replace_attr("plug_rule", 0, "wisp", "1");
  }
  printf("msg:%s\n", msg);
}


x86 assembly (clang, -O0):
<filt_w_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1060 <strchr@plt>
mov    %rax,-0x420(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   10c0 <strstr@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     1209 <filt_w_message+0x69>
cmpq   $0x0,-0x428(%rbp)
jne    120e <filt_w_message+0x6e>
jmp    13b7 <filt_w_message+0x217>
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
lea    0xdd9(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x428(%rbp)
mov    -0x418(%rbp),%rdi
mov    $0x200,%esi
lea    0xdb7(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x418(%rbp),%rax
movslq -0x42c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
mov    -0x420(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <memcpy@plt>
mov    -0x418(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
lea    -0x210(%rbp),%rax
add    $0x200,%rax
mov    -0x418(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x428(%rbp),%rcx
lea    0xd41(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <strncpy@plt>
mov    -0x428(%rbp),%rdi
lea    0xd28(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
jne    1328 <filt_w_message+0x188>
mov    -0x428(%rbp),%rdi
lea    0xd11(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     13a7 <filt_w_message+0x207>
lea    -0x410(%rbp),%rcx
lea    0xcff(%rip),%rdi
xor    %r9d,%r9d
lea    0xd05(%rip),%rdx
mov    $0x200,%r8d
mov    %r9d,%esi
call   1030 <ezplib_get_attr_val@plt>
lea    -0x410(%rbp),%rdi
lea    0xcef(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     1386 <filt_w_message+0x1e6>
lea    -0x410(%rbp),%rdi
lea    0xcd5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    13a2 <filt_w_message+0x202>
lea    0xcc2(%rip),%rdi
xor    %esi,%esi
lea    0xcc3(%rip),%rdx
lea    0xcb0(%rip),%rcx
call   1090 <ezplib_replace_attr@plt>
jmp    13a7 <filt_w_message+0x207>
mov    -0x8(%rbp),%rsi
lea    0xcac(%rip),%rdi
call   1070 <printf@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_w_message>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    $0x3e,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strstr@plt>
test   %rbx,%rbx
je     12d4 <filt_w_message+0x144>
mov    %rax,%r15
test   %rax,%rax
je     12d4 <filt_w_message+0x144>
add    $0x1,%rbx
lea    0xe21(%rip),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%r15
lea    0xe1c(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1080 <snprintf@plt>
movslq %eax,%r13
lea    (%rsp,%r13,1),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   10a0 <memcpy@plt>
lea    (%rsp,%r13,1),%rdi
add    $0x10,%rdi
mov    %r12d,%esi
sub    %edi,%esi
add    $0x200,%esi
lea    0xde3(%rip),%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x200,%edx
call   1040 <strncpy@plt>
lea    0xdd3(%rip),%rsi
mov    %r15,%rdi
call   10b0 <strstr@plt>
test   %rax,%rax
jne    1272 <filt_w_message+0xe2>
lea    0xdc5(%rip),%rsi
mov    %r15,%rdi
call   10b0 <strstr@plt>
test   %rax,%rax
je     12c5 <filt_w_message+0x135>
lea    0xdbc(%rip),%rdi
lea    0xdc5(%rip),%rdx
lea    0x200(%rsp),%rcx
xor    %esi,%esi
mov    $0x200,%r8d
xor    %r9d,%r9d
call   1030 <ezplib_get_attr_val@plt>
movzwl 0x200(%rsp),%eax
and    $0xfffffffe,%eax
cmp    $0x30,%ax
jne    12c5 <filt_w_message+0x135>
lea    0xd9d(%rip),%rdi
lea    0xda0(%rip),%rdx
lea    0xd8d(%rip),%rcx
xor    %esi,%esi
call   1090 <ezplib_replace_attr@plt>
lea    0xd90(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"WIFIConnect\00"
@.str.1 = [7 x i8] c"<SYS>\09\00"
@.str.2 = [17 x i8] c"WIFI Connect: %s\00"
@.str.3 = [6 x i8] c"wrong\00"
@.str.4 = [11 x i8] c"encryption\00"
@.str.5 = [16 x i8] c"wan_status_rule\00"
@.str.6 = [6 x i8] c"state\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [2 x i8] c"1\00"
@.str.9 = [10 x i8] c"plug_rule\00"
@.str.10 = [5 x i8] c"wisp\00"
@.str.11 = [8 x i8] c"msg:%s\0A\00"
define void @filt_w_message(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
store i8* %11, i8** %7
%12 = load i8*, i8** %3
%13 = call i8* @strchr(i8* %12, i8 signext 62)
store i8* %13, i8** %8
%14 = load i8*, i8** %3
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %9
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %18, %2
br label %76
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %8
%25 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %9
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %9
%29 = load i8*, i8** %7
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %29, i32 512, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %30, i32* %10
%31 = load i8*, i8** %7
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = call i32 @memcpy(i8* %35, i8* %36, i32 16)
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 16
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds i8, i8* %41, i64 512
%43 = load i8*, i8** %7
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = trunc i64 %46 to i32
%48 = load i8*, i8** %9
%49 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %40, i32 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %48)
%50 = load i8*, i8** %3
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%52 = call i32 @strncpy(i8* %50, i8* %51, i32 512)
%53 = load i8*, i8** %9
%54 = call i8* @strstr(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp ne i8* %54, null
br i1 %55, label %60, label %56
56: ; preds = %22
%57 = load i8*, i8** %9
%58 = call i8* @strstr(i8* %57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %73
60: ; preds = %56, %22
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%62 = call i32 @ezplib_get_attr_val(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %61, i32 512, i32 0)
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %60
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%68 = call i32 @strcmp(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%69 = icmp ne i32 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %66, %60
%71 = call i32 @ezplib_replace_attr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
br label %73
73: ; preds = %72, %56
%74 = load i8*, i8** %3
%75 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %73, %21
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"WIFIConnect\00"
@.str.1 = [7 x i8] c"<SYS>\09\00"
@.str.2 = [17 x i8] c"WIFI Connect: %s\00"
@.str.3 = [6 x i8] c"wrong\00"
@.str.4 = [11 x i8] c"encryption\00"
@.str.5 = [16 x i8] c"wan_status_rule\00"
@.str.6 = [6 x i8] c"state\00"
@.str.8 = [2 x i8] c"1\00"
@.str.9 = [10 x i8] c"plug_rule\00"
@.str.10 = [5 x i8] c"wisp\00"
@.str.11 = [8 x i8] c"msg:%s\0A\00"
define void @filt_w_message(i8* %0, i8* nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 62)
%8 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i8* %7, null
%10 = icmp ne i8* %8, null
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %44
12: ; preds = %2
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %8, i64 %15
%17 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 512, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %18
%20 = call i32 @memcpy(i8* %19, i8* %13, i32 16)
%21 = getelementptr inbounds i8, i8* %19, i64 16
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 512
%23 = ptrtoint i8* %22 to i64
%24 = ptrtoint i8* %21 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %21, i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%28 = call i32 @strncpy(i8* %0, i8* %5, i32 512)
%29 = call i8* @strstr(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %12
%32 = call i8* @strstr(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i8* %32, null
br i1 %33, label %42, label %34
34: ; preds = %31, %12
%35 = call i32 @ezplib_get_attr_val(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %6, i32 512, i32 0)
%36 = bitcast [512 x i8]* %4 to i16*
%37 = load i16, i16* %36
%38 = and i16 %37, -2
%39 = icmp eq i16 %38, 48
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @ezplib_replace_attr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %42
42: ; preds = %34, %40, %31
%43 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* %0)
br label %44
44: ; preds = %2, %42
ret void
}