#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 order {
  int dummy;
};
struct node {
  int dummy;
};

/* Variables and functions */
scalar_t__ malloc(int);
int visit(int, struct node **, int, int *, int, int, struct order *);
void dfs(struct node *adj[], int V, struct order *values) {
  int k = 0, id = 1, count = 1;
  int *val;
  val = (int *)malloc((V + 2) * sizeof(int));
  for (k = 1; k <= V; k++) {
    if (val[k] == 0) {
      count = visit(k, adj, id, val, V, count, values);
      id++;
    }
  }
  id--;
}


x86 assembly (clang, -O0):
<dfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11c6 <dfs+0xa6>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11b3 <dfs+0x93>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x18(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <visit@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b8 <dfs+0x98>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <dfs+0x46>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dfs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %esi,%r12d
mov    %rdi,%r15
lea    0x8(,%r12,4),%edi
call   1030 <malloc@plt>
test   %r12d,%r12d
jle    11a4 <dfs+0x84>
mov    %rax,%r13
lea    0x1(%r12),%r14d
mov    $0x1,%eax
mov    $0x1,%ebx
mov    $0x1,%ebp
jmp    1179 <dfs+0x59>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r14
je     11a4 <dfs+0x84>
cmpl   $0x0,0x0(%r13,%rbx,4)
jne    1170 <dfs+0x50>
mov    0x10(%rsp),%rcx
mov    %rcx,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
mov    %r12d,%r8d
mov    %eax,%r9d
call   1040 <visit@plt>
add    $0x1,%ebp
jmp    1170 <dfs+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
%struct.order = type { i32 }
define void @dfs(%struct.node** %0, i32 %1, %struct.order* %2) {
%4 = alloca %struct.node**
%5 = alloca i32
%6 = alloca %struct.order*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store %struct.node** %0, %struct.node*** %4
store i32 %1, i32* %5
store %struct.order* %2, %struct.order** %6
store i32 0, i32* %7
store i32 1, i32* %8
store i32 1, i32* %9
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %10
store i32 1, i32* %7
br label %18
18: ; preds = %41, %3
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %44
22: ; preds = %18
%23 = load i32*, i32** %10
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %22
%30 = load i32, i32* %7
%31 = load %struct.node**, %struct.node*** %4
%32 = load i32, i32* %8
%33 = load i32*, i32** %10
%34 = load i32, i32* %5
%35 = load i32, i32* %9
%36 = load %struct.order*, %struct.order** %6
%37 = call i32 @visit(i32 %30, %struct.node** %31, i32 %32, i32* %33, i32 %34, i32 %35, %struct.order* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %40
40: ; preds = %29, %22
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %18
44: ; preds = %18
%45 = load i32, i32* %8
%46 = add nsw i32 %45, -1
store i32 %46, i32* %8
ret void
}

LLVM IR (-O2):
%struct.node = type { i32 }
%struct.order = type { i32 }
define void @dfs(%struct.node** %0, i32 %1, %struct.order* %2) {
%4 = shl i32 %1, 2
%5 = add i32 %4, 8
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32*
%8 = icmp slt i32 %1, 1
br i1 %8, label %28, label %9
9: ; preds = %3
%10 = add nuw i32 %1, 1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %9, %23
%13 = phi i64 [ 1, %9 ], [ %26, %23 ]
%14 = phi i32 [ 1, %9 ], [ %25, %23 ]
%15 = phi i32 [ 1, %9 ], [ %24, %23 ]
%16 = getelementptr inbounds i32, i32* %7, i64 %13
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = trunc i64 %13 to i32
%21 = tail call i32 @visit(i32 %20, %struct.node** %0, i32 %15, i32* %7, i32 %1, i32 %14, %struct.order* %2)
%22 = add nsw i32 %15, 1
br label %23
23: ; preds = %12, %19
%24 = phi i32 [ %22, %19 ], [ %15, %12 ]
%25 = phi i32 [ %21, %19 ], [ %14, %12 ]
%26 = add nuw nsw i64 %13, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %28, label %12
28: ; preds = %23, %3
ret void
}