#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 ahead_c(unsigned char const *, int, int);
scalar_t__ n_digits(unsigned char const *, int, int);
int try_c(const unsigned char source[], int position, int length) {
  int retval = 0;
  if (n_digits(source, position, length) > 0) {
    if (ahead_c(source, position, length) >
        ahead_c(source, position + 1, length)) {
      retval = ahead_c(source, position, length);
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<try_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <n_digits@plt>
cmp    $0x0,%rax
jle    119a <try_c+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <ahead_c@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <ahead_c@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jle    1195 <try_c+0x75>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <ahead_c@plt>
mov    %eax,-0x14(%rbp)
jmp    119a <try_c+0x7a>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_c>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%rbp
call   1040 <n_digits@plt>
test   %rax,%rax
jle    1173 <try_c+0x53>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <ahead_c@plt>
mov    %eax,%r15d
lea    0x1(%rbx),%esi
mov    %rbp,%rdi
mov    %r14d,%edx
call   1030 <ahead_c@plt>
cmp    %eax,%r15d
jle    1173 <try_c+0x53>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <ahead_c@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @try_c(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @n_digits(i8* %0, i32 %1, i32 %2)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i32 @ahead_c(i8* %0, i32 %1, i32 %2)
%8 = add nsw i32 %1, 1
%9 = tail call i32 @ahead_c(i8* %0, i32 %8, i32 %2)
%10 = icmp sgt i32 %7, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @ahead_c(i8* %0, i32 %1, i32 %2)
br label %13
13: ; preds = %6, %11, %3
%14 = phi i32 [ %12, %11 ], [ 0, %6 ], [ 0, %3 ]
ret i32 %14
}