; LLVM IR from ippeb/ACM-ICPC :: graph_theory/hierholzer/hierholzer.ll (Z11findcircuiti)

; 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"

@n = external dso_local global i32, align 4
@cp = external dso_local global i32, align 4
@C = external dso_local global [10000 x i32], align 16
@G = external dso_local global [100 x [100 x i8]], align 16
@Gdeg = external dso_local global [100 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7deledgeii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11findcircuiti(i32 noundef %0) #1 {
  %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 [100 x i32], ptr @Gdeg, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %15, label %9

9:                                                ; preds = %1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @cp, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @cp, align 4, !tbaa !5
  %13 = sext i32 %11 to i64
  %14 = getelementptr inbounds [10000 x i32], ptr @C, i64 0, i64 %13
  store i32 %10, ptr %14, align 4, !tbaa !5
  br label %52

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %43, %15
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %20, label %26

20:                                               ; preds = %16
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i32], ptr @Gdeg, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 0
  br label %26

26:                                               ; preds = %20, %16
  %27 = phi i1 [ false, %16 ], [ %25, %20 ]
  br i1 %27, label %29, label %28

28:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %46

29:                                               ; preds = %26
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100 x [100 x i8]], ptr @G, i64 0, i64 %31
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100 x i8], ptr %32, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %29
  br label %43

39:                                               ; preds = %29
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z7deledgeii(i32 noundef %40, i32 noundef %41)
  %42 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z11findcircuiti(i32 noundef %42)
  br label %43

43:                                               ; preds = %39, %38
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !10

46:                                               ; preds = %28
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr @cp, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @cp, align 4, !tbaa !5
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds [10000 x i32], ptr @C, i64 0, i64 %50
  store i32 %47, ptr %51, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %46, %9
  ret void
}

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

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

attributes #0 = { mustprogress nounwind 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@cp = external dso_local local_unnamed_addr global i32, align 4
@C = external dso_local local_unnamed_addr global [10000 x i32], align 16
@G = external dso_local local_unnamed_addr global [100 x [100 x i8]], align 16
@Gdeg = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7deledgeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11findcircuiti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100 x i32], ptr @Gdeg, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  %5 = load i32, ptr @n, align 4
  %.not1113 = icmp slt i32 %5, 1
  %or.cond = select i1 %.not, i1 true, i1 %.not1113
  br i1 %or.cond, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %14
  %6 = phi i32 [ %15, %14 ], [ %5, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %14 ], [ 1, %1 ]
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds [100 x [100 x i8]], ptr @G, i64 0, i64 %2, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %.not12 = icmp eq i8 %11, 0
  br i1 %.not12, label %14, label %12

12:                                               ; preds = %9
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z7deledgeii(i32 noundef %0, i32 noundef %13)
  tail call void @_Z11findcircuiti(i32 noundef %13)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %9, %12
  %15 = phi i32 [ %6, %9 ], [ %.pre, %12 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = sext i32 %15 to i64
  %.not11.not = icmp slt i64 %indvars.iv, %16
  br i1 %.not11.not, label %.lr.ph, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %14, %.lr.ph, %1
  %17 = load i32, ptr @cp, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @cp, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [10000 x i32], ptr @C, i64 0, i64 %19
  store i32 %0, ptr %20, align 4, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nounwind 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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