#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 */
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int xfind(char *str, const char *substr) {
  int fullstrlen, substrlen, pos, insidequote;
  pos = 0;
  insidequote = 0;
  fullstrlen = strlen(str);
  substrlen = strlen(substr);
  for (int i = 0; i < fullstrlen; i++) {
    if (!insidequote && str[i] == '\"')
      insidequote = 1;
    else if (insidequote && str[i] == '\"')
      insidequote = 0;
    if (!insidequote) {
      if (strncmp(str + i, substr, substrlen) == 0)
        return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<xfind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120d <xfind+0xed>
cmpl   $0x0,-0x28(%rbp)
jne    1194 <xfind+0x74>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    1194 <xfind+0x74>
movl   $0x1,-0x28(%rbp)
jmp    11bf <xfind+0x9f>
cmpl   $0x0,-0x28(%rbp)
je     11ba <xfind+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    11ba <xfind+0x9a>
movl   $0x0,-0x28(%rbp)
jmp    11bf <xfind+0x9f>
cmpl   $0x0,-0x28(%rbp)
jne    11fa <xfind+0xda>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f5 <xfind+0xd5>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1214 <xfind+0xf4>
jmp    11fa <xfind+0xda>
jmp    11ff <xfind+0xdf>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115d <xfind+0x3d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfind>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0xffffffff,%r15d
test   %r12d,%r12d
jle    11ae <xfind+0x8e>
mov    %eax,%r13d
mov    %r12d,%r12d
xor    %ebp,%ebp
xor    %ecx,%ecx
jmp    117f <xfind+0x5f>
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     11ab <xfind+0x8b>
add    $0x1,%rbp
cmp    %rbp,%r12
je     11ae <xfind+0x8e>
movzbl (%rbx,%rbp,1),%eax
test   %ecx,%ecx
je     11a0 <xfind+0x80>
mov    $0x1,%ecx
cmp    $0x22,%al
je     1160 <xfind+0x40>
jmp    1176 <xfind+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%ecx
cmp    $0x22,%al
jne    1160 <xfind+0x40>
jmp    1176 <xfind+0x56>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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