#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 */
char *strchr(char const *, char);
scalar_t__ strcmp(char *, char const *);
unsigned int strlen(char const *);
const char *strfin(const char *s, const char *suffix) {
  char *p = strchr(s, '\0');
  unsigned int l = strlen(suffix);
  if (l > strlen(s))
    return NULL;
  p -= l;
  return strcmp(p, suffix) ? NULL : p;
}


x86 assembly (clang, -O0):
<strfin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jbe    1184 <strfin+0x54>
movq   $0x0,-0x8(%rbp)
jmp    11cd <strfin+0x9d>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11bd <strfin+0x8d>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11c5 <strfin+0x95>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jbe    114f <strfin+0x2f>
xor    %eax,%eax
jmp    116e <strfin+0x4e>
add    %r15,%rbx
mov    %ebp,%eax
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
cmove  %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strfin(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i8* @strchr(i8* %8, i8 signext 0)
store i8* %9, i8** %6
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = icmp ugt i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %32
17: ; preds = %2
%18 = load i32, i32* %7
%19 = load i8*, i8** %6
%20 = zext i32 %18 to i64
%21 = sub i64 0, %20
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = call i64 @strcmp(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %17
br label %30
28: ; preds = %17
%29 = load i8*, i8** %6
br label %30
30: ; preds = %28, %27
%31 = phi i8* [ null, %27 ], [ %29, %28 ]
store i8* %31, i8** %3
br label %32
32: ; preds = %30, %16
%33 = load i8*, i8** %3
ret i8* %33
}

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