; LLVM IR from mfem/mfem :: general/gecko.ll (ZN5Gecko8Subgraph4swapEj)

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

%"class.Gecko::Subgraph" = type { ptr, i32, ptr, %"class.Gecko::WeightedSum", [16 x i8], [16 x i8], [16 x ptr], ptr, [16 x i32], [16 x [16 x float]] }
%"class.Gecko::WeightedSum" = type { %"class.Gecko::WeightedValue" }
%"class.Gecko::WeightedValue" = type { float, float }
%"class.Gecko::Subnode" = type { float, %"class.Gecko::WeightedSum" }

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN5Gecko8Subgraph4swapEj(ptr noundef nonnull align 8 dereferenceable(1288) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = add i32 %9, 1
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %11 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %8, i32 0, i32 5
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !11
  store i8 %15, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %16 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %8, i32 0, i32 5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [16 x i8], ptr %16, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  store i8 %20, ptr %7, align 1, !tbaa !11
  %21 = load i8, ptr %7, align 1, !tbaa !11
  %22 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %8, i32 0, i32 5
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [16 x i8], ptr %22, i64 0, i64 %24
  store i8 %21, ptr %25, align 1, !tbaa !11
  %26 = load i8, ptr %6, align 1, !tbaa !11
  %27 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %8, i32 0, i32 5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 %29
  store i8 %26, ptr %30, align 1, !tbaa !11
  %31 = load i8, ptr %7, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = zext i32 %32 to i64
  %34 = shl i64 1, %33
  %35 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %8, i32 0, i32 6
  %36 = load i8, ptr %6, align 1, !tbaa !11
  %37 = zext i8 %36 to i64
  %38 = getelementptr inbounds [16 x ptr], ptr %35, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = sub i64 0, %34
  %41 = getelementptr inbounds %"class.Gecko::Subnode", ptr %39, i64 %40
  store ptr %41, ptr %38, align 8, !tbaa !5
  %42 = load i8, ptr %6, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = zext i32 %43 to i64
  %45 = shl i64 1, %44
  %46 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %8, i32 0, i32 6
  %47 = load i8, ptr %7, align 1, !tbaa !11
  %48 = zext i8 %47 to i64
  %49 = getelementptr inbounds [16 x ptr], ptr %46, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds %"class.Gecko::Subnode", ptr %50, i64 %45
  store ptr %51, ptr %49, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !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"

%"class.Gecko::Subnode" = type { float, %"class.Gecko::WeightedSum" }
%"class.Gecko::WeightedSum" = type { %"class.Gecko::WeightedValue" }
%"class.Gecko::WeightedValue" = type { float, float }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN5Gecko8Subgraph4swapEj(ptr nocapture noundef nonnull align 8 dereferenceable(1288) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = add i32 %1, 1
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = zext i32 %1 to i64
  %6 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = zext i32 %3 to i64
  %9 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  store i8 %10, ptr %6, align 1, !tbaa !5
  store i8 %7, ptr %9, align 1, !tbaa !5
  %11 = zext i8 %10 to i64
  %.neg = shl nsw i64 -1, %11
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = zext i8 %7 to i64
  %14 = getelementptr inbounds [16 x ptr], ptr %12, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !8
  %16 = getelementptr inbounds %"class.Gecko::Subnode", ptr %15, i64 %.neg
  store ptr %16, ptr %14, align 8, !tbaa !8
  %17 = shl nuw i64 1, %13
  %18 = getelementptr inbounds [16 x ptr], ptr %12, i64 0, i64 %11
  %19 = load ptr, ptr %18, align 8, !tbaa !8
  %20 = getelementptr inbounds %"class.Gecko::Subnode", ptr %19, i64 %17
  store ptr %20, ptr %18, align 8, !tbaa !8
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


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