#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int string_prefix_is(const char *string, const char *prefix) {
  size_t n;
  if (!string || !prefix)
    return 0;
  if ((n = strlen(prefix)) == 0)
    return 0;
  if (strncmp(string, prefix, n) == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<string_prefix_is>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <string_prefix_is+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <string_prefix_is+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <string_prefix_is+0x83>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1175 <string_prefix_is+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <string_prefix_is+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119c <string_prefix_is+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <string_prefix_is+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_prefix_is>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
test   %rdi,%rdi
je     115a <string_prefix_is+0x3a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     115a <string_prefix_is+0x3a>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     115a <string_prefix_is+0x3a>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_prefix_is(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9, %2
store i32 0, i32* %3
br label %26
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 0, i32* %3
br label %26
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = call i64 @strncmp(i8* %19, i8* %20, i64 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1, i32* %3
br label %26
25: ; preds = %18
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24, %17, %12
%27 = load i32, i32* %3
ret i32 %27
}

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