; LLVM IR from qc-tum/chemtensor :: src/tensor (su2_irrep_lists)

; 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.su2_irreducible_list = type { ptr, i32 }
%struct.charge_sectors = type { ptr, i64, i32 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @compare_su2_irreducible_lists(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @charge_sector_index(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.su2_irreducible_list, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca %struct.su2_irreducible_list, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #2
  %13 = getelementptr inbounds %struct.su2_irreducible_list, ptr %6, i32 0, i32 0
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.su2_irreducible_list, ptr %6, i32 0, i32 1
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.charge_sectors, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !12
  store i32 %18, ptr %15, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.charge_sectors, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !17
  store i64 %21, ptr %8, align 8, !tbaa !16
  br label %22

22:                                               ; preds = %65, %2
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %7, align 8, !tbaa !16
  %25 = load i64, ptr %8, align 8, !tbaa !16
  %26 = icmp sge i64 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %66

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %29 = load i64, ptr %7, align 8, !tbaa !16
  %30 = load i64, ptr %8, align 8, !tbaa !16
  %31 = add nsw i64 %29, %30
  %32 = sdiv i64 %31, 2
  store i64 %32, ptr %10, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #2
  %33 = getelementptr inbounds %struct.su2_irreducible_list, ptr %11, i32 0, i32 0
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.charge_sectors, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = load i64, ptr %10, align 8, !tbaa !16
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.charge_sectors, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %37, %41
  %43 = getelementptr inbounds i32, ptr %36, i64 %42
  store ptr %43, ptr %33, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.su2_irreducible_list, ptr %11, i32 0, i32 1
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.charge_sectors, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !12
  store i32 %47, ptr %44, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %48 = call i32 @compare_su2_irreducible_lists(ptr noundef %6, ptr noundef %11)
  store i32 %48, ptr %12, align 4, !tbaa !19
  %49 = load i32, ptr %12, align 4, !tbaa !19
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %28
  %52 = load i64, ptr %10, align 8, !tbaa !16
  store i64 %52, ptr %8, align 8, !tbaa !16
  br label %62

53:                                               ; preds = %28
  %54 = load i32, ptr %12, align 4, !tbaa !19
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = load i64, ptr %10, align 8, !tbaa !16
  store i64 %57, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

58:                                               ; preds = %53
  %59 = load i64, ptr %10, align 8, !tbaa !16
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %7, align 8, !tbaa !16
  br label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61, %51
  store i32 0, ptr %9, align 4
  br label %63

63:                                               ; preds = %62, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %64 = load i32, ptr %9, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %22

66:                                               ; preds = %63, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  %67 = load i64, ptr %3, align 8
  ret i64 %67
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!10 = !{!"su2_irreducible_list", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 16}
!13 = !{!"charge_sectors", !6, i64 0, !14, i64 8, !11, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!14, !14, i64 0}
!17 = !{!13, !14, i64 8}
!18 = !{!13, !6, i64 0}
!19 = !{!11, !11, i64 0}


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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @compare_su2_irreducible_lists(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @charge_sector_index(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.su2_irreducible_list, align 8
  %4 = alloca %struct.su2_irreducible_list, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  store ptr %1, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !11
  store i32 %7, ptr %5, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !15
  %.not29 = icmp sgt i64 %9, 0
  br i1 %.not29, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  br label %11

11:                                               ; preds = %.lr.ph, %25
  %.01731 = phi i64 [ 0, %.lr.ph ], [ %.219, %25 ]
  %.02130 = phi i64 [ %9, %.lr.ph ], [ %.223, %25 ]
  %12 = add nuw nsw i64 %.01731, %.02130
  %13 = lshr i64 %12, 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  %14 = load ptr, ptr %0, align 8, !tbaa !16
  %15 = load i32, ptr %6, align 8, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = mul nsw i64 %13, %16
  %18 = getelementptr inbounds i32, ptr %14, i64 %17
  store ptr %18, ptr %4, align 8, !tbaa !5
  store i32 %15, ptr %10, align 8, !tbaa !14
  %19 = call i32 @compare_su2_irreducible_lists(ptr noundef nonnull %3, ptr noundef nonnull %4)
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %25, label %21

21:                                               ; preds = %11
  %22 = icmp eq i32 %19, 0
  br i1 %22, label %.thread, label %23

.thread:                                          ; preds = %21
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  br label %.loopexit

23:                                               ; preds = %21
  %24 = add nuw nsw i64 %13, 1
  br label %25

25:                                               ; preds = %23, %11
  %.223 = phi i64 [ %.02130, %23 ], [ %13, %11 ]
  %.219 = phi i64 [ %24, %23 ], [ %.01731, %11 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  %.not = icmp slt i64 %.219, %.223
  br i1 %.not, label %11, label %.loopexit

.loopexit:                                        ; preds = %25, %2, %.thread
  %.2 = phi i64 [ %13, %.thread ], [ -1, %2 ], [ -1, %25 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  ret i64 %.2
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 0}
!6 = !{!"su2_irreducible_list", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"charge_sectors", !7, i64 0, !13, i64 8, !10, i64 16}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !7, i64 0}


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