#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 graph_vertex {
  int dummy;
};
struct graph_arc {
  int dummy;
};

/* Variables and functions */
struct graph_arc *a_next(struct graph_arc *);
struct graph_arc *v_arcs_first(struct graph_vertex *);
int /*<<< orphan*/ v_arcs_is_done(struct graph_arc *, struct graph_vertex *);
size_t v_arcs_length(struct graph_vertex *_l0) {
  size_t count = 0;
  struct graph_arc *_e0 = v_arcs_first(_l0);
  while (!v_arcs_is_done(_e0, _l0)) {
    count++;
    _e0 = a_next(_e0);
  }
  return count;
}


x86 assembly (clang, -O0):
<v_arcs_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <v_arcs_first@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <v_arcs_is_done@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1173 <v_arcs_length+0x43>
jmp    1191 <v_arcs_length+0x61>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <a_next@plt>
mov    %rax,-0x18(%rbp)
jmp    1151 <v_arcs_length+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_arcs_length>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <v_arcs_first@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <v_arcs_is_done@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    117e <v_arcs_length+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <a_next@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <v_arcs_is_done@plt>
test   %eax,%eax
je     1160 <v_arcs_length+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.graph_vertex = type { i32 }
%struct.graph_arc = type { i32 }
define i64 @v_arcs_length(%struct.graph_vertex* %0) {
%2 = alloca %struct.graph_vertex*
%3 = alloca i64
%4 = alloca %struct.graph_arc*
store %struct.graph_vertex* %0, %struct.graph_vertex** %2
store i64 0, i64* %3
%5 = load %struct.graph_vertex*, %struct.graph_vertex** %2
%6 = call %struct.graph_arc* @v_arcs_first(%struct.graph_vertex* %5)
store %struct.graph_arc* %6, %struct.graph_arc** %4
br label %7
7: ; preds = %13, %1
%8 = load %struct.graph_arc*, %struct.graph_arc** %4
%9 = load %struct.graph_vertex*, %struct.graph_vertex** %2
%10 = call i32 @v_arcs_is_done(%struct.graph_arc* %8, %struct.graph_vertex* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = load i64, i64* %3
%15 = add i64 %14, 1
store i64 %15, i64* %3
%16 = load %struct.graph_arc*, %struct.graph_arc** %4
%17 = call %struct.graph_arc* @a_next(%struct.graph_arc* %16)
store %struct.graph_arc* %17, %struct.graph_arc** %4
br label %7
18: ; preds = %7
%19 = load i64, i64* %3
ret i64 %19
}

LLVM IR (-O2):
%struct.graph_vertex = type { i32 }
%struct.graph_arc = type { i32 }
define i64 @v_arcs_length(%struct.graph_vertex* %0) {
%2 = tail call %struct.graph_arc* @v_arcs_first(%struct.graph_vertex* %0)
%3 = tail call i32 @v_arcs_is_done(%struct.graph_arc* %2, %struct.graph_vertex* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %1, %5
%6 = phi %struct.graph_arc* [ %9, %5 ], [ %2, %1 ]
%7 = phi i64 [ %8, %5 ], [ 0, %1 ]
%8 = add i64 %7, 1
%9 = tail call %struct.graph_arc* @a_next(%struct.graph_arc* %6)
%10 = tail call i32 @v_arcs_is_done(%struct.graph_arc* %9, %struct.graph_vertex* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %5, label %12
12: ; preds = %5, %1
%13 = phi i64 [ 0, %1 ], [ %8, %5 ]
ret i64 %13
}