#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 node_t {
  int dummy;
};

/* Variables and functions */
int pick_next(int, struct node_t *, int);
int fleury(struct node_t *g, int n, int *out) {
  int traversed = 0;
  int next = 0;
  out[traversed] = 0;
  while (next >= 0) {
    next = pick_next(next, g, n);
    if (next >= 0)
      out[++traversed] = next;
  }
  return traversed;
}


x86 assembly (clang, -O0):
<fleury>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
cmpl   $0x0,-0x20(%rbp)
jl     1181 <fleury+0x71>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <pick_next@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     117c <fleury+0x6c>
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1140 <fleury+0x30>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fleury>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
movl   $0x0,(%rdx)
xor    %ebp,%ebp
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <pick_next@plt>
test   %eax,%eax
js     115a <fleury+0x4a>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %eax,0x4(%r14,%rbp,4)
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <pick_next@plt>
add    $0x1,%rbp
test   %eax,%eax
jns    1140 <fleury+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node_t = type { i32 }
define i32 @fleury(%struct.node_t* %0, i32 %1, i32* %2) {
%4 = alloca %struct.node_t*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store %struct.node_t* %0, %struct.node_t** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32*, i32** %6
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %9, i64 %11
store i32 0, i32* %12
br label %13
13: ; preds = %30, %3
%14 = load i32, i32* %8
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i32, i32* %8
%18 = load %struct.node_t*, %struct.node_t** %4
%19 = load i32, i32* %5
%20 = call i32 @pick_next(i32 %17, %struct.node_t* %18, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %16
%24 = load i32, i32* %8
%25 = load i32*, i32** %6
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
store i32 %24, i32* %29
br label %30
30: ; preds = %23, %16
br label %13
31: ; preds = %13
%32 = load i32, i32* %7
ret i32 %32
}

LLVM IR (-O2):
%struct.node_t = type { i32 }
define i32 @fleury(%struct.node_t* %0, i32 %1, i32* nocapture writeonly %2) {
store i32 0, i32* %2
%4 = tail call i32 @pick_next(i32 0, %struct.node_t* %0, i32 %1)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ %4, %3 ]
%8 = phi i32 [ %9, %6 ], [ 0, %3 ]
%9 = add nuw nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %2, i64 %10
store i32 %7, i32* %11
%12 = tail call i32 @pick_next(i32 %7, %struct.node_t* %0, i32 %1)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %6, label %14
14: ; preds = %6, %3
%15 = phi i32 [ 0, %3 ], [ %9, %6 ]
ret i32 %15
}