#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 /*<<< orphan*/ ll2string(char *, int, long long);
scalar_t__ memcmp(char *, char *, size_t);
int rdbEncodeInteger(long long, unsigned char *);
size_t strlen(char *);
long long strtoll(char *, char **, int);
int rdbTryIntegerEncoding(char *s, size_t len, unsigned char *enc) {
  long long value;
  char *endptr, buf[32];
  value = strtoll(s, &endptr, 10);
  if (endptr[0] != '\0')
    return 0;
  ll2string(buf, 32, value);
  if (strlen(buf) != len || memcmp(buf, s, len))
    return 0;
  return rdbEncodeInteger(value, enc);
}


x86 assembly (clang, -O0):
<rdbTryIntegerEncoding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoll@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <rdbTryIntegerEncoding+0x46>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <rdbTryIntegerEncoding+0xa2>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x20,%esi
call   1060 <ll2string@plt>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x18(%rbp),%rax
jne    11d6 <rdbTryIntegerEncoding+0x86>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11e2 <rdbTryIntegerEncoding+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <rdbTryIntegerEncoding+0xa2>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <rdbEncodeInteger@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdbTryIntegerEncoding>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtoll@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rax
xor    %ebp,%ebp
cmpb   $0x0,(%rax)
jne    11c9 <rdbTryIntegerEncoding+0x79>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x20,%esi
mov    %r15,%rdx
call   1060 <ll2string@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
cmp    %r12,%rax
jne    11c9 <rdbTryIntegerEncoding+0x79>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11c9 <rdbTryIntegerEncoding+0x79>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <rdbEncodeInteger@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rdbTryIntegerEncoding(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca [32 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = call i64 @strtoll(i8* %11, i8** %9, i32 10)
store i64 %12, i64* %8
%13 = load i8*, i8** %9
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 0, i32* %4
br label %38
19: ; preds = %3
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%21 = load i64, i64* %8
%22 = call i32 @ll2string(i8* %20, i32 32, i64 %21)
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = load i64, i64* %6
%26 = icmp ne i64 %24, %25
br i1 %26, label %33, label %27
27: ; preds = %19
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = call i64 @memcmp(i8* %28, i8* %29, i64 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27, %19
store i32 0, i32* %4
br label %38
34: ; preds = %27
%35 = load i64, i64* %8
%36 = load i8*, i8** %7
%37 = call i32 @rdbEncodeInteger(i64 %35, i8* %36)
store i32 %37, i32* %4
br label %38
38: ; preds = %34, %33, %18
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @rdbTryIntegerEncoding(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = call i64 @strtoll(i8* %0, i8** %4, i32 10)
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = call i32 @ll2string(i8* %7, i32 32, i64 %8)
%14 = call i64 @strlen(i8* %7)
%15 = icmp eq i64 %14, %1
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i64 @memcmp(i8* %7, i8* %0, i64 %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @rdbEncodeInteger(i64 %8, i8* %2)
br label %21
21: ; preds = %12, %16, %3, %19
%22 = phi i32 [ %20, %19 ], [ 0, %3 ], [ 0, %16 ], [ 0, %12 ]
ret i32 %22
}