#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 dfs(int, int *, int *, int);
int *roadlength_prepare(int *, int, int);
int roadlength_main(int roads[], int player) {
  int numroads = -1;
  while (roads[++numroads] != 0)
    ;
  numroads /= 2;
  int max = 0;
  int i, len;
  int *graph = roadlength_prepare(roads, numroads, player);
  static int beento[30];
  for (i = 0; i < 30; i++)
    beento[i] = 100;
  for (i = 0; graph[i * 3] != 100; i++) {
    len = dfs(i, graph, beento, 100);
    if (len > max)
      max = len;
  }
  if (max == 0)
    max++;
  return max - 1;
}


x86 assembly (clang, -O0):
<roadlength_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1155 <roadlength_main+0x35>
jmp    1136 <roadlength_main+0x16>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <roadlength_prepare@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1e,-0x18(%rbp)
jge    11ae <roadlength_main+0x8e>
movslq -0x18(%rbp),%rcx
lea    0x2ea7(%rip),%rax
movl   $0x64,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1184 <roadlength_main+0x64>
movl   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
movslq %ecx,%rcx
cmpl   $0x64,(%rax,%rcx,4)
je     120a <roadlength_main+0xea>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
lea    0x2e68(%rip),%rdx
mov    $0x64,%ecx
call   1040 <dfs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11f7 <roadlength_main+0xd7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11fc <roadlength_main+0xdc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b5 <roadlength_main+0x95>
cmpl   $0x0,-0x14(%rbp)
jne    121d <roadlength_main+0xfd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roadlength_main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%edx
xor    %eax,%eax
nopl   0x0(%rax)
cmpl   $0x0,(%rdi,%rax,4)
lea    0x1(%rax),%rax
jne    1130 <roadlength_main+0x10>
mov    %eax,%ecx
add    $0xffffffff,%ecx
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%esi
add    $0xffffffff,%esi
sar    %esi
call   1030 <roadlength_prepare@plt>
mov    %rax,%r14
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x2ee0(%rip)
movaps %xmm0,0x2ee9(%rip)
movaps %xmm0,0x2ef2(%rip)
movaps %xmm0,0x2efb(%rip)
movaps %xmm0,0x2f04(%rip)
movaps %xmm0,0x2f0d(%rip)
movaps %xmm0,0x2f16(%rip)
movabs $0x6400000064,%rax
mov    %rax,0x2f15(%rip)
cmpl   $0x64,(%r14)
je     11ef <roadlength_main+0xcf>
xor    %ebx,%ebx
mov    $0x3,%ebp
lea    0x2e91(%rip),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x64,%ecx
call   1040 <dfs@plt>
cmp    %r12d,%eax
cmovg  %eax,%r12d
mov    %ebp,%eax
add    $0x1,%ebx
add    $0x3,%rbp
cmpl   $0x64,(%r14,%rax,4)
jne    11c0 <roadlength_main+0xa0>
sub    $0x1,%r12d
jae    11f2 <roadlength_main+0xd2>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@roadlength_main.beento = internal global [30 x i32] zeroinitializer
define i32 @roadlength_main(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
br label %10
10: ; preds = %18, %2
%11 = load i32*, i32** %3
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %11, i64 %14
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
br label %10
19: ; preds = %10
%20 = load i32, i32* %5
%21 = sdiv i32 %20, 2
store i32 %21, i32* %5
store i32 0, i32* %6
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = call i32* @roadlength_prepare(i32* %22, i32 %23, i32 %24)
store i32* %25, i32** %9
store i32 0, i32* %7
br label %26
26: ; preds = %33, %19
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 30
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 %31
store i32 100, i32* %32
br label %33
33: ; preds = %29
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %26
36: ; preds = %26
store i32 0, i32* %7
br label %37
37: ; preds = %55, %36
%38 = load i32*, i32** %9
%39 = load i32, i32* %7
%40 = mul nsw i32 %39, 3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %38, i64 %41
%43 = load i32, i32* %42
%44 = icmp ne i32 %43, 100
br i1 %44, label %45, label %58
45: ; preds = %37
%46 = load i32, i32* %7
%47 = load i32*, i32** %9
%48 = call i32 @dfs(i32 %46, i32* %47, i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 0), i32 100)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = load i32, i32* %6
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = load i32, i32* %8
store i32 %53, i32* %6
br label %54
54: ; preds = %52, %45
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %37
58: ; preds = %37
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %64
64: ; preds = %61, %58
%65 = load i32, i32* %6
%66 = sub nsw i32 %65, 1
ret i32 %66
}

LLVM IR (-O2):
@roadlength_main.beento = internal global [30 x i32] zeroinitializer
define i32 @roadlength_main(i32* %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %5, %3 ], [ -1, %2 ]
%5 = add nsw i64 %4, 1
%6 = getelementptr inbounds i32, i32* %0, i64 %5
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = trunc i64 %5 to i32
%11 = sdiv i32 %10, 2
%12 = tail call i32* @roadlength_prepare(i32* %0, i32 %11, i32 %1)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast ([30 x i32]* @roadlength_main.beento to <4 x i32>*)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast (i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 4) to <4 x i32>*)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast (i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 8) to <4 x i32>*)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast (i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 12) to <4 x i32>*)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast (i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 16) to <4 x i32>*)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast (i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 20) to <4 x i32>*)
store <4 x i32> <i32 100, i32 100, i32 100, i32 100>, <4 x i32>* bitcast (i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 24) to <4 x i32>*)
store i32 100, i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 28)
store i32 100, i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 29)
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 100
br i1 %14, label %31, label %15
15: ; preds = %9, %15
%16 = phi i64 [ %22, %15 ], [ 0, %9 ]
%17 = phi i32 [ %21, %15 ], [ 0, %9 ]
%18 = trunc i64 %16 to i32
%19 = tail call i32 @dfs(i32 %18, i32* %12, i32* getelementptr inbounds ([30 x i32], [30 x i32]* @roadlength_main.beento, i64 0, i64 0), i32 100)
%20 = icmp sgt i32 %19, %17
%21 = select i1 %20, i32 %19, i32 %17
%22 = add nuw i64 %16, 1
%23 = mul i64 %22, 3
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds i32, i32* %12, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 100
br i1 %27, label %28, label %15
28: ; preds = %15
%29 = icmp eq i32 %21, 0
%30 = add nsw i32 %21, -1
br i1 %29, label %31, label %32
31: ; preds = %9, %28
br label %32
32: ; preds = %28, %31
%33 = phi i32 [ 0, %31 ], [ %30, %28 ]
ret i32 %33
}