#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 strmlen(char *);
char *strmchr(char *str, char searchFor) {
  char *pointer = NULL;
  register int counter = 0;
  int strlen = strmlen(str);
  for (; counter <= strlen; ++counter)
    if (str[counter] == searchFor) {
      pointer = &str[counter];
      break;
    }
  return pointer;
}


x86 assembly (clang, -O0):
<strmchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strmlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1188 <strmchr+0x78>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1175 <strmchr+0x65>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1188 <strmchr+0x78>
jmp    117a <strmchr+0x6a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <strmchr+0x2d>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmchr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strmlen@plt>
test   %eax,%eax
js     113f <strmchr+0x2f>
add    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %bpl,(%rbx)
je     1141 <strmchr+0x31>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rax
jne    1130 <strmchr+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strmchr(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i8* null, i8** %5
store i32 0, i32* %6
%8 = load i8*, i8** %3
%9 = call i32 @strmlen(i8* %8)
store i32 %9, i32* %7
br label %10
10: ; preds = %30, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i32, i32* %6
%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 = sext i8 %21 to i32
%23 = icmp eq i32 %20, %22
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8* %28, i8** %5
br label %33
29: ; preds = %14
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %10
33: ; preds = %24, %10
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
define i8* @strmchr(i8* %0, i8 signext %1) {
%3 = tail call i32 @strmlen(i8* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = add nuw i32 %3, 1
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %13
%9 = phi i64 [ 0, %5 ], [ %14, %13 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, %1
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %19, label %8
16: ; preds = %8
%17 = and i64 %9, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
br label %19
19: ; preds = %13, %2, %16
%20 = phi i8* [ %18, %16 ], [ null, %2 ], [ null, %13 ]
ret i8* %20
}