#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 char strlen(char *);
short buscaCaracter(char *entrada, char caracter) {
  unsigned char pos = 0;
  for (; pos <= strlen(entrada); pos++) {
    if (caracter == entrada[pos]) {
      return pos;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<buscaCaracter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,%cl
mov    -0x18(%rbp),%eax
movzbl %cl,%ecx
cmp    %ecx,%eax
jg     117d <buscaCaracter+0x6d>
movsbl -0x11(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl -0x12(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    116b <buscaCaracter+0x5b>
movzbl -0x12(%rbp),%eax
mov    %ax,-0x2(%rbp)
jmp    1183 <buscaCaracter+0x73>
jmp    1170 <buscaCaracter+0x60>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    1126 <buscaCaracter+0x16>
movw   $0xffff,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscaCaracter>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl %bpl,%eax
cmp    %r14b,(%rbx,%rax,1)
je     114f <buscaCaracter+0x3f>
add    $0x1,%bpl
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %al,%bpl
jbe    1130 <buscaCaracter+0x20>
mov    $0xffff,%ax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i16 @buscaCaracter(i8* %0, i8 signext %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8 0, i8* %6
br label %7
7: ; preds = %28, %2
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = load i8*, i8** %4
%11 = call zeroext i8 @strlen(i8* %10)
%12 = zext i8 %11 to i32
%13 = icmp sle i32 %9, %12
br i1 %13, label %14, label %31
14: ; preds = %7
%15 = load i8, i8* %5
%16 = sext i8 %15 to i32
%17 = load i8*, i8** %4
%18 = load i8, i8* %6
%19 = zext i8 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %16, %22
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i8, i8* %6
%26 = zext i8 %25 to i16
store i16 %26, i16* %3
br label %32
27: ; preds = %14
br label %28
28: ; preds = %27
%29 = load i8, i8* %6
%30 = add i8 %29, 1
store i8 %30, i8* %6
br label %7
31: ; preds = %7
store i16 -1, i16* %3
br label %32
32: ; preds = %31, %24
%33 = load i16, i16* %3
ret i16 %33
}

LLVM IR (-O2):
define signext i16 @buscaCaracter(i8* %0, i8 signext %1) {
%3 = tail call zeroext i8 @strlen(i8* %0)
br label %4
4: ; preds = %2, %12
%5 = phi i8 [ 0, %2 ], [ %13, %12 ]
%6 = zext i8 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, %1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = zext i8 %5 to i16
br label %16
12: ; preds = %4
%13 = add i8 %5, 1
%14 = tail call zeroext i8 @strlen(i8* %0)
%15 = icmp ugt i8 %13, %14
br i1 %15, label %16, label %4
16: ; preds = %12, %10
%17 = phi i16 [ %11, %10 ], [ -1, %12 ]
ret i16 %17
}