; LLVM IR from alexzheng42/sDMD :: analysis (Cluster)

; 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.AtomStr = type { ptr, ptr }
%struct.PropertyStr = type { [8 x i8], [2 x [16 x i8]], [8 x i8], i32, i32, i32, double, double, [3 x double], %struct.AtomSeqStr, ptr, ptr }
%struct.AtomSeqStr = type { i32, i32, i32 }

@atomnum = external global i32, align 4
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@atom = external global ptr, align 8

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local void @PrintInteraction(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %61, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = load i32, ptr @atomnum, align 4, !tbaa !9
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %64

11:                                               ; preds = %6
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = load i32, ptr @atomnum, align 4, !tbaa !9
  %14 = sdiv i32 %13, 2
  %15 = icmp sle i32 %12, %14
  br i1 %15, label %16, label %60

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

17:                                               ; preds = %56, %16
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr @atomnum, align 4, !tbaa !9
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %59

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i64, ptr %27, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = icmp sgt i64 %31, 0
  br i1 %32, label %33, label %55

33:                                               ; preds = %22
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load ptr, ptr @atom, align 8, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.AtomStr, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct.AtomStr, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct.PropertyStr, ptr %41, i32 0, i32 9
  %43 = getelementptr inbounds %struct.AtomSeqStr, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = load ptr, ptr @atom, align 8, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.AtomStr, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.AtomStr, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = getelementptr inbounds %struct.PropertyStr, ptr %50, i32 0, i32 9
  %52 = getelementptr inbounds %struct.AtomSeqStr, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !15
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %34, i32 noundef %35, i32 noundef %44, i32 noundef %53)
  br label %55

55:                                               ; preds = %33, %22
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %5, align 4, !tbaa !9
  br label %17, !llvm.loop !19

59:                                               ; preds = %21
  br label %60

60:                                               ; preds = %59, %11
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %3, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !21

64:                                               ; preds = %10
  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 = { "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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"AtomStr", !6, i64 0, !6, i64 8}
!15 = !{!16, !10, i64 108}
!16 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !17, i64 64, !17, i64 72, !7, i64 80, !18, i64 104, !6, i64 120, !6, i64 128}
!17 = !{!"double", !7, i64 0}
!18 = !{!"AtomSeqStr", !10, i64 0, !10, i64 4, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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.AtomStr = type { ptr, ptr }

@atomnum = external local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@atom = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @PrintInteraction(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @atomnum, align 4
  %.not17 = icmp slt i32 %2, 1
  br i1 %.not17, label %._crit_edge, label %.lr.ph20

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void

.lr.ph20:                                         ; preds = %1, %.loopexit
  %3 = phi i32 [ %31, %.loopexit ], [ %2, %1 ]
  %indvars.iv22 = phi i64 [ %indvars.iv.next23, %.loopexit ], [ 1, %1 ]
  %4 = sdiv i32 %3, 2
  %5 = sext i32 %4 to i64
  %.not13 = icmp sgt i64 %indvars.iv22, %5
  %.not1415 = icmp slt i32 %3, 1
  %or.cond = or i1 %.not13, %.not1415
  br i1 %or.cond, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph20
  %6 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv22
  %7 = trunc nuw nsw i64 %indvars.iv22 to i32
  br label %8

8:                                                ; preds = %.lr.ph, %27
  %9 = phi i32 [ %3, %.lr.ph ], [ %28, %27 ]
  %10 = phi i32 [ %3, %.lr.ph ], [ %29, %27 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds i64, ptr %11, i64 %indvars.iv
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp sgt i64 %13, 0
  br i1 %14, label %15, label %27

15:                                               ; preds = %8
  %16 = load ptr, ptr @atom, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.AtomStr, ptr %16, i64 %indvars.iv22
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %18, i64 108
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = getelementptr inbounds %struct.AtomStr, ptr %16, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %22, i64 108
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %7, i32 noundef %25, i32 noundef %20, i32 noundef %24)
  %.pre = load i32, ptr @atomnum, align 4
  br label %27

27:                                               ; preds = %8, %15
  %28 = phi i32 [ %9, %8 ], [ %.pre, %15 ]
  %29 = phi i32 [ %10, %8 ], [ %.pre, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = sext i32 %29 to i64
  %.not14.not = icmp slt i64 %indvars.iv, %30
  br i1 %.not14.not, label %8, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %27, %.lr.ph20
  %31 = phi i32 [ %3, %.lr.ph20 ], [ %28, %27 ]
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %32 = sext i32 %31 to i64
  %.not.not = icmp slt i64 %indvars.iv22, %32
  br i1 %.not.not, label %.lr.ph20, label %._crit_edge, !llvm.loop !20
}

attributes #0 = { nofree nounwind "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 = { nofree 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"AtomStr", !6, i64 0, !6, i64 8}
!13 = !{!14, !15, i64 108}
!14 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !15, i64 48, !15, i64 52, !15, i64 56, !16, i64 64, !16, i64 72, !7, i64 80, !17, i64 104, !6, i64 120, !6, i64 128}
!15 = !{!"int", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!"AtomSeqStr", !15, i64 0, !15, i64 4, !15, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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