#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 strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
bool endwith(const char *str, const char *pro) {
  int shift = strlen(str) - strlen(pro);
  if (shift < 0)
    return false;
  return strncmp(pro, str + shift, strlen(pro)) == 0;
}


x86 assembly (clang, -O0):
<endwith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1165 <endwith+0x45>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <endwith+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%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):
<endwith>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
js     1164 <endwith+0x44>
mov    %ebp,%eax
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1166 <endwith+0x46>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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