#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 *, char *, int);
int _udp_search_directconnect(unsigned char *haystack, const int packet_len,
                              int payload_len) {
  unsigned char *t = haystack;
  if ((packet_len == payload_len) && (*(t + 8) == 0x24) &&
      (*(t + packet_len - 1) == 0x7c)) {
    t += 8;
    if (memcmp(t, "SR ", 3) == 0)
      return ((5 * 100) + 60);
    if (memcmp(t, "Ping ", 5) == 0)
      return ((5 * 100) + 61);
  }
  return 0;
}


x86 assembly (clang, -O0):
<_udp_search_directconnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11c4 <_udp_search_directconnect+0xb4>
mov    -0x20(%rbp),%rax
movzbl 0x8(%rax),%eax
cmp    $0x24,%eax
jne    11c4 <_udp_search_directconnect+0xb4>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl -0x1(%rax,%rcx,1),%eax
cmp    $0x7c,%eax
jne    11c4 <_udp_search_directconnect+0xb4>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1194 <_udp_search_directconnect+0x84>
movl   $0x230,-0x4(%rbp)
jmp    11cb <_udp_search_directconnect+0xbb>
mov    -0x20(%rbp),%rdi
lea    0xe65(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    11bf <_udp_search_directconnect+0xaf>
movl   $0x231,-0x4(%rbp)
jmp    11cb <_udp_search_directconnect+0xbb>
jmp    11c4 <_udp_search_directconnect+0xb4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_udp_search_directconnect>:
push   %rbx
cmp    %edx,%esi
jne    115e <_udp_search_directconnect+0x4e>
mov    %rdi,%rbx
cmpb   $0x24,0x8(%rdi)
jne    115e <_udp_search_directconnect+0x4e>
movslq %esi,%rax
cmpb   $0x7c,-0x1(%rbx,%rax,1)
jne    115e <_udp_search_directconnect+0x4e>
add    $0x8,%rbx
lea    0xecd(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1162 <_udp_search_directconnect+0x52>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1169 <_udp_search_directconnect+0x59>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x230,%eax
pop    %rbx
ret
mov    $0x231,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"SR \00"
@.str.1 = [6 x i8] c"Ping \00"
define i32 @_udp_search_directconnect(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
store i8* %9, i8** %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %41
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = getelementptr inbounds i8, i8* %14, i64 8
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp eq i32 %17, 36
br i1 %18, label %19, label %41
19: ; preds = %13
%20 = load i8*, i8** %8
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 124
br i1 %27, label %28, label %41
28: ; preds = %19
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 8
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = call i64 @memcmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 560, i32* %4
br label %42
35: ; preds = %28
%36 = load i8*, i8** %8
%37 = call i64 @memcmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 561, i32* %4
br label %42
40: ; preds = %35
br label %41
41: ; preds = %40, %19, %13, %3
store i32 0, i32* %4
br label %42
42: ; preds = %41, %39, %34
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [4 x i8] c"SR \00"
@.str.1 = [6 x i8] c"Ping \00"
define i32 @_udp_search_directconnect(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, %2
br i1 %4, label %5, label %21
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 8
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 36
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 124
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = tail call i64 @memcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = tail call i64 @memcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18, %9, %5, %3
br label %22
22: ; preds = %18, %15, %21
%23 = phi i32 [ 0, %21 ], [ 560, %15 ], [ 561, %18 ]
ret i32 %23
}