; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/hardware (quantum_geometric_gpu)

; 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.GPUContext = type { i32, ptr, %struct.GPUDeviceInfo, [256 x i8], %struct.GPUPerformanceMetrics }
%struct.GPUDeviceInfo = type { [256 x i8], i64, i64, i32, i32, i8, i8, i8 }
%struct.GPUPerformanceMetrics = type { double, double, i64, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @gpu_quantum_attention(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) #0 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !5
  store ptr %3, ptr %14, align 8, !tbaa !5
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i32 %5, ptr %16, align 4, !tbaa !9
  store i32 %6, ptr %17, align 4, !tbaa !9
  store i32 %7, ptr %18, align 4, !tbaa !9
  store i32 %8, ptr %19, align 4, !tbaa !9
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %9
  store i32 -4, ptr %10, align 4
  br label %54

23:                                               ; preds = %9
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %35

26:                                               ; preds = %23
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %32, %29, %26, %23
  store i32 -1, ptr %10, align 4
  br label %54

36:                                               ; preds = %32
  %37 = load i32, ptr %16, align 4, !tbaa !9
  %38 = icmp sle i32 %37, 0
  br i1 %38, label %48, label %39

39:                                               ; preds = %36
  %40 = load i32, ptr %17, align 4, !tbaa !9
  %41 = icmp sle i32 %40, 0
  br i1 %41, label %48, label %42

42:                                               ; preds = %39
  %43 = load i32, ptr %18, align 4, !tbaa !9
  %44 = icmp sle i32 %43, 0
  br i1 %44, label %48, label %45

45:                                               ; preds = %42
  %46 = load i32, ptr %19, align 4, !tbaa !9
  %47 = icmp sle i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45, %42, %39, %36
  store i32 -1, ptr %10, align 4
  br label %54

49:                                               ; preds = %45
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.GPUContext, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !11
  switch i32 %52, label %53 [
  ]

53:                                               ; preds = %49
  store i32 -6, ptr %10, align 4
  br label %54

54:                                               ; preds = %53, %48, %35, %22
  %55 = load i32, ptr %10, align 4
  ret i32 %55
}

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

!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, !10, i64 0}
!12 = !{!"GPUContext", !10, i64 0, !6, i64 8, !13, i64 16, !7, i64 304, !16, i64 560}
!13 = !{!"GPUDeviceInfo", !7, i64 0, !14, i64 256, !14, i64 264, !10, i64 272, !10, i64 276, !15, i64 280, !15, i64 281, !15, i64 282}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"GPUPerformanceMetrics", !17, i64 0, !17, i64 8, !14, i64 16, !10, i64 24}
!17 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local range(i32 -6, 0) i32 @gpu_quantum_attention(ptr noundef readnone %0, ptr noundef readnone %1, ptr noundef readnone %2, ptr noundef readnone %3, ptr noundef readnone %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %23, label %10

10:                                               ; preds = %9
  %11 = insertelement <4 x ptr> poison, ptr %1, i64 0
  %12 = insertelement <4 x ptr> %11, ptr %2, i64 1
  %13 = insertelement <4 x ptr> %12, ptr %3, i64 2
  %14 = insertelement <4 x ptr> %13, ptr %4, i64 3
  %15 = icmp eq <4 x ptr> %14, zeroinitializer
  %16 = bitcast <4 x i1> %15 to i4
  %17 = icmp eq i4 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %10
  %19 = icmp slt i32 %5, 1
  %20 = icmp slt i32 %6, 1
  %or.cond7 = or i1 %19, %20
  %21 = icmp slt i32 %7, 1
  %or.cond9 = or i1 %or.cond7, %21
  %22 = icmp slt i32 %8, 1
  %or.cond11 = or i1 %or.cond9, %22
  %. = select i1 %or.cond11, i32 -1, i32 -6
  br label %23

23:                                               ; preds = %18, %10, %9
  %.0 = phi i32 [ -4, %9 ], [ -1, %10 ], [ %., %18 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


; Effective O3 passes: GlobalDCEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass