#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*/ strcmp(char *, char *);
int strlen(char *);
int pl_endswith(char *string, char *postfix) {
  char *pch = NULL;
  int ret_val = -1;
  int string_length = 0, postfix_length = 0;
  if (string == NULL || postfix == NULL) {
    goto error_exit;
  }
  string_length = strlen(string);
  postfix_length = strlen(postfix);
  if (string_length == 0 || postfix_length == 0) {
    goto error_exit;
  }
  pch = string + string_length - postfix_length;
  if (!strcmp(pch, postfix)) {
    ret_val = 1;
  } else {
    ret_val = 0;
  }
  return ret_val;
error_exit:
  return ret_val;
}


x86 assembly (clang, -O0):
<pl_endswith>:
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)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1163 <pl_endswith+0x43>
cmpq   $0x0,-0x18(%rbp)
jne    1168 <pl_endswith+0x48>
jmp    11e8 <pl_endswith+0xc8>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1194 <pl_endswith+0x74>
cmpl   $0x0,-0x2c(%rbp)
jne    1199 <pl_endswith+0x79>
jmp    11e8 <pl_endswith+0xc8>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <pl_endswith+0xb6>
movl   $0x1,-0x24(%rbp)
jmp    11dd <pl_endswith+0xbd>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <pl_endswith+0xce>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_endswith>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1173 <pl_endswith+0x53>
mov    %rsi,%r14
test   %rsi,%rsi
je     1173 <pl_endswith+0x53>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %r15d,%r15d
je     1173 <pl_endswith+0x53>
test   %eax,%eax
je     1173 <pl_endswith+0x53>
movslq %r15d,%rcx
add    %rcx,%rbx
cltq
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pl_endswith(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = 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
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %12, %2
br label %44
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %8
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %9
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23, %16
br label %44
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = sub i64 0, %33
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = load i8*, i8** %5
%38 = call i32 @strcmp(i8* %36, i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %27
store i32 1, i32* %7
br label %42
41: ; preds = %27
store i32 0, i32* %7
br label %42
42: ; preds = %41, %40
%43 = load i32, i32* %7
store i32 %43, i32* %3
br label %46
44: ; preds = %26, %15
%45 = load i32, i32* %7
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %42
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @pl_endswith(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 %21, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = icmp eq i32 %7, 0
%10 = icmp eq i32 %8, 0
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = sext i32 %8 to i64
%16 = sub nsw i64 0, %15
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(1) %1)
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %2, %6, %12
%22 = phi i32 [ %20, %12 ], [ -1, %6 ], [ -1, %2 ]
ret i32 %22
}