#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 */
struct snof {
  int dummy;
};

/* Variables and functions */
scalar_t__ snofCmp(char *, char *, int, int);
char *snofNameAtIx(struct snof *, int);
int /*<<< orphan*/ snofSearch(struct snof *, char *, int, int, int *, char **);
int snofFindFirstStartingWith(struct snof *snof, char *prefix, int prefixSize,
                              int *pSnofIx) {
  char *nameOffset;
  int matchIx;
  if (!snofSearch(snof, prefix, prefixSize, 1, &matchIx, &nameOffset)) {
    *pSnofIx = matchIx;
    return 0;
  }
  while (--matchIx >= 0) {
    nameOffset = snofNameAtIx(snof, matchIx);
    if (snofCmp(prefix, nameOffset, prefixSize, 1) != 0)
      break;
  }
  ++matchIx;
  *pSnofIx = matchIx;
  return 1;
}


x86 assembly (clang, -O0):
<snofFindFirstStartingWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%ecx
lea    -0x34(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1030 <snofSearch@plt>
cmp    $0x0,%eax
jne    1182 <snofFindFirstStartingWith+0x52>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11eb <snofFindFirstStartingWith+0xbb>
jmp    1187 <snofFindFirstStartingWith+0x57>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jl     11d2 <snofFindFirstStartingWith+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <snofNameAtIx@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%ecx
call   1040 <snofCmp@plt>
cmp    $0x0,%rax
je     11cd <snofFindFirstStartingWith+0x9d>
jmp    11d2 <snofFindFirstStartingWith+0xa2>
jmp    1187 <snofFindFirstStartingWith+0x57>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snofFindFirstStartingWith>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xc(%rsp),%r8
lea    0x10(%rsp),%r9
mov    $0x1,%ecx
call   1030 <snofSearch@plt>
test   %eax,%eax
je     11a2 <snofFindFirstStartingWith+0x72>
xchg   %ax,%ax
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%esi
mov    %esi,0xc(%rsp)
test   %eax,%eax
jle    1198 <snofFindFirstStartingWith+0x68>
mov    %rbp,%rdi
call   1050 <snofNameAtIx@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
mov    $0x1,%ecx
call   1040 <snofCmp@plt>
test   %rax,%rax
je     1160 <snofFindFirstStartingWith+0x30>
mov    0xc(%rsp),%esi
add    $0x1,%esi
mov    $0x1,%eax
jmp    11a8 <snofFindFirstStartingWith+0x78>
xor    %eax,%eax
mov    0xc(%rsp),%esi
mov    %esi,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.snof = type { i32 }
define i32 @snofFindFirstStartingWith(%struct.snof* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.snof*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
store %struct.snof* %0, %struct.snof** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load %struct.snof*, %struct.snof** %6
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = call i32 @snofSearch(%struct.snof* %12, i8* %13, i32 %14, i32 1, i32* %11, i8** %10)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %4
%18 = load i32, i32* %11
%19 = load i32*, i32** %9
store i32 %18, i32* %19
store i32 0, i32* %5
br label %41
20: ; preds = %4
br label %21
21: ; preds = %35, %20
%22 = load i32, i32* %11
%23 = add nsw i32 %22, -1
store i32 %23, i32* %11
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load %struct.snof*, %struct.snof** %6
%27 = load i32, i32* %11
%28 = call i8* @snofNameAtIx(%struct.snof* %26, i32 %27)
store i8* %28, i8** %10
%29 = load i8*, i8** %7
%30 = load i8*, i8** %10
%31 = load i32, i32* %8
%32 = call i64 @snofCmp(i8* %29, i8* %30, i32 %31, i32 1)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %25
br label %36
35: ; preds = %25
br label %21
36: ; preds = %34, %21
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
%39 = load i32, i32* %11
%40 = load i32*, i32** %9
store i32 %39, i32* %40
store i32 1, i32* %5
br label %41
41: ; preds = %36, %17
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%struct.snof = type { i32 }
define i32 @snofFindFirstStartingWith(%struct.snof* %0, i8* %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = bitcast i8** %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 @snofSearch(%struct.snof* %0, i8* %1, i32 %2, i32 1, i32* %6, i8** %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = load i32, i32* %6
br label %26
13: ; preds = %4, %17
%14 = load i32, i32* %6
%15 = add nsw i32 %14, -1
store i32 %15, i32* %6
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = call i8* @snofNameAtIx(%struct.snof* %0, i32 %15)
store i8* %18, i8** %5
%19 = call i64 @snofCmp(i8* %1, i8* %18, i32 %2, i32 1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %13, label %21
21: ; preds = %17
%22 = load i32, i32* %6
br label %23
23: ; preds = %13, %21
%24 = phi i32 [ %22, %21 ], [ %15, %13 ]
%25 = add nsw i32 %24, 1
br label %26
26: ; preds = %23, %11
%27 = phi i32 [ %12, %11 ], [ %25, %23 ]
%28 = phi i32 [ 0, %11 ], [ 1, %23 ]
store i32 %27, i32* %3
ret i32 %28
}