#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__ strlen(char const *);
char *strstr(char const *, char const *);
char *startsWith(const char *conts, const char *contd) {
  char *ptr = strstr(conts, contd);
  if (strlen(contd) > strlen(conts))
    return NULL;
  return ptr && (*contd == *conts) ? ptr : NULL;
}


x86 assembly (clang, -O0):
<startsWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jle    1174 <startsWith+0x54>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <startsWith+0x95>
cmpq   $0x0,-0x20(%rbp)
je     11a2 <startsWith+0x82>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11a2 <startsWith+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11ad <startsWith+0x8d>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11ad <startsWith+0x8d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startsWith>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strstr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%r12
jg     1163 <startsWith+0x43>
test   %r15,%r15
je     1163 <startsWith+0x43>
mov    (%rbx),%cl
xor    %eax,%eax
cmp    (%r14),%cl
cmove  %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @startsWith(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** %4
%8 = load i8*, i8** %5
%9 = call i8* @strstr(i8* %7, i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = icmp sgt i64 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* null, i8** %3
br label %32
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %22, %25
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = load i8*, i8** %6
br label %30
29: ; preds = %19, %16
br label %30
30: ; preds = %29, %27
%31 = phi i8* [ %28, %27 ], [ null, %29 ]
store i8* %31, i8** %3
br label %32
32: ; preds = %30, %15
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @startsWith(i8* %0, i8* nocapture %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp sgt i64 %4, %5
%7 = icmp eq i8* %3, null
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i8, i8* %1
%11 = load i8, i8* %0
%12 = icmp eq i8 %10, %11
%13 = select i1 %12, i8* %3, i8* null
br label %14
14: ; preds = %9, %2
%15 = phi i8* [ null, %2 ], [ %13, %9 ]
ret i8* %15
}