#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 *compare_str(char *, char *);
char *find_substr(char *main, char *substr) {
  char *ptr = NULL;
  while (main) {
    if (*main == '\n') {
      break;
    }
    if (*substr == *main) {
      ptr = compare_str(main, substr);
      if (ptr) {
        return ptr;
      }
    }
    main++;
  }
  return ptr;
}


x86 assembly (clang, -O0):
<find_substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119d <find_substr+0x8d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1148 <find_substr+0x38>
jmp    119d <find_substr+0x8d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    118c <find_substr+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <compare_str@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1187 <find_substr+0x77>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <find_substr+0x95>
jmp    118c <find_substr+0x7c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1128 <find_substr+0x18>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_substr>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1122 <find_substr+0x12>
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0xa,%al
jne    112c <find_substr+0x1c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsi,%r14
jmp    114c <find_substr+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0xa,%al
je     1122 <find_substr+0x12>
cmp    %al,(%r14)
jne    1140 <find_substr+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <compare_str@plt>
test   %rax,%rax
je     1140 <find_substr+0x30>
jmp    1124 <find_substr+0x14>

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

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