#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 */
scalar_t__ rnc_larger(char, char);
int strlen(char *);
char *_last_larger_digit(char *num, char digit) {
  for (char *p = num + strlen(num); p >= num; p--) {
    if (rnc_larger(*p, digit)) {
      return p;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<_last_larger_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11a0 <_last_larger_digit+0x80>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
movsbl %al,%edi
movsbl -0x11(%rbp),%esi
call   1030 <rnc_larger@plt>
cmp    $0x0,%rax
je     118a <_last_larger_digit+0x6a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <_last_larger_digit+0x88>
jmp    118f <_last_larger_digit+0x6f>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1153 <_last_larger_digit+0x33>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_last_larger_digit>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
js     1158 <_last_larger_digit+0x38>
mov    %eax,%ebx
add    %r14,%rbx
movsbl %bpl,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
mov    %ebp,%esi
call   1030 <rnc_larger@plt>
test   %rax,%rax
jne    115a <_last_larger_digit+0x3a>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1140 <_last_larger_digit+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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