#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 */
scalar_t__ toupper(int);
char *find_upc(char *str, char *search) {
  char *s;
  char c;
  s = search;
  while ((c = *str++)) {
    c = (char)toupper((int)c);
    if (c == *s++) {
      if (!*s) {
        return (str);
      }
    } else {
      s = search;
    }
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<find_upc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
cmp    $0x0,%al
je     119a <find_upc+0x8a>
movsbl -0x21(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    118d <find_upc+0x7d>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1188 <find_upc+0x78>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <find_upc+0x92>
jmp    1195 <find_upc+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <find_upc+0x18>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_upc>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1162 <find_upc+0x52>
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x1,%r15
mov    %rsi,%rbx
jmp    113f <find_upc+0x2f>
nopw   0x0(%rax,%rax,1)
movzbl (%r15),%eax
add    $0x1,%r15
mov    %rcx,%rbx
test   %al,%al
je     1162 <find_upc+0x52>
movsbl %al,%edi
call   1030 <toupper@plt>
movsbl %al,%eax
movsbl (%rbx),%edx
mov    %r14,%rcx
cmp    %edx,%eax
jne    1130 <find_upc+0x20>
add    $0x1,%rbx
cmpb   $0x0,(%rbx)
mov    %rbx,%rcx
jne    1130 <find_upc+0x20>
jmp    1165 <find_upc+0x55>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @find_upc(i8* %0, i8* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %2, %22
%6 = phi i8 [ %24, %22 ], [ %3, %2 ]
%7 = phi i8* [ %9, %22 ], [ %0, %2 ]
%8 = phi i8* [ %23, %22 ], [ %1, %2 ]
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = sext i8 %6 to i32
%11 = tail call i64 @toupper(i32 %10)
%12 = trunc i64 %11 to i32
%13 = shl i32 %12, 24
%14 = ashr exact i32 %13, 24
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = load i8, i8* %8
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %14, %17
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i8, i8* %15
%21 = icmp eq i8 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %5, %19
%23 = phi i8* [ %15, %19 ], [ %1, %5 ]
%24 = load i8, i8* %9
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %5
26: ; preds = %19, %22, %2
%27 = phi i8* [ null, %2 ], [ null, %22 ], [ %9, %19 ]
ret i8* %27
}