#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__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
char *strncpy(char *, char *, int);
int pl_startswith(char *string, char *prefix) {
  char *tmp = NULL;
  int ret_val = -1;
  int prefix_length = 0;
  if (string == NULL || prefix == NULL) {
    goto error_exit;
  }
  if (strlen(string) == 0) {
    goto error_exit;
  }
  prefix_length = strlen(prefix);
  if (prefix_length == 0) {
    goto error_exit;
  }
  tmp = (char *)calloc(prefix_length + 1, sizeof(char));
  if (tmp == NULL) {
    goto error_exit;
  }
  tmp = strncpy(tmp, string, prefix_length);
  if (!strcmp(tmp, prefix)) {
    ret_val = 1;
  } else {
    ret_val = 0;
  }
  free(tmp);
  return ret_val;
error_exit:
  free(tmp);
  return ret_val;
}


x86 assembly (clang, -O0):
<pl_startswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <pl_startswith+0x3c>
cmpq   $0x0,-0x18(%rbp)
jne    1191 <pl_startswith+0x41>
jmp    1238 <pl_startswith+0xe8>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    11a8 <pl_startswith+0x58>
jmp    1238 <pl_startswith+0xe8>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11c3 <pl_startswith+0x73>
jmp    1238 <pl_startswith+0xe8>
mov    -0x28(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e7 <pl_startswith+0x97>
jmp    1238 <pl_startswith+0xe8>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <strncpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    121d <pl_startswith+0xcd>
movl   $0x1,-0x24(%rbp)
jmp    1224 <pl_startswith+0xd4>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <pl_startswith+0xf7>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_startswith>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     11c0 <pl_startswith+0x70>
mov    %rsi,%r15
test   %rsi,%rsi
je     11c0 <pl_startswith+0x70>
mov    %rdi,%rbx
call   1050 <strlen@plt>
test   %eax,%eax
je     11be <pl_startswith+0x6e>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11be <pl_startswith+0x6e>
mov    %eax,%ebp
lea    0x1(%rbp),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11be <pl_startswith+0x6e>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
xor    %r14d,%r14d
test   %eax,%eax
sete   %r14b
jmp    11c0 <pl_startswith+0x70>
xor    %ebp,%ebp
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pl_startswith(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i32 -1, i32* %7
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
br label %49
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %49
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %49
26: ; preds = %20
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
%29 = call i64 @calloc(i32 %28, i32 1)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %26
br label %49
34: ; preds = %26
%35 = load i8*, i8** %6
%36 = load i8*, i8** %4
%37 = load i32, i32* %8
%38 = call i8* @strncpy(i8* %35, i8* %36, i32 %37)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = load i8*, i8** %5
%41 = call i32 @strcmp(i8* %39, i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %34
store i32 1, i32* %7
br label %45
44: ; preds = %34
store i32 0, i32* %7
br label %45
45: ; preds = %44, %43
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* %7
store i32 %48, i32* %3
br label %53
49: ; preds = %33, %25, %19, %14
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
%52 = load i32, i32* %7
store i32 %52, i32* %3
br label %53
53: ; preds = %49, %45
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
define i32 @pl_startswith(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %9
%13 = add nsw i32 %10, 1
%14 = tail call i64 @calloc(i32 %13, i32 1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %12
%17 = inttoptr i64 %14 to i8*
%18 = tail call i8* @strncpy(i8* %17, i8* %0, i32 %10)
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %18, i8* dereferenceable(1) %1)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %2, %6, %9, %12, %16
%23 = phi i8* [ %18, %16 ], [ null, %12 ], [ null, %9 ], [ null, %6 ], [ null, %2 ]
%24 = phi i32 [ %21, %16 ], [ -1, %12 ], [ -1, %9 ], [ -1, %6 ], [ -1, %2 ]
%25 = tail call i32 @free(i8* %23)
ret i32 %24
}