#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*/ cut_log(char *, char *, int);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
void check_log_len(char *msg, int time_len) {
  int log_len;
  int log_max_len;
  int log_max_size = 128;
  log_len = strlen(msg);
  log_max_len = log_max_size - time_len;
  if (log_len <= log_max_len)
    return;
  if (strncasecmp(msg, "[Dynamic DNS]", strlen("[Dynamic DNS]")) == 0) {
    cut_log(msg, " registration", log_max_len);
    return;
  }
  if (strncasecmp(msg, "[USB device attached]",
                  strlen("[USB device attached]")) == 0) {
    cut_log(msg, " is attached to the router", log_max_len);
    return;
  }
  if (strncasecmp(msg, "[USB device detached]",
                  strlen("[USB device detached]")) == 0) {
    cut_log(msg, " is detached from the router", log_max_len);
    return;
  }
  if ((strncasecmp(msg, "[site allowed:", strlen("[site allowed:")) == 0) ||
      (strncasecmp(msg, "[site blocked:", strlen("[site blocked:")) == 0)) {
    cut_log(msg, "]", log_max_len);
    return;
  }
  msg[log_max_len] = '\0';
  return;
}


x86 assembly (clang, -O0):
<check_log_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x80,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     116c <check_log_len+0x3c>
jmp    12c8 <check_log_len+0x198>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe73(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11b4 <check_log_len+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe64(%rip),%rsi
call   1040 <cut_log@plt>
jmp    12c8 <check_log_len+0x198>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe59(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe47(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11fc <check_log_len+0xcc>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe40(%rip),%rsi
call   1040 <cut_log@plt>
jmp    12c8 <check_log_len+0x198>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe42(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe30(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1244 <check_log_len+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe29(%rip),%rsi
call   1040 <cut_log@plt>
jmp    12c8 <check_log_len+0x198>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe2d(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe1b(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
je     12a4 <check_log_len+0x174>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xe0c(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xdfa(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    12bc <check_log_len+0x18c>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd5a(%rip),%rsi
call   1040 <cut_log@plt>
jmp    12c8 <check_log_len+0x198>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_log_len>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %ebx,%rcx
mov    $0x80,%ebx
sub    %rcx,%rbx
cmp    %ebx,%eax
jle    1200 <check_log_len+0xd0>
lea    0xea7(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     1206 <check_log_len+0xd6>
lea    0xe9e(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     120f <check_log_len+0xdf>
lea    0xeae(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     1218 <check_log_len+0xe8>
lea    0xec0(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     1221 <check_log_len+0xf1>
lea    0xeae(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     1221 <check_log_len+0xf1>
movb   $0x0,(%r14,%rbx,1)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe01(%rip),%rsi
jmp    1228 <check_log_len+0xf8>
lea    0xe1c(%rip),%rsi
jmp    1228 <check_log_len+0xf8>
lea    0xe44(%rip),%rsi
jmp    1228 <check_log_len+0xf8>
lea    0xde4(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <cut_log@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"[Dynamic DNS]\00"
@.str.1 = [14 x i8] c" registration\00"
@.str.2 = [22 x i8] c"[USB device attached]\00"
@.str.3 = [27 x i8] c" is attached to the router\00"
@.str.4 = [22 x i8] c"[USB device detached]\00"
@.str.5 = [29 x i8] c" is detached from the router\00"
@.str.6 = [15 x i8] c"[site allowed:\00"
@.str.7 = [15 x i8] c"[site blocked:\00"
@.str.8 = [2 x i8] c"]\00"
define void @check_log_len(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 128, i32* %7
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = sub nsw i32 %10, %11
store i32 %12, i32* %6
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %2
br label %63
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%20 = call i64 @strncasecmp(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = call i32 @cut_log(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %63
26: ; preds = %17
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%29 = call i64 @strncasecmp(i8* %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = load i32, i32* %6
%34 = call i32 @cut_log(i8* %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %63
35: ; preds = %26
%36 = load i8*, i8** %3
%37 = call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%38 = call i64 @strncasecmp(i8* %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = load i32, i32* %6
%43 = call i32 @cut_log(i8* %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %63
44: ; preds = %35
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%47 = call i64 @strncasecmp(i8* %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %54, label %49
49: ; preds = %44
%50 = load i8*, i8** %3
%51 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%52 = call i64 @strncasecmp(i8* %50, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49, %44
%55 = load i8*, i8** %3
%56 = load i32, i32* %6
%57 = call i32 @cut_log(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 %56)
br label %63
58: ; preds = %49
%59 = load i8*, i8** %3
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %58, %54, %40, %31, %22, %16
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"[Dynamic DNS]\00"
@.str.1 = [14 x i8] c" registration\00"
@.str.2 = [22 x i8] c"[USB device attached]\00"
@.str.3 = [27 x i8] c" is attached to the router\00"
@.str.4 = [22 x i8] c"[USB device detached]\00"
@.str.5 = [29 x i8] c" is detached from the router\00"
@.str.6 = [15 x i8] c"[site allowed:\00"
@.str.7 = [15 x i8] c"[site blocked:\00"
@.str.8 = [2 x i8] c"]\00"
define void @check_log_len(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sub nsw i32 128, %1
%5 = icmp sgt i32 %3, %4
br i1 %5, label %6, label %37
6: ; preds = %2
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @cut_log(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %37
12: ; preds = %6
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @cut_log(i8* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %4)
br label %37
18: ; preds = %12
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @cut_log(i8* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %4)
br label %37
24: ; preds = %18
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%26 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%30 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28, %24
%33 = tail call i32 @cut_log(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 %4)
br label %37
34: ; preds = %28
%35 = sext i32 %4 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %2, %34, %32, %22, %16, %10
ret void
}