#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 *);
int string_starts_with(char *str, char *prefix) {
  if (strlen(prefix) > strlen(str)) {
    return 0;
  }
  while (*prefix != '\0') {
    if (*prefix++ != *str++) {
      return 0;
    }
  };
  return 1;
}


x86 assembly (clang, -O0):
<string_starts_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jle    1152 <string_starts_with+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11ab <string_starts_with+0x9b>
jmp    1157 <string_starts_with+0x47>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <string_starts_with+0x94>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     119f <string_starts_with+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    11ab <string_starts_with+0x9b>
jmp    1157 <string_starts_with+0x47>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_starts_with>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%r15
jg     115e <string_starts_with+0x4e>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rax,1),%ecx
test   %cl,%cl
je     1159 <string_starts_with+0x49>
lea    0x1(%rax),%rdx
cmp    (%r14,%rax,1),%cl
mov    %rdx,%rax
je     1140 <string_starts_with+0x30>
xor    %eax,%eax
jmp    115e <string_starts_with+0x4e>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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