#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 (*(t + 8) != 0x24)
    return 0;
  t += 9;
  if ((payload_len > 11) && (memcmp(t, "SR ", 3) == 0))
    return ((5 * 100) + 60);
  else if ((payload_len > 13) && (memcmp(t, "Ping ", 5) == 0))
    return ((5 * 100) + 61);
  else
    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    -0x20(%rbp),%rax
movzbl 0x8(%rax),%eax
cmp    $0x24,%eax
je     1147 <udp_search_directconnect+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <udp_search_directconnect+0xb4>
mov    -0x20(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0xb,-0x18(%rbp)
jle    1188 <udp_search_directconnect+0x78>
mov    -0x20(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1188 <udp_search_directconnect+0x78>
movl   $0x230,-0x4(%rbp)
jmp    11c4 <udp_search_directconnect+0xb4>
cmpl   $0xd,-0x18(%rbp)
jle    11bd <udp_search_directconnect+0xad>
mov    -0x20(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    11bd <udp_search_directconnect+0xad>
movl   $0x231,-0x4(%rbp)
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   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmpb   $0x24,0x8(%rdi)
jne    1170 <udp_search_directconnect+0x60>
mov    %edx,%ebp
cmp    $0xc,%edx
jl     1170 <udp_search_directconnect+0x60>
mov    %rdi,%rbx
add    $0x9,%rbx
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     116a <udp_search_directconnect+0x5a>
cmp    $0xe,%ebp
jb     1170 <udp_search_directconnect+0x60>
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1170 <udp_search_directconnect+0x60>
mov    $0x231,%r14d
jmp    1170 <udp_search_directconnect+0x60>
mov    $0x230,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
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 i8*, i8** %8
%11 = getelementptr inbounds i8, i8* %10, i64 8
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = icmp ne i32 %13, 36
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %35
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = getelementptr inbounds i8, i8* %17, i64 9
store i8* %18, i8** %8
%19 = load i32, i32* %7
%20 = icmp sgt i32 %19, 11
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %8
%23 = call i64 @memcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 560, i32* %4
br label %35
26: ; preds = %21, %16
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 13
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %8
%31 = call i64 @memcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 561, i32* %4
br label %35
34: ; preds = %29, %26
store i32 0, i32* %4
br label %35
35: ; preds = %34, %33, %25, %15
%36 = load i32, i32* %4
ret i32 %36
}

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 = getelementptr inbounds i8, i8* %0, i64 8
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 36
br i1 %6, label %7, label %19
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %0, i64 9
%9 = icmp sgt i32 %2, 11
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = tail call i64 @memcmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = icmp ugt i32 %2, 13
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = tail call i64 @memcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %7, %15, %13
br label %19
19: ; preds = %15, %10, %3, %18
%20 = phi i32 [ 0, %18 ], [ 0, %3 ], [ 560, %10 ], [ 561, %15 ]
ret i32 %20
}