#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 */
size_t GetStringLength(char const *);
char *FindFirstChar(const char *str, const char findChar) {
  char *found = NULL;
  size_t idx = 0;
  size_t len = GetStringLength(str);
  for (idx = 0; idx < len; ++idx) {
    if (str[idx] == 0) {
      break;
    }
    if (str[idx] == findChar) {
      found = (char *)str + idx;
      break;
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<FindFirstChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <GetStringLength@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ae <FindFirstChar+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    116f <FindFirstChar+0x5f>
jmp    11ae <FindFirstChar+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1198 <FindFirstChar+0x88>
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ae <FindFirstChar+0x9e>
jmp    119d <FindFirstChar+0x8d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1147 <FindFirstChar+0x37>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindFirstChar>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <GetStringLength@plt>
test   %rax,%rax
je     1146 <FindFirstChar+0x36>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%ecx
test   %cl,%cl
je     1146 <FindFirstChar+0x36>
cmp    %bpl,%cl
je     1148 <FindFirstChar+0x38>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rax
jne    1130 <FindFirstChar+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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