#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 */
void *wg_first(void *, void *);
scalar_t__ wg_ispair(void *, void *);
void *wg_rest(void *, void *);
int wg_listtreecount(void *db, void *ptr) {
  if (wg_ispair(db, ptr))
    return wg_listtreecount(db, wg_first(db, ptr)) +
           wg_listtreecount(db, wg_rest(db, ptr));
  else
    return 1;
}


x86 assembly (clang, -O0):
<wg_listtreecount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <wg_ispair@plt>
cmp    $0x0,%rax
je     11bb <wg_listtreecount+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <wg_first@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1040 <wg_listtreecount@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <wg_rest@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1040 <wg_listtreecount@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <wg_listtreecount+0x82>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wg_listtreecount>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <wg_ispair@plt>
test   %rax,%rax
je     119f <wg_listtreecount+0x5f>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <wg_first@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <wg_listtreecount@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <wg_rest@plt>
mov    %rax,%rbx
add    %r15d,%ebp
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <wg_ispair@plt>
test   %rax,%rax
jne    1160 <wg_listtreecount+0x20>
add    $0x1,%ebp
jmp    11a4 <wg_listtreecount+0x64>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wg_listtreecount(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = load i8*, i8** %5
%8 = call i64 @wg_ispair(i8* %6, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i8* @wg_first(i8* %12, i8* %13)
%15 = call i32 @wg_listtreecount(i8* %11, i8* %14)
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i8* @wg_rest(i8* %17, i8* %18)
%20 = call i32 @wg_listtreecount(i8* %16, i8* %19)
%21 = add nsw i32 %15, %20
store i32 %21, i32* %3
br label %23
22: ; preds = %2
store i32 1, i32* %3
br label %23
23: ; preds = %22, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @wg_listtreecount(i8* %0, i8* %1) {
%3 = tail call i64 @wg_ispair(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2, %5
%6 = phi i8* [ %10, %5 ], [ %1, %2 ]
%7 = phi i32 [ %11, %5 ], [ 0, %2 ]
%8 = tail call i8* @wg_first(i8* %0, i8* %6)
%9 = tail call i32 @wg_listtreecount(i8* %0, i8* %8)
%10 = tail call i8* @wg_rest(i8* %0, i8* %6)
%11 = add nsw i32 %9, %7
%12 = tail call i64 @wg_ispair(i8* %0, i8* %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %5
14: ; preds = %5
%15 = add i32 %11, 1
br label %16
16: ; preds = %14, %2
%17 = phi i32 [ 1, %2 ], [ %15, %14 ]
ret i32 %17
}