#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 const *, unsigned int);
int /*<<< orphan*/ strlen(char const *);
unsigned udp_contains_sz(const unsigned char *px, unsigned length,
                         const char *sz) {
  unsigned sz_length = (unsigned)strlen(sz);
  unsigned offset = 0;
  if (length < sz_length)
    return 0;
  length -= sz_length;
  while (offset < length) {
    if (px[offset] == sz[0] && memcmp(px + offset, sz, sz_length) == 0)
      return 1;
    offset++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<udp_contains_sz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    115e <udp_contains_sz+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <udp_contains_sz+0xb0>
mov    -0x24(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11c9 <udp_contains_sz+0xa9>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11bb <udp_contains_sz+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11bb <udp_contains_sz+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <udp_contains_sz+0xb0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1169 <udp_contains_sz+0x49>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_contains_sz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    %r12d,%eax
ja     1190 <udp_contains_sz+0x70>
mov    %eax,%r15d
sub    %eax,%r12d
je     1190 <udp_contains_sz+0x70>
mov    %r12d,%ebx
jmp    116a <udp_contains_sz+0x4a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     1190 <udp_contains_sz+0x70>
movzbl 0x0(%rbp),%eax
movsbl 0x0(%r13),%ecx
cmp    %ecx,%eax
jne    1160 <udp_contains_sz+0x40>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    1160 <udp_contains_sz+0x40>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @udp_contains_sz(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %8
store i32 0, i32* %9
%12 = load i32, i32* %6
%13 = load i32, i32* %8
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %50
16: ; preds = %3
%17 = load i32, i32* %8
%18 = load i32, i32* %6
%19 = sub i32 %18, %17
store i32 %19, i32* %6
br label %20
20: ; preds = %46, %16
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = load i32, i32* %9
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %30, %34
br i1 %35, label %36, label %46
36: ; preds = %24
%37 = load i8*, i8** %5
%38 = load i32, i32* %9
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8*, i8** %7
%42 = load i32, i32* %8
%43 = call i64 @memcmp(i8* %40, i8* %41, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %36
store i32 1, i32* %4
br label %50
46: ; preds = %36, %24
%47 = load i32, i32* %9
%48 = add i32 %47, 1
store i32 %48, i32* %9
br label %20
49: ; preds = %20
store i32 0, i32* %4
br label %50
50: ; preds = %49, %45, %15
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @udp_contains_sz(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp ugt i32 %4, %1
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = sub i32 %1, %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %22
%12 = phi i64 [ 0, %9 ], [ %23, %22 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i64 @memcmp(i8* %13, i8* %2, i32 %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19, %11
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %25, label %11
25: ; preds = %19, %22, %6, %3
%26 = phi i32 [ 0, %3 ], [ 0, %6 ], [ 1, %19 ], [ 0, %22 ]
ret i32 %26
}