#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 *const);
scalar_t__ strncasecmp(char const *const, char const *, unsigned int);
const unsigned char *find_string(const unsigned char *bp, int *tgt,
                                 const char *const *n1, const char *const *n2,
                                 int c) {
  int i;
  unsigned int len;
  for (; n1 != NULL; n1 = n2, n2 = NULL) {
    for (i = 0; i < c; i++, n1++) {
      len = strlen(*n1);
      if (strncasecmp(*n1, (const char *)bp, len) == 0) {
        *tgt = i;
        return bp + len;
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11db <find_string+0xbb>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11c1 <find_string+0xa1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11a2 <find_string+0x82>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <find_string+0xc3>
jmp    11a7 <find_string+0x87>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <find_string+0x2e>
jmp    11c6 <find_string+0xa6>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    113c <find_string+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdx,%rdx
je     11af <find_string+0x8f>
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rdi,%rbx
mov    %rsi,0x10(%rsp)
mov    %r8d,%r14d
mov    %r8d,0xc(%rsp)
jmp    1163 <find_string+0x43>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rbp
test   %r13,%r13
mov    $0x0,%r13d
mov    0xc(%rsp),%r8d
je     11af <find_string+0x8f>
test   %r8d,%r8d
jle    1150 <find_string+0x30>
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp,%r12,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    0x0(%rbp,%r12,8),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     119c <find_string+0x7c>
add    $0x1,%r12
cmp    %r12d,%r14d
jne    1170 <find_string+0x50>
jmp    1150 <find_string+0x30>
mov    0x10(%rsp),%rax
mov    %r12d,(%rax)
mov    %r15d,%eax
add    %rax,%rbx
mov    %rbx,%rax
jmp    11b1 <find_string+0x91>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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