; LLVM IR from Dev-XYS/Algorithms :: Eulerian-Tour(Digraph).ll (Z7connecti)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.vertex = type { i32, i32, i32, i8 }
%struct.edge = type { i32, i32, i32 }

@V = external dso_local global [100010 x %struct.vertex], align 16
@E = external dso_local global [200010 x %struct.edge], align 16
@cnt = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7connecti(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %5
  %7 = getelementptr inbounds %struct.vertex, ptr %6, i32 0, i32 3
  %8 = load i8, ptr %7, align 4, !tbaa !9, !range !12, !noundef !13
  %9 = trunc i8 %8 to i1
  %10 = zext i1 %9 to i32
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %41

12:                                               ; preds = %1
  %13 = load i32, ptr @cnt, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @cnt, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.vertex, ptr %17, i32 0, i32 3
  store i8 1, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.vertex, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 16, !tbaa !14
  store i32 %23, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %34, %12
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %40

28:                                               ; preds = %24
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200010 x %struct.edge], ptr @E, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.edge, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  call void @_Z7connecti(i32 noundef %33)
  br label %34

34:                                               ; preds = %28
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200010 x %struct.edge], ptr @E, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.edge, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !17
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !18

40:                                               ; preds = %27
  br label %41

41:                                               ; preds = %40, %1
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 12}
!10 = !{!"_ZTS6vertex", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 12}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!10, !6, i64 0}
!15 = !{!16, !6, i64 4}
!16 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.vertex = type { i32, i32, i32, i8 }
%struct.edge = type { i32, i32, i32 }

@V = external dso_local local_unnamed_addr global [100010 x %struct.vertex], align 16
@E = external dso_local local_unnamed_addr global [200010 x %struct.edge], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7connecti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 12
  %5 = load i8, ptr %4, align 4, !tbaa !5, !range !11, !noundef !12
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %7, label %.loopexit

7:                                                ; preds = %1
  %8 = load i32, ptr @cnt, align 4, !tbaa !13
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @cnt, align 4, !tbaa !13
  store i8 1, ptr %4, align 4, !tbaa !5
  %.06 = load i32, ptr %3, align 16, !tbaa !13
  %.not7 = icmp eq i32 %.06, 0
  br i1 %.not7, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.08 = phi i32 [ %.0, %.lr.ph ], [ %.06, %7 ]
  %10 = sext i32 %.08 to i64
  %11 = getelementptr inbounds [200010 x %struct.edge], ptr @E, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !14
  tail call void @_Z7connecti(i32 noundef %13)
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  %.0 = load i32, ptr %14, align 4, !tbaa !13
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph, %7, %1
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !10, i64 12}
!6 = !{!"_ZTS6vertex", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !7, i64 4}
!15 = !{!"_ZTS4edge", !7, i64 0, !7, i64 4, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass