#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 base32_decode_into(char const *, int, char *);
int strlen(char const *);
int valid_tth(const char *tth) {
  if (tth == NULL)
    return 0;
  int tthlen = strlen(tth);
  if (tthlen < 39 || tthlen > 40)
    return 0;
  char decbuf[25];
  return (base32_decode_into(tth, tthlen, decbuf) == 24 ? 1 : 0);
}


x86 assembly (clang, -O0):
<valid_tth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <valid_tth+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1191 <valid_tth+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x27,-0x14(%rbp)
jl     1163 <valid_tth+0x43>
cmpl   $0x28,-0x14(%rbp)
jle    116f <valid_tth+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1191 <valid_tth+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x30(%rbp),%rdx
call   1040 <base32_decode_into@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x18,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_tth>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     1153 <valid_tth+0x33>
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    -0x29(%rax),%ecx
cmp    $0xfffffffe,%ecx
jb     1153 <valid_tth+0x33>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <base32_decode_into@plt>
xor    %ebp,%ebp
cmp    $0x18,%eax
sete   %bpl
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @valid_tth(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [25 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %26
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 39
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 40
br i1 %16, label %17, label %18
17: ; preds = %14, %9
store i32 0, i32* %2
br label %26
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%22 = call i32 @base32_decode_into(i8* %19, i32 %20, i8* %21)
%23 = icmp eq i32 %22, 24
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 0
store i32 %25, i32* %2
br label %26
26: ; preds = %18, %17, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @valid_tth(i8* %0) {
%2 = alloca [25 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = add i32 %5, -41
%7 = icmp ult i32 %6, -2
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%10 = call i32 @base32_decode_into(i8* %0, i32 %5, i8* %9)
%11 = icmp eq i32 %10, 24
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %8, %4, %1
%14 = phi i32 [ 0, %1 ], [ %12, %8 ], [ 0, %4 ]
ret i32 %14
}