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

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

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.clebsch_gordan = external hidden unnamed_addr constant [100 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@cg_table = external hidden global <{ <{ <{ ptr, [10 x ptr] }>, <{ ptr, ptr, [9 x ptr] }>, <{ ptr, ptr, ptr, [8 x ptr] }>, [11 x ptr], [11 x ptr], [11 x ptr] }>, <{ <{ ptr, ptr, [9 x ptr] }>, <{ ptr, ptr, ptr, [8 x ptr] }>, [11 x ptr], [11 x ptr], [11 x ptr], [11 x ptr] }>, <{ <{ ptr, ptr, ptr, [8 x ptr] }>, [11 x ptr], [11 x ptr], [11 x ptr], [11 x ptr], [11 x ptr] }>, [6 x [11 x ptr]], [6 x [11 x ptr]], [6 x [11 x ptr]] }>, align 16

; Function Attrs: nounwind uwtable
define dso_local double @clebsch_gordan(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %11, align 4, !tbaa !5
  %15 = icmp sle i32 0, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %6
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  br label %23

22:                                               ; preds = %16, %6
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 113, ptr noundef @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

23:                                               ; preds = %21
  %24 = load i32, ptr %12, align 4, !tbaa !5
  %25 = icmp sle i32 0, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %23
  %27 = load i32, ptr %12, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  br label %33

32:                                               ; preds = %26, %23
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 114, ptr noundef @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

33:                                               ; preds = %31
  %34 = load i32, ptr %13, align 4, !tbaa !5
  %35 = icmp sle i32 0, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  %37 = load i32, ptr %13, align 4, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  br label %43

42:                                               ; preds = %36, %33
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 115, ptr noundef @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

43:                                               ; preds = %41
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = sub nsw i32 %45, %46
  %48 = call i32 @llvm.abs.i32(i32 %47, i1 true)
  %49 = icmp slt i32 %44, %48
  br i1 %49, label %56, label %50

50:                                               ; preds = %43
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = add nsw i32 %52, %53
  %55 = icmp sgt i32 %51, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %50, %43
  store double 0.000000e+00, ptr %7, align 8
  br label %106

57:                                               ; preds = %50
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = add nsw i32 %58, %59
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  %63 = srem i32 %62, 2
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %57
  store double 0.000000e+00, ptr %7, align 8
  br label %106

66:                                               ; preds = %57
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = icmp sle i32 %67, 5
  br i1 %68, label %69, label %70

69:                                               ; preds = %66
  br label %71

70:                                               ; preds = %66
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 125, ptr noundef @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

71:                                               ; preds = %69
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = icmp sle i32 %72, 5
  br i1 %73, label %74, label %75

74:                                               ; preds = %71
  br label %76

75:                                               ; preds = %71
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 126, ptr noundef @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

76:                                               ; preds = %74
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = icmp sle i32 %77, 10
  br i1 %78, label %79, label %80

79:                                               ; preds = %76
  br label %81

80:                                               ; preds = %76
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 127, ptr noundef @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

81:                                               ; preds = %79
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [6 x [6 x [11 x ptr]]], ptr @cg_table, i64 0, i64 %83
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [6 x [11 x ptr]], ptr %84, i64 0, i64 %86
  %88 = load i32, ptr %10, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [11 x ptr], ptr %87, i64 0, i64 %89
  %91 = load ptr, ptr %90, align 8, !tbaa !9
  %92 = load i32, ptr %11, align 4, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  %95 = mul nsw i32 %92, %94
  %96 = load i32, ptr %12, align 4, !tbaa !5
  %97 = add nsw i32 %95, %96
  %98 = load i32, ptr %10, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  %100 = mul nsw i32 %97, %99
  %101 = load i32, ptr %13, align 4, !tbaa !5
  %102 = add nsw i32 %100, %101
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds double, ptr %91, i64 %103
  %105 = load double, ptr %104, align 8, !tbaa !11
  store double %105, ptr %7, align 8
  br label %106

106:                                              ; preds = %81, %65, %56
  %107 = load double, ptr %7, align 8
  ret double %107
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

attributes #0 = { 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 = { noreturn 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, 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"

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.clebsch_gordan = external hidden unnamed_addr constant [100 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@cg_table = external hidden local_unnamed_addr global <{ <{ <{ ptr, [10 x ptr] }>, <{ ptr, ptr, [9 x ptr] }>, <{ ptr, ptr, ptr, [8 x ptr] }>, [11 x ptr], [11 x ptr], [11 x ptr] }>, <{ <{ ptr, ptr, [9 x ptr] }>, <{ ptr, ptr, ptr, [8 x ptr] }>, [11 x ptr], [11 x ptr], [11 x ptr], [11 x ptr] }>, <{ <{ ptr, ptr, ptr, [8 x ptr] }>, [11 x ptr], [11 x ptr], [11 x ptr], [11 x ptr], [11 x ptr] }>, [6 x [11 x ptr]], [6 x [11 x ptr]], [6 x [11 x ptr]] }>, align 16

; Function Attrs: nounwind uwtable
define dso_local double @clebsch_gordan(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = icmp slt i32 %3, 0
  %.not = icmp slt i32 %0, %3
  %or.cond = or i1 %7, %.not
  br i1 %or.cond, label %8, label %9

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 113, ptr noundef nonnull @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

9:                                                ; preds = %6
  %10 = icmp sgt i32 %4, -1
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = add nsw i32 %1, 1
  %.not38 = icmp slt i32 %1, %4
  br i1 %.not38, label %13, label %14

13:                                               ; preds = %11, %9
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 114, ptr noundef nonnull @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

14:                                               ; preds = %11
  %15 = icmp sgt i32 %5, -1
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = add nsw i32 %2, 1
  %.not39 = icmp slt i32 %2, %5
  br i1 %.not39, label %18, label %19

18:                                               ; preds = %16, %14
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 115, ptr noundef nonnull @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

19:                                               ; preds = %16
  %20 = sub nsw i32 %0, %1
  %21 = tail call i32 @llvm.abs.i32(i32 %20, i1 true)
  %22 = icmp ugt i32 %21, %2
  br i1 %22, label %48, label %23

23:                                               ; preds = %19
  %24 = add nsw i32 %1, %0
  %25 = icmp slt i32 %24, %2
  br i1 %25, label %48, label %26

26:                                               ; preds = %23
  %27 = add nuw nsw i32 %24, %2
  %28 = and i32 %27, 1
  %.not40 = icmp eq i32 %28, 0
  br i1 %.not40, label %29, label %48

29:                                               ; preds = %26
  %30 = icmp slt i32 %0, 6
  br i1 %30, label %32, label %31

31:                                               ; preds = %29
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 125, ptr noundef nonnull @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

32:                                               ; preds = %29
  %33 = icmp ult i32 %1, 6
  br i1 %33, label %35, label %34

34:                                               ; preds = %32
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 126, ptr noundef nonnull @__PRETTY_FUNCTION__.clebsch_gordan) #3
  unreachable

35:                                               ; preds = %32
  %36 = sext i32 %0 to i64
  %37 = zext nneg i32 %1 to i64
  %38 = zext nneg i32 %2 to i64
  %39 = getelementptr inbounds [6 x [6 x [11 x ptr]]], ptr @cg_table, i64 0, i64 %36, i64 %37, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = mul nuw nsw i32 %12, %3
  %42 = add nuw nsw i32 %41, %4
  %43 = mul nuw nsw i32 %42, %17
  %44 = add nuw nsw i32 %43, %5
  %45 = zext nneg i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %40, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %26, %19, %23, %35
  %.0 = phi double [ %47, %35 ], [ 0.000000e+00, %23 ], [ 0.000000e+00, %19 ], [ 0.000000e+00, %26 ]
  ret double %.0
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

attributes #0 = { 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 = { noreturn 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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 = !{!"double", !7, i64 0}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass