; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (quantum_gate_operations)

; 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.ComplexFloat = type { float, float }
%struct.quantum_gate_t = type { i64, ptr, ptr, ptr, i64, i8, i32, ptr, i64, i8 }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 hidden void @compute_rotation_matrix(double noundef, i8 noundef signext, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @compute_controlled_matrix(ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @update_gate_parameters(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca [4 x %struct.ComplexFloat], align 16
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %41

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.quantum_gate_t, ptr %13, i32 0, i32 9
  %15 = load i8, ptr %14, align 8, !tbaa !11, !range !15, !noundef !16
  %16 = trunc i8 %15 to i1
  br i1 %16, label %17, label %41

17:                                               ; preds = %12
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %41

20:                                               ; preds = %17
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.quantum_gate_t, ptr %22, i32 0, i32 8
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = icmp ne i64 %21, %24
  br i1 %25, label %41, label %26

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.quantum_gate_t, ptr %27, i32 0, i32 6
  %29 = load i32, ptr %28, align 4, !tbaa !18
  %30 = icmp ne i32 %29, 7
  br i1 %30, label %31, label %42

31:                                               ; preds = %26
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.quantum_gate_t, ptr %32, i32 0, i32 6
  %34 = load i32, ptr %33, align 4, !tbaa !18
  %35 = icmp ne i32 %34, 8
  br i1 %35, label %36, label %42

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.quantum_gate_t, ptr %37, i32 0, i32 6
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = icmp ne i32 %39, 9
  br i1 %40, label %41, label %42

41:                                               ; preds = %36, %20, %17, %12, %3
  store i1 false, ptr %4, align 1
  br label %88

42:                                               ; preds = %36, %31, %26
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #3
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.quantum_gate_t, ptr %43, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !19
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = mul i64 %47, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %45, ptr align 8 %46, i64 %48, i1 false)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.quantum_gate_t, ptr %49, i32 0, i32 6
  %51 = load i32, ptr %50, align 4, !tbaa !18
  switch i32 %51, label %67 [
    i32 7, label %52
    i32 8, label %57
    i32 9, label %62
  ]

52:                                               ; preds = %42
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %53, i64 0
  %55 = load double, ptr %54, align 8, !tbaa !20
  %56 = getelementptr inbounds [4 x %struct.ComplexFloat], ptr %8, i64 0, i64 0
  call void @compute_rotation_matrix(double noundef %55, i8 noundef signext 120, ptr noundef %56)
  br label %68

57:                                               ; preds = %42
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds double, ptr %58, i64 0
  %60 = load double, ptr %59, align 8, !tbaa !20
  %61 = getelementptr inbounds [4 x %struct.ComplexFloat], ptr %8, i64 0, i64 0
  call void @compute_rotation_matrix(double noundef %60, i8 noundef signext 121, ptr noundef %61)
  br label %68

62:                                               ; preds = %42
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds double, ptr %63, i64 0
  %65 = load double, ptr %64, align 8, !tbaa !20
  %66 = getelementptr inbounds [4 x %struct.ComplexFloat], ptr %8, i64 0, i64 0
  call void @compute_rotation_matrix(double noundef %65, i8 noundef signext 122, ptr noundef %66)
  br label %68

67:                                               ; preds = %42
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %87

68:                                               ; preds = %62, %57, %52
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.quantum_gate_t, ptr %69, i32 0, i32 5
  %71 = load i8, ptr %70, align 8, !tbaa !22, !range !15, !noundef !16
  %72 = trunc i8 %71 to i1
  br i1 %72, label %73, label %81

73:                                               ; preds = %68
  %74 = getelementptr inbounds [4 x %struct.ComplexFloat], ptr %8, i64 0, i64 0
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.quantum_gate_t, ptr %75, i32 0, i32 0
  %77 = load i64, ptr %76, align 8, !tbaa !23
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.quantum_gate_t, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !24
  call void @compute_controlled_matrix(ptr noundef %74, i64 noundef %77, ptr noundef %80)
  br label %86

81:                                               ; preds = %68
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.quantum_gate_t, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !24
  %85 = getelementptr inbounds [4 x %struct.ComplexFloat], ptr %8, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %84, ptr align 16 %85, i64 32, i1 false)
  br label %86

86:                                               ; preds = %81, %73
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %87

87:                                               ; preds = %86, %67
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #3
  br label %88

88:                                               ; preds = %87, %41
  %89 = load i1, ptr %4, align 1
  ret i1 %89
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 64}
!12 = !{!"quantum_gate_t", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !14, i64 44, !6, i64 48, !10, i64 56, !13, i64 64}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!12, !10, i64 56}
!18 = !{!12, !14, i64 44}
!19 = !{!12, !6, i64 48}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = !{!12, !13, i64 40}
!23 = !{!12, !10, i64 0}
!24 = !{!12, !6, i64 8}


; 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.ComplexFloat = type { float, float }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 hidden void @compute_rotation_matrix(double noundef, i8 noundef signext, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @compute_controlled_matrix(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @update_gate_parameters(ptr noundef readonly %0, ptr noundef readonly %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca [4 x %struct.ComplexFloat], align 16
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %34, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load i8, ptr %6, align 8, !tbaa !5, !range !13, !noundef !14
  %8 = trunc nuw i8 %7 to i1
  %9 = icmp ne ptr %1, null
  %or.cond = and i1 %9, %8
  br i1 %or.cond, label %10, label %34

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %.not24 = icmp eq i64 %12, %2
  br i1 %.not24, label %13, label %34

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 44
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %.off = add i32 %15, -7
  %switch = icmp ult i32 %.off, 3
  br i1 %switch, label %16, label %34

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = shl i64 %2, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %18, ptr nonnull align 8 %1, i64 %19, i1 false)
  %20 = load i32, ptr %14, align 4, !tbaa !16
  %switch.tableidx = add i32 %20, -7
  %21 = icmp ult i32 %switch.tableidx, 3
  br i1 %21, label %switch.lookup, label %33

switch.lookup:                                    ; preds = %16
  %switch.idx.cast = trunc nuw i32 %switch.tableidx to i8
  %switch.offset = or disjoint i8 %switch.idx.cast, 120
  %22 = load double, ptr %1, align 8, !tbaa !18
  call void @compute_rotation_matrix(double noundef %22, i8 noundef signext %switch.offset, ptr noundef nonnull %4)
  %23 = getelementptr inbounds i8, ptr %0, i64 40
  %24 = load i8, ptr %23, align 8, !tbaa !20, !range !13, !noundef !14
  %25 = trunc nuw i8 %24 to i1
  br i1 %25, label %26, label %30

26:                                               ; preds = %switch.lookup
  %27 = load i64, ptr %0, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  call void @compute_controlled_matrix(ptr noundef nonnull %4, i64 noundef %27, ptr noundef %29)
  br label %33

30:                                               ; preds = %switch.lookup
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %32, ptr noundef nonnull align 16 dereferenceable(32) %4, i64 32, i1 false)
  br label %33

33:                                               ; preds = %16, %26, %30
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  br label %34

34:                                               ; preds = %13, %3, %5, %10, %33
  %.1 = phi i1 [ %21, %33 ], [ false, %13 ], [ false, %10 ], [ false, %5 ], [ false, %3 ]
  ret i1 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !11, i64 64}
!6 = !{!"quantum_gate_t", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !11, i64 40, !12, i64 44, !10, i64 48, !7, i64 56, !11, i64 64}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !7, i64 56}
!16 = !{!6, !12, i64 44}
!17 = !{!6, !10, i64 48}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !8, i64 0}
!20 = !{!6, !11, i64 40}
!21 = !{!6, !7, i64 0}
!22 = !{!6, !10, i64 8}


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