#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 graph_connected_components_perm(int, int *, int *, int *, int *, int *);
int /*<<< orphan*/ graph_reverse(int, int *, int *, int *, int *);
int /*<<< orphan*/ topological_order(int, int *, int *, int *, int *);
int *u_alloc(int, int **);
int kosraju_sharir_scc(int n, int *xadj, int *adj, int *part, int *aux) {
  int nnz = xadj[n];
  int *auxptr = aux;
  int *rxadj = u_alloc(n + 2, &auxptr);
  int *radj = u_alloc(nnz, &auxptr);
  int *perm = u_alloc(n, &auxptr);
  graph_reverse(n, xadj, adj, rxadj, radj);
  topological_order(n, rxadj, radj, perm, aux);
  return graph_connected_components_perm(n, xadj, adj, perm, part, auxptr);
}


x86 assembly (clang, -O0):
<kosraju_sharir_scc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
add    $0x2,%edi
lea    -0x38(%rbp),%rsi
call   1040 <u_alloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1040 <u_alloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1040 <u_alloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1060 <graph_reverse@plt>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1050 <topological_order@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1030 <graph_connected_components_perm@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kosraju_sharir_scc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdx,%r12
mov    %rsi,%r13
movslq %edi,%rbx
mov    (%rsi,%rbx,4),%ebp
mov    %r8,(%rsp)
lea    0x2(%rbx),%edi
mov    %rsp,%r14
mov    %r14,%rsi
call   1040 <u_alloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <u_alloc@plt>
mov    %rax,%rbp
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <u_alloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %rbp,%r8
call   1060 <graph_reverse@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    0x8(%rsp),%r8
call   1050 <topological_order@plt>
mov    (%rsp),%r9
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    0x10(%rsp),%r8
call   1030 <graph_connected_components_perm@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @kosraju_sharir_scc(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%16 = load i32*, i32** %7
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %11
%21 = load i32*, i32** %10
store i32* %21, i32** %12
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 2
%24 = call i32* @u_alloc(i32 %23, i32** %12)
store i32* %24, i32** %13
%25 = load i32, i32* %11
%26 = call i32* @u_alloc(i32 %25, i32** %12)
store i32* %26, i32** %14
%27 = load i32, i32* %6
%28 = call i32* @u_alloc(i32 %27, i32** %12)
store i32* %28, i32** %15
%29 = load i32, i32* %6
%30 = load i32*, i32** %7
%31 = load i32*, i32** %8
%32 = load i32*, i32** %13
%33 = load i32*, i32** %14
%34 = call i32 @graph_reverse(i32 %29, i32* %30, i32* %31, i32* %32, i32* %33)
%35 = load i32, i32* %6
%36 = load i32*, i32** %13
%37 = load i32*, i32** %14
%38 = load i32*, i32** %15
%39 = load i32*, i32** %10
%40 = call i32 @topological_order(i32 %35, i32* %36, i32* %37, i32* %38, i32* %39)
%41 = load i32, i32* %6
%42 = load i32*, i32** %7
%43 = load i32*, i32** %8
%44 = load i32*, i32** %15
%45 = load i32*, i32** %9
%46 = load i32*, i32** %12
%47 = call i32 @graph_connected_components_perm(i32 %41, i32* %42, i32* %43, i32* %44, i32* %45, i32* %46)
ret i32 %47
}

LLVM IR (-O2):
define i32 @kosraju_sharir_scc(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = sext i32 %0 to i64
%8 = getelementptr inbounds i32, i32* %1, i64 %7
%9 = load i32, i32* %8
%10 = bitcast i32** %6 to i8*
store i32* %4, i32** %6
%11 = add nsw i32 %0, 2
%12 = call i32* @u_alloc(i32 %11, i32** %6)
%13 = call i32* @u_alloc(i32 %9, i32** %6)
%14 = call i32* @u_alloc(i32 %0, i32** %6)
%15 = call i32 @graph_reverse(i32 %0, i32* %1, i32* %2, i32* %12, i32* %13)
%16 = call i32 @topological_order(i32 %0, i32* %12, i32* %13, i32* %14, i32* %4)
%17 = load i32*, i32** %6
%18 = call i32 @graph_connected_components_perm(i32 %0, i32* %1, i32* %2, i32* %14, i32* %3, i32* %17)
ret i32 %18
}