#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) {
  if (s && *s) {
    size_t sz = strlen(s) - 1;
    s += sz;
    if ((unsigned char)*s == c)
      return (char *)s;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<last_char_is>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117a <last_char_is+0x6a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117a <last_char_is+0x6a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    1175 <last_char_is+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1182 <last_char_is+0x72>
jmp    117a <last_char_is+0x6a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_char_is>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     113e <last_char_is+0x2e>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     113e <last_char_is+0x2e>
mov    %esi,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movzbl -0x1(%rax,%rbx,1),%ecx
cmp    %ebp,%ecx
jne    113e <last_char_is+0x2e>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    1140 <last_char_is+0x30>
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 i64
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 %9, label %30
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 %19
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = load i32, i32* %5
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = load i8*, i8** %4
store i8* %28, i8** %3
br label %31
29: ; preds = %14
br label %30
30: ; preds = %29, %9, %2
store i8* null, i8** %3
br label %31
31: ; preds = %30, %27
%32 = load i8*, i8** %3
ret i8* %32
}

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 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, %1
br i1 %14, label %16, label %15
15: ; preds = %7, %4, %2
br label %16
16: ; preds = %7, %15
%17 = phi i8* [ %11, %7 ], [ null, %15 ]
ret i8* %17
}