#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_kazaa(unsigned char *haystack, const int packet_len,
                     int payload_len) {
  unsigned char *t = haystack;
  if (packet_len == payload_len && t[packet_len - 1] == 0x00) {
    t += (packet_len - 6);
    if (memcmp(t, "KaZaA", 5) == 0)
      return (8 * 100 + 50);
  }
  return 0;
}


x86 assembly (clang, -O0):
<udp_search_kazaa>:
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    1194 <udp_search_kazaa+0x84>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1194 <udp_search_kazaa+0x84>
mov    -0x14(%rbp),%ecx
sub    $0x6,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    118f <udp_search_kazaa+0x7f>
movl   $0x352,-0x4(%rbp)
jmp    119b <udp_search_kazaa+0x8b>
jmp    1194 <udp_search_kazaa+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_search_kazaa>:
push   %rax
cmp    %edx,%esi
jne    113c <udp_search_kazaa+0x2c>
movslq %esi,%rax
cmpb   $0x0,-0x1(%rax,%rdi,1)
jne    113c <udp_search_kazaa+0x2c>
add    %rax,%rdi
add    $0xfffffffffffffffa,%rdi
lea    0xed3(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1140 <udp_search_kazaa+0x30>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x352,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"KaZaA\00"
define i32 @udp_search_kazaa(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 %33
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %13
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 6
%25 = load i8*, i8** %8
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = call i64 @memcmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %22
store i32 850, i32* %4
br label %34
32: ; preds = %22
br label %33
33: ; preds = %32, %13, %3
store i32 0, i32* %4
br label %34
34: ; preds = %33, %31
%35 = load i32, i32* %4
ret i32 %35
}

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