#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_borrow(char *, size_t, char);
char *strchr(char *, char);
char *_find_digit(char *buf, size_t buf_len, char digit) {
  char *l = strchr(buf, digit);
  if (!l) {
    if (0 != rnc_borrow(buf, buf_len, digit)) {
      return NULL;
    }
    l = strchr(buf, digit);
    if (!l) {
      return NULL;
    }
  }
  return l;
}


x86 assembly (clang, -O0):
<_find_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ab <_find_digit+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsbl -0x19(%rbp),%edx
call   1040 <rnc_borrow@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     117d <_find_digit+0x5d>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <_find_digit+0x93>
mov    -0x10(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <_find_digit+0x86>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <_find_digit+0x93>
jmp    11ab <_find_digit+0x8b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_find_digit>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    115f <_find_digit+0x3f>
movsbl %bpl,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <rnc_borrow@plt>
test   %rax,%rax
jne    115d <_find_digit+0x3d>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    115f <_find_digit+0x3f>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @_find_digit(i8* %0, i64 %1, i8 signext %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i64 @rnc_borrow(i8* %0, i64 %1, i8 signext %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9, %3
%13 = phi i8* [ %4, %3 ], [ %10, %9 ]
br label %14
14: ; preds = %9, %6, %12
%15 = phi i8* [ %13, %12 ], [ null, %6 ], [ null, %9 ]
ret i8* %15
}