#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 */
char tolower(char);
char *ulindex(char *str, char *chr) {
  char c;
  c = tolower((int)(*chr));
  while (*str != '\0' && tolower(*str) != c)
    str++;
  if (*str == '\0')
    return NULL;
  else
    return str;
}


x86 assembly (clang, -O0):
<ulindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl %al,%edi
call   1030 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
je     1162 <ulindex+0x52>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
movsbl %al,%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    1172 <ulindex+0x62>
jmp    1183 <ulindex+0x73>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <ulindex+0x22>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a0 <ulindex+0x90>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <ulindex+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ulindex>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rsi),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
mov    (%rbx),%al
test   %al,%al
je     1150 <ulindex+0x40>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <tolower@plt>
cmp    %bpl,%al
je     114b <ulindex+0x3b>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <ulindex+0x20>
jmp    1150 <ulindex+0x40>
cmpb   $0x0,(%rbx)
jne    1152 <ulindex+0x42>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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