#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 */
struct itree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
struct itree *itree_first_child(struct itree *);
struct itree *itree_next_sibling(struct itree *);
size_t itree_child_count(struct itree const *node) {
  struct itree *p;
  size_t i;
  assert(node != NULL);
  i = 0;
  p = (struct itree *)node;
  for (p = itree_first_child(p); p; p = itree_next_sibling(p))
    i++;
  return i;
}


x86 assembly (clang, -O0):
<itree_child_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <itree_first_child@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1194 <itree_child_count+0x64>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <itree_next_sibling@plt>
mov    %rax,-0x10(%rbp)
jmp    116b <itree_child_count+0x3b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itree_child_count>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <itree_first_child@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1171 <itree_child_count+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rax,%rdi
call   1030 <itree_next_sibling@plt>
test   %rax,%rax
jne    1160 <itree_child_count+0x30>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.itree = type { i32 }
define i64 @itree_child_count(%struct.itree* %0) {
%2 = alloca %struct.itree*
%3 = alloca %struct.itree*
%4 = alloca i64
store %struct.itree* %0, %struct.itree** %2
%5 = load %struct.itree*, %struct.itree** %2
%6 = icmp ne %struct.itree* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
store i64 0, i64* %4
%9 = load %struct.itree*, %struct.itree** %2
store %struct.itree* %9, %struct.itree** %3
%10 = load %struct.itree*, %struct.itree** %3
%11 = call %struct.itree* @itree_first_child(%struct.itree* %10)
store %struct.itree* %11, %struct.itree** %3
br label %12
12: ; preds = %18, %1
%13 = load %struct.itree*, %struct.itree** %3
%14 = icmp ne %struct.itree* %13, null
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i64, i64* %4
%17 = add i64 %16, 1
store i64 %17, i64* %4
br label %18
18: ; preds = %15
%19 = load %struct.itree*, %struct.itree** %3
%20 = call %struct.itree* @itree_next_sibling(%struct.itree* %19)
store %struct.itree* %20, %struct.itree** %3
br label %12
21: ; preds = %12
%22 = load i64, i64* %4
ret i64 %22
}

LLVM IR (-O2):
%struct.itree = type { i32 }
define i64 @itree_child_count(%struct.itree* %0) {
%2 = icmp ne %struct.itree* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call %struct.itree* @itree_first_child(%struct.itree* %0)
%6 = icmp eq %struct.itree* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %10, %7 ], [ 0, %1 ]
%9 = phi %struct.itree* [ %11, %7 ], [ %5, %1 ]
%10 = add i64 %8, 1
%11 = tail call %struct.itree* @itree_next_sibling(%struct.itree* %9)
%12 = icmp eq %struct.itree* %11, null
br i1 %12, label %13, label %7
13: ; preds = %7, %1
%14 = phi i64 [ 0, %1 ], [ %10, %7 ]
ret i64 %14
}