#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 */
typedef int /*<<< orphan*/ u_int32_t;

/* Variables and functions */
size_t u8_strlen(int /*<<< orphan*/ const *);
scalar_t__ u8_strncmp(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                      size_t);
int u8_ends_with(const u_int32_t *s1, const u_int32_t *s2) {
  size_t s1_len = u8_strlen(s1);
  size_t s2_len = u8_strlen(s2);
  if (s1_len < s2_len)
    return 0;
  return (u8_strncmp(&s1[s1_len - s2_len], s2, u8_strlen(s2)) == 0);
}


x86 assembly (clang, -O0):
<u8_ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <u8_strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <u8_strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1164 <u8_ends_with+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11ab <u8_ends_with+0x8b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    -0x28(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <u8_strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1030 <u8_strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u8_ends_with>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <u8_strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <u8_strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rbx
jb     116a <u8_ends_with+0x4a>
lea    (%r15,%rbx,4),%rbx
mov    %r14,%rdi
call   1040 <u8_strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <u8_strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret

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

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