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


x86 assembly (clang, -O0):
<semanage_is_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <semanage_is_prefix+0x27>
movl   $0x0,-0x4(%rbp)
jmp    1195 <semanage_is_prefix+0x75>
cmpq   $0x0,-0x18(%rbp)
jne    115e <semanage_is_prefix+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    1195 <semanage_is_prefix+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@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):
<semanage_is_prefix>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1156 <semanage_is_prefix+0x36>
mov    %rsi,%r14
test   %rsi,%rsi
je     115a <semanage_is_prefix+0x3a>
mov    %rdi,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    115f <semanage_is_prefix+0x3f>
xor    %eax,%eax
jmp    115f <semanage_is_prefix+0x3f>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @semanage_is_prefix(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** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i32 0, i32* %3
br label %21
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i32 1, i32* %3
br label %21
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = call i64 @strncmp(i8* %14, i8* %15, i32 %17)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
store i32 %20, i32* %3
br label %21
21: ; preds = %13, %12, %8
%22 = load i32, i32* %3
ret i32 %22
}

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