#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 *);
int buscarSubcadena(char *str1, const char *busc) {
  int i, cont = 0, pos = -1;
  int encont;
  encont = 0;
  for (i = 0; i < strlen(str1); i++) {
    if (str1[i] == busc[cont]) {
      cont++;
      if (!encont) {
        pos = i;
      }
    }
  }
  return pos;
}


x86 assembly (clang, -O0):
<buscarSubcadena>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11a9 <buscarSubcadena+0x99>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1196 <buscarSubcadena+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1191 <buscarSubcadena+0x81>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <buscarSubcadena+0x86>
jmp    119b <buscarSubcadena+0x8b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <buscarSubcadena+0x2c>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscarSubcadena>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    116b <buscarSubcadena+0x5b>
xor    %ebx,%ebx
mov    $0xffffffff,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
mov    %ebp,%ecx
xor    %edx,%edx
cmp    (%r14,%rcx,1),%al
sete   %dl
cmove  %ebx,%r12d
add    %edx,%ebp
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <buscarSubcadena+0x30>
jmp    1171 <buscarSubcadena+0x61>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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