#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 */
unsigned int strlen(char const *);
int payload_get_offset_by_name(const char *name, const char buf[0],
                               const unsigned int n_buf) {
  const unsigned int n_name = strlen(name);
  unsigned int i_name = 0;
  unsigned int i = 0;
  while (i < n_buf) {
    while (name[i_name] == buf[i + i_name] && ((i + i_name) < n_buf) &&
           (i_name < n_name))
      ++i_name;
    if (i_name == n_name)
      return i;
    else
      i_name = 0;
    ++i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<payload_get_offset_by_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11e0 <payload_get_offset_by_name+0xd0>
jmp    114e <payload_get_offset_by_name+0x3e>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%ecx
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%edx
add    -0x24(%rbp),%edx
mov    %edx,%edx
movsbl (%rax,%rdx,1),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x29(%rbp)
jne    1196 <payload_get_offset_by_name+0x86>
mov    -0x28(%rbp),%ecx
add    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x29(%rbp)
jae    1196 <payload_get_offset_by_name+0x86>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
setb   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a6 <payload_get_offset_by_name+0x96>
jmp    11b4 <payload_get_offset_by_name+0xa4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <payload_get_offset_by_name+0x3e>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11cb <payload_get_offset_by_name+0xbb>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <payload_get_offset_by_name+0xd7>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    113d <payload_get_offset_by_name+0x2d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<payload_get_offset_by_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
test   %r15d,%r15d
je     117b <payload_get_offset_by_name+0x6b>
mov    %eax,%edx
add    $0x1,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r14,%rcx,1),%rsi
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12,%rdi,1),%ebx
lea    0x1(%rdi),%rbp
cmp    (%rsi,%rdi,1),%bl
jne    116e <payload_get_offset_by_name+0x5e>
lea    (%rcx,%rdi,1),%ebx
cmp    %r15d,%ebx
jae    116e <payload_get_offset_by_name+0x5e>
cmp    %rdx,%rdi
mov    %rbp,%rdi
jb     1150 <payload_get_offset_by_name+0x40>
cmp    %ebp,%eax
je     1180 <payload_get_offset_by_name+0x70>
add    $0x1,%rcx
cmp    %r15d,%ecx
jne    1140 <payload_get_offset_by_name+0x30>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @payload_get_offset_by_name(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %2, 0
br i1 %5, label %31, label %6
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %28
%9 = phi i32 [ %29, %28 ], [ 0, %6 ]
br label %10
10: ; preds = %10, %8
%11 = phi i64 [ %24, %10 ], [ 0, %8 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = trunc i64 %11 to i32
%15 = add i32 %9, %14
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %13, %18
%20 = icmp ult i32 %15, %2
%21 = select i1 %19, i1 %20, i1 false
%22 = icmp ult i64 %11, %7
%23 = select i1 %21, i1 %22, i1 false
%24 = add nuw nsw i64 %11, 1
br i1 %23, label %10, label %25
25: ; preds = %10
%26 = trunc i64 %11 to i32
%27 = icmp eq i32 %4, %26
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = add nuw i32 %9, 1
%30 = icmp eq i32 %29, %2
br i1 %30, label %31, label %8
31: ; preds = %25, %28, %3
%32 = phi i32 [ -1, %3 ], [ -1, %28 ], [ %9, %25 ]
ret i32 %32
}