#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 */
int /*<<< orphan*/ assert(char const *);
scalar_t__ memcmp(char const *, char const *, size_t);
size_t strlen(char const *);
bool startswith(const char *s, const char *prefix) {
  size_t sl, pl;
  assert(s);
  assert(prefix);
  sl = strlen(s);
  pl = strlen(prefix);
  if (pl == 0)
    return true;
  if (sl < pl)
    return false;
  return memcmp(s, prefix, pl) == 0;
}


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
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <startswith+0x53>
movl   $0x1,-0x4(%rbp)
jmp    11bd <startswith+0x8d>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    119d <startswith+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11bd <startswith+0x8d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startswith>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <assert@plt>
mov    %r15,%rdi
call   1050 <assert@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1185 <startswith+0x55>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rbx,%rcx
jb     118a <startswith+0x5a>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    118a <startswith+0x5a>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @startswith(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %5
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %6
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %3
br label %31
19: ; preds = %2
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %3
br label %31
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i64, i64* %7
%28 = call i64 @memcmp(i8* %25, i8* %26, i64 %27)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
store i32 %30, i32* %3
br label %31
31: ; preds = %24, %23, %18
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @startswith(i8* %0, i8* %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i32 @assert(i8* %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = icmp ult i64 %8, %5
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i64 @memcmp(i8* %0, i8* %1, i64 %5)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %7, %2, %10
%15 = phi i32 [ %13, %10 ], [ 1, %2 ], [ 0, %7 ]
ret i32 %15
}