#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 *);
char *last_char_is(const char *s, int c) {
  char *sret;
  if (!s)
    return NULL;
  sret = (char *)s + strlen(s) - 1;
  if (sret >= s && *sret == c) {
    return sret;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<last_char_is>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <last_char_is+0x27>
movq   $0x0,-0x8(%rbp)
jmp    118f <last_char_is+0x7f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     1187 <last_char_is+0x77>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    1187 <last_char_is+0x77>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <last_char_is+0x7f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_char_is>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1137 <last_char_is+0x27>
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1137 <last_char_is+0x27>
movsbl (%rax),%ecx
cmp    %ebp,%ecx
je     1139 <last_char_is+0x29>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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