#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_gnu(unsigned char *haystack, const int packet_len,
                   int payload_len) {
  unsigned char *t = haystack;
  t += 8;
  if (memcmp(t, "GND", 3) == 0)
    return ((7 * 100) + 51);
  if (memcmp(t, "GNUTELLA ", 9) == 0)
    return ((7 * 100) + 52);
  return 0;
}


x86 assembly (clang, -O0):
<udp_search_gnu>:
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
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xebf(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1161 <udp_search_gnu+0x51>
movl   $0x2ef,-0x4(%rbp)
jmp    1193 <udp_search_gnu+0x83>
mov    -0x20(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x9,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    118c <udp_search_gnu+0x7c>
movl   $0x2f0,-0x4(%rbp)
jmp    1193 <udp_search_gnu+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_search_gnu>:
push   %rbx
mov    %rdi,%rbx
add    $0x8,%rbx
lea    0xee1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1154 <udp_search_gnu+0x44>
lea    0xecc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1030 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x2f0,%eax
cmovne %ecx,%eax
pop    %rbx
ret
mov    $0x2ef,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"GND\00"
@.str.1 = [10 x i8] c"GNUTELLA \00"
define i32 @udp_search_gnu(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
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = call i64 @memcmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 751, i32* %4
br label %22
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 752, i32* %4
br label %22
21: ; preds = %16
store i32 0, i32* %4
br label %22
22: ; preds = %21, %20, %15
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [4 x i8] c"GND\00"
@.str.1 = [10 x i8] c"GNUTELLA \00"
define i32 @udp_search_gnu(i8* %0, i32 %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 8
%5 = tail call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i32 752, i32 0
br label %11
11: ; preds = %7, %3
%12 = phi i32 [ 751, %3 ], [ %10, %7 ]
ret i32 %12
}