#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 */
scalar_t__ memcmp(unsigned char const *, char *, int);
int search_all_dc(const unsigned char *payload, const int plen,
                  int payload_len) {
  if (payload[0] != 0x24)
    return 0;
  if ((payload_len == plen) && payload[plen - 1] != 0x7c)
    return 0;
  if (payload_len <= plen) {
    const unsigned char *t = &payload[1];
    if (payload_len >= 6 && memcmp(t, "Lock ", 5) == 0)
      return ((5 * 100) + 1);
    if (payload_len >= 8 && memcmp(t, "MyNick ", 7) == 0)
      return ((5 * 100) + 38);
    if (payload_len >= 6 && memcmp(t, "Send|", 5) == 0)
      return (5 * 100);
  }
  return 0;
}


x86 assembly (clang, -O0):
<search_all_dc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x24,%eax
je     113e <search_all_dc+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1233 <search_all_dc+0x123>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1170 <search_all_dc+0x60>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7c,%eax
je     1170 <search_all_dc+0x60>
movl   $0x0,-0x4(%rbp)
jmp    1233 <search_all_dc+0x123>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     122c <search_all_dc+0x11c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x6,-0x18(%rbp)
jl     11bd <search_all_dc+0xad>
mov    -0x20(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    11bd <search_all_dc+0xad>
movl   $0x1f5,-0x4(%rbp)
jmp    1233 <search_all_dc+0x123>
cmpl   $0x8,-0x18(%rbp)
jl     11f2 <search_all_dc+0xe2>
mov    -0x20(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0x7,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    11f2 <search_all_dc+0xe2>
movl   $0x21a,-0x4(%rbp)
jmp    1233 <search_all_dc+0x123>
cmpl   $0x6,-0x18(%rbp)
jl     1227 <search_all_dc+0x117>
mov    -0x20(%rbp),%rdi
lea    0xe07(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1227 <search_all_dc+0x117>
movl   $0x1f4,-0x4(%rbp)
jmp    1233 <search_all_dc+0x123>
jmp    122c <search_all_dc+0x11c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_all_dc>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmpb   $0x24,(%rdi)
jne    11a6 <search_all_dc+0x96>
mov    %edx,%ebp
mov    %rdi,%rbx
cmp    %esi,%edx
jne    1135 <search_all_dc+0x25>
movslq %ebp,%rax
cmpb   $0x7c,-0x1(%rax,%rbx,1)
je     1137 <search_all_dc+0x27>
jmp    11a6 <search_all_dc+0x96>
jg     11a6 <search_all_dc+0x96>
cmp    $0x6,%ebp
jl     11a6 <search_all_dc+0x96>
add    $0x1,%rbx
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1198 <search_all_dc+0x88>
cmp    $0x8,%ebp
jb     1177 <search_all_dc+0x67>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     11a0 <search_all_dc+0x90>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    11a6 <search_all_dc+0x96>
mov    $0x1f4,%r14d
jmp    11a6 <search_all_dc+0x96>
mov    $0x1f5,%r14d
jmp    11a6 <search_all_dc+0x96>
mov    $0x21a,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Lock \00"
@.str.1 = [8 x i8] c"MyNick \00"
@.str.2 = [6 x i8] c"Send|\00"
define i32 @search_all_dc(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = icmp ne i32 %12, 36
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %61
15: ; preds = %3
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %26, 124
br i1 %27, label %28, label %29
28: ; preds = %19
store i32 0, i32* %4
br label %61
29: ; preds = %19, %15
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %60
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %35, i8** %8
%36 = load i32, i32* %7
%37 = icmp sge i32 %36, 6
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i8*, i8** %8
%40 = call i64 @memcmp(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 501, i32* %4
br label %61
43: ; preds = %38, %33
%44 = load i32, i32* %7
%45 = icmp sge i32 %44, 8
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i8*, i8** %8
%48 = call i64 @memcmp(i8* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 538, i32* %4
br label %61
51: ; preds = %46, %43
%52 = load i32, i32* %7
%53 = icmp sge i32 %52, 6
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = load i8*, i8** %8
%56 = call i64 @memcmp(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
store i32 500, i32* %4
br label %61
59: ; preds = %54, %51
br label %60
60: ; preds = %59, %29
store i32 0, i32* %4
br label %61
61: ; preds = %60, %58, %50, %42, %28, %14
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [6 x i8] c"Lock \00"
@.str.1 = [8 x i8] c"MyNick \00"
@.str.2 = [6 x i8] c"Send|\00"
define i32 @search_all_dc(i8* %0, i32 %1, i32 %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 36
br i1 %5, label %6, label %32
6: ; preds = %3
%7 = icmp eq i32 %2, %1
br i1 %7, label %8, label %14
8: ; preds = %6
%9 = add nsw i32 %2, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 124
br i1 %13, label %16, label %32
14: ; preds = %6
%15 = icmp sgt i32 %2, %1
br i1 %15, label %32, label %16
16: ; preds = %8, %14
%17 = getelementptr inbounds i8, i8* %0, i64 1
%18 = icmp sgt i32 %2, 5
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = tail call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = icmp ugt i32 %2, 7
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = tail call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24, %22
%28 = tail call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %19, %24, %27
%31 = phi i32 [ 500, %27 ], [ 538, %24 ], [ 501, %19 ]
br label %32
32: ; preds = %14, %27, %16, %30, %8, %3
%33 = phi i32 [ 0, %3 ], [ 0, %8 ], [ %31, %30 ], [ 0, %16 ], [ 0, %27 ], [ 0, %14 ]
ret i32 %33
}