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

; 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_graph = type { ptr, ptr, i32, i32 }
%struct.su2_graph_edge = type { [2 x i32] }
%struct.su2_graph_node = type { i32, [2 x i32], i32 }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@__PRETTY_FUNCTION__.su2_graph_yoga_to_simple_subtree = external hidden unnamed_addr constant [69 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @su2_graph_is_yoga_edge(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @su2_graph_yoga_to_simple_subtree(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = call zeroext i1 @su2_graph_is_yoga_edge(ptr noundef %10, i32 noundef %11)
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %15

14:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 397, ptr noundef @__PRETTY_FUNCTION__.su2_graph_yoga_to_simple_subtree) #3
  unreachable

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.su2_graph, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.su2_graph_edge, ptr %18, i64 %20
  store ptr %21, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.su2_graph, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.su2_graph_edge, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds [2 x i32], ptr %26, i64 0, i64 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.su2_graph_node, ptr %24, i64 %29
  store ptr %30, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.su2_graph, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.su2_graph_edge, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [2 x i32], ptr %35, i64 0, i64 1
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.su2_graph_node, ptr %33, i64 %38
  store ptr %39, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.su2_graph_edge, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [2 x i32], ptr %41, i64 0, i64 1
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.su2_graph, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.su2_graph_node, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !14
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.su2_graph_edge, ptr %46, i64 %50
  %52 = getelementptr inbounds %struct.su2_graph_edge, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [2 x i32], ptr %52, i64 0, i64 1
  store i32 %43, ptr %53, align 4, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.su2_graph_edge, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds [2 x i32], ptr %55, i64 0, i64 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.su2_graph, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.su2_graph_node, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !14
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.su2_graph_edge, ptr %60, i64 %64
  %66 = getelementptr inbounds %struct.su2_graph_edge, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds [2 x i32], ptr %66, i64 0, i64 0
  store i32 %57, ptr %67, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.su2_graph_node, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds [2 x i32], ptr %70, i64 0, i64 0
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = icmp eq i32 %68, %72
  %74 = zext i1 %73 to i64
  %75 = select i1 %73, i32 0, i32 1
  store i32 %75, ptr %8, align 4, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.su2_graph_node, ptr %76, i32 0, i32 0
  %78 = load i32, ptr %77, align 4, !tbaa !14
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.su2_graph_node, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [2 x i32], ptr %80, i64 0, i64 %82
  store i32 %78, ptr %83, align 4, !tbaa !9
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.su2_graph_node, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !14
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.su2_graph_node, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = sub nsw i32 1, %89
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [2 x i32], ptr %88, i64 0, i64 %91
  store i32 %86, ptr %92, align 4, !tbaa !9
  %93 = load i32, ptr %4, align 4, !tbaa !9
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.su2_graph_node, ptr %94, i32 0, i32 0
  store i32 %93, ptr %95, align 4, !tbaa !14
  %96 = load i32, ptr %4, align 4, !tbaa !9
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.su2_graph_node, ptr %97, i32 0, i32 0
  store i32 %96, ptr %98, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.su2_graph_edge, ptr %99, i32 0, i32 0
  %101 = getelementptr inbounds [2 x i32], ptr %100, i64 0, i64 0
  %102 = load i32, ptr %101, align 4, !tbaa !9
  store i32 %102, ptr %9, align 4, !tbaa !9
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.su2_graph_edge, ptr %103, i32 0, i32 0
  %105 = getelementptr inbounds [2 x i32], ptr %104, i64 0, i64 1
  %106 = load i32, ptr %105, align 4, !tbaa !9
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.su2_graph_edge, ptr %107, i32 0, i32 0
  %109 = getelementptr inbounds [2 x i32], ptr %108, i64 0, i64 0
  store i32 %106, ptr %109, align 4, !tbaa !9
  %110 = load i32, ptr %9, align 4, !tbaa !9
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.su2_graph_edge, ptr %111, i32 0, i32 0
  %113 = getelementptr inbounds [2 x i32], ptr %112, i64 0, i64 1
  store i32 %110, ptr %113, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { noreturn nounwind }
attributes #4 = { 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, !6, i64 8}
!12 = !{!"su2_graph", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"su2_graph_node", !10, i64 0, !7, i64 4, !10, i64 12}


; 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_graph_edge = type { [2 x i32] }
%struct.su2_graph_node = type { i32, [2 x i32], i32 }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@__PRETTY_FUNCTION__.su2_graph_yoga_to_simple_subtree = external hidden unnamed_addr constant [69 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @su2_graph_yoga_to_simple_subtree(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i1 @su2_graph_is_yoga_edge(ptr noundef %0, i32 noundef %1)
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 397, ptr noundef nonnull @__PRETTY_FUNCTION__.su2_graph_yoga_to_simple_subtree) #2
  unreachable

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds %struct.su2_graph_edge, ptr %7, i64 %8
  %10 = load ptr, ptr %0, align 8, !tbaa !11
  %11 = load i32, ptr %9, align 4, !tbaa !12
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds %struct.su2_graph_node, ptr %10, i64 %12
  %14 = getelementptr inbounds i8, ptr %9, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct.su2_graph_node, ptr %10, i64 %16
  %18 = load i32, ptr %13, align 4, !tbaa !13
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds %struct.su2_graph_edge, ptr %7, i64 %19, i32 0, i64 1
  store i32 %15, ptr %20, align 4, !tbaa !12
  %21 = load i32, ptr %17, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.su2_graph_edge, ptr %7, i64 %22
  store i32 %11, ptr %23, align 4, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %13, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %26 = icmp ne i32 %25, %1
  %27 = load i32, ptr %17, align 4, !tbaa !13
  %28 = zext i1 %26 to i64
  %29 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 %28
  store i32 %27, ptr %29, align 4, !tbaa !12
  %30 = load i32, ptr %13, align 4, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %17, i64 4
  %not. = xor i1 %26, true
  %32 = zext i1 %not. to i64
  %33 = getelementptr inbounds [2 x i32], ptr %31, i64 0, i64 %32
  store i32 %30, ptr %33, align 4, !tbaa !12
  store i32 %1, ptr %13, align 4, !tbaa !13
  store i32 %1, ptr %17, align 4, !tbaa !13
  %34 = load <2 x i32>, ptr %9, align 4, !tbaa !12
  %35 = shufflevector <2 x i32> %34, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i32> %35, ptr %9, align 4, !tbaa !12
  ret void
}

attributes #0 = { 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 #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 = { 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, !7, i64 8}
!6 = !{!"su2_graph", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"su2_graph_node", !10, i64 0, !8, i64 4, !10, i64 12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass