; LLVM IR from FSmallenburg/EDMD :: Cell (mdCell)

; 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.sparticle = type { double, double, double, double, double, double, double, double, double, i8, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i8 }

@cx = external dso_local global i32, align 4
@cy = external dso_local global i32, align 4
@cz = external dso_local global i32, align 4
@cxsize = external dso_local global double, align 8
@cysize = external dso_local global double, align 8
@czsize = external dso_local global double, align 8
@celllist = external dso_local global [75 x [75 x [75 x ptr]]], align 16

; Function Attrs: nounwind uwtable
define dso_local void @addtocelllist(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.sparticle, ptr %3, i32 0, i32 0
  %5 = load double, ptr %4, align 8, !tbaa !9
  %6 = load double, ptr @cxsize, align 8, !tbaa !13
  %7 = fdiv double %5, %6
  %8 = fptosi double %7 to i32
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.sparticle, ptr %9, i32 0, i32 10
  store i32 %8, ptr %10, align 4, !tbaa !14
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.sparticle, ptr %11, i32 0, i32 1
  %13 = load double, ptr %12, align 8, !tbaa !15
  %14 = load double, ptr @cysize, align 8, !tbaa !13
  %15 = fdiv double %13, %14
  %16 = fptosi double %15 to i32
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sparticle, ptr %17, i32 0, i32 11
  store i32 %16, ptr %18, align 8, !tbaa !16
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sparticle, ptr %19, i32 0, i32 2
  %21 = load double, ptr %20, align 8, !tbaa !17
  %22 = load double, ptr @czsize, align 8, !tbaa !13
  %23 = fdiv double %21, %22
  %24 = fptosi double %23 to i32
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.sparticle, ptr %25, i32 0, i32 12
  store i32 %24, ptr %26, align 4, !tbaa !18
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sparticle, ptr %27, i32 0, i32 10
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [75 x [75 x [75 x ptr]]], ptr @celllist, i64 0, i64 %30
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.sparticle, ptr %32, i32 0, i32 11
  %34 = load i32, ptr %33, align 8, !tbaa !16
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [75 x [75 x ptr]], ptr %31, i64 0, i64 %35
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.sparticle, ptr %37, i32 0, i32 12
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [75 x ptr], ptr %36, i64 0, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.sparticle, ptr %43, i32 0, i32 18
  store ptr %42, ptr %44, align 8, !tbaa !19
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.sparticle, ptr %45, i32 0, i32 18
  %47 = load ptr, ptr %46, align 8, !tbaa !19
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %55

49:                                               ; preds = %1
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.sparticle, ptr %51, i32 0, i32 18
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  %54 = getelementptr inbounds %struct.sparticle, ptr %53, i32 0, i32 17
  store ptr %50, ptr %54, align 8, !tbaa !20
  br label %55

55:                                               ; preds = %49, %1
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.sparticle, ptr %57, i32 0, i32 10
  %59 = load i32, ptr %58, align 4, !tbaa !14
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [75 x [75 x [75 x ptr]]], ptr @celllist, i64 0, i64 %60
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sparticle, ptr %62, i32 0, i32 11
  %64 = load i32, ptr %63, align 8, !tbaa !16
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [75 x [75 x ptr]], ptr %61, i64 0, i64 %65
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.sparticle, ptr %67, i32 0, i32 12
  %69 = load i32, ptr %68, align 4, !tbaa !18
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [75 x ptr], ptr %66, i64 0, i64 %70
  store ptr %56, ptr %71, align 8, !tbaa !5
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.sparticle, ptr %72, i32 0, i32 17
  store ptr null, ptr %73, align 8, !tbaa !20
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.sparticle, ptr %74, i32 0, i32 10
  %76 = load i32, ptr %75, align 4, !tbaa !14
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %109, label %78

78:                                               ; preds = %55
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.sparticle, ptr %79, i32 0, i32 11
  %81 = load i32, ptr %80, align 8, !tbaa !16
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %109, label %83

83:                                               ; preds = %78
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.sparticle, ptr %84, i32 0, i32 12
  %86 = load i32, ptr %85, align 4, !tbaa !18
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %109, label %88

88:                                               ; preds = %83
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.sparticle, ptr %89, i32 0, i32 10
  %91 = load i32, ptr %90, align 4, !tbaa !14
  %92 = load i32, ptr @cx, align 4, !tbaa !21
  %93 = sub nsw i32 %92, 1
  %94 = icmp eq i32 %91, %93
  br i1 %94, label %109, label %95

95:                                               ; preds = %88
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.sparticle, ptr %96, i32 0, i32 11
  %98 = load i32, ptr %97, align 8, !tbaa !16
  %99 = load i32, ptr @cy, align 4, !tbaa !21
  %100 = sub nsw i32 %99, 1
  %101 = icmp eq i32 %98, %100
  br i1 %101, label %109, label %102

102:                                              ; preds = %95
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.sparticle, ptr %103, i32 0, i32 12
  %105 = load i32, ptr %104, align 4, !tbaa !18
  %106 = load i32, ptr @cz, align 4, !tbaa !21
  %107 = sub nsw i32 %106, 1
  %108 = icmp eq i32 %105, %107
  br label %109

109:                                              ; preds = %102, %95, %88, %83, %78, %55
  %110 = phi i1 [ true, %95 ], [ true, %88 ], [ true, %83 ], [ true, %78 ], [ true, %55 ], [ %108, %102 ]
  %111 = zext i1 %110 to i32
  %112 = trunc i32 %111 to i8
  %113 = load ptr, ptr %2, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.sparticle, ptr %113, i32 0, i32 9
  store i8 %112, ptr %114, align 8, !tbaa !22
  ret void
}

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, !11, i64 0}
!10 = !{!"sparticle", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !7, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !12, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !7, i64 128}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !12, i64 76}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !12, i64 80}
!17 = !{!10, !11, i64 16}
!18 = !{!10, !12, i64 84}
!19 = !{!10, !6, i64 120}
!20 = !{!10, !6, i64 112}
!21 = !{!12, !12, i64 0}
!22 = !{!10, !7, i64 72}


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

@cx = external dso_local local_unnamed_addr global i32, align 4
@cy = external dso_local local_unnamed_addr global i32, align 4
@cz = external dso_local local_unnamed_addr global i32, align 4
@cxsize = external dso_local local_unnamed_addr global double, align 8
@cysize = external dso_local local_unnamed_addr global double, align 8
@czsize = external dso_local local_unnamed_addr global double, align 8
@celllist = external dso_local local_unnamed_addr global [75 x [75 x [75 x ptr]]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @addtocelllist(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load double, ptr @cxsize, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  %4 = load double, ptr @cysize, align 8, !tbaa !5
  %5 = load <2 x double>, ptr %0, align 8, !tbaa !5
  %6 = insertelement <2 x double> poison, double %2, i64 0
  %7 = insertelement <2 x double> %6, double %4, i64 1
  %8 = fdiv <2 x double> %5, %7
  %9 = fptosi <2 x double> %8 to <2 x i32>
  store <2 x i32> %9, ptr %3, align 4, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = load double, ptr @czsize, align 8, !tbaa !5
  %13 = fdiv double %11, %12
  %14 = fptosi double %13 to i32
  %15 = getelementptr inbounds i8, ptr %0, i64 84
  store i32 %14, ptr %15, align 4, !tbaa !14
  %16 = extractelement <2 x i32> %9, i64 0
  %17 = sext i32 %16 to i64
  %18 = extractelement <2 x i32> %9, i64 1
  %19 = sext i32 %18 to i64
  %20 = sext i32 %14 to i64
  %21 = getelementptr inbounds [75 x [75 x [75 x ptr]]], ptr @celllist, i64 0, i64 %17, i64 %19, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %0, i64 120
  store ptr %22, ptr %23, align 8, !tbaa !16
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %26, label %24

24:                                               ; preds = %1
  %25 = getelementptr inbounds i8, ptr %22, i64 112
  store ptr %0, ptr %25, align 8, !tbaa !17
  br label %26

26:                                               ; preds = %24, %1
  store ptr %0, ptr %21, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %0, i64 112
  store ptr null, ptr %27, align 8, !tbaa !17
  %28 = icmp eq <2 x i32> %9, zeroinitializer
  %shift = shufflevector <2 x i1> %28, <2 x i1> poison, <2 x i32> <i32 1, i32 poison>
  %29 = or <2 x i1> %28, %shift
  %or.cond = extractelement <2 x i1> %29, i64 0
  %30 = icmp eq i32 %14, 0
  %or.cond28 = or i1 %or.cond, %30
  br i1 %or.cond28, label %44, label %31

31:                                               ; preds = %26
  %32 = load i32, ptr @cx, align 4, !tbaa !9
  %33 = add nsw i32 %32, -1
  %34 = icmp eq i32 %33, %16
  br i1 %34, label %44, label %35

35:                                               ; preds = %31
  %36 = load i32, ptr @cy, align 4, !tbaa !9
  %37 = add nsw i32 %36, -1
  %38 = icmp eq i32 %37, %18
  br i1 %38, label %44, label %39

39:                                               ; preds = %35
  %40 = load i32, ptr @cz, align 4, !tbaa !9
  %41 = add nsw i32 %40, -1
  %42 = icmp eq i32 %41, %14
  %43 = zext i1 %42 to i8
  br label %44

44:                                               ; preds = %39, %35, %31, %26
  %45 = phi i8 [ 1, %35 ], [ 1, %31 ], [ 1, %26 ], [ %43, %39 ]
  %46 = getelementptr inbounds i8, ptr %0, i64 72
  store i8 %45, ptr %46, align 8, !tbaa !18
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !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 16}
!12 = !{!"sparticle", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !7, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !7, i64 128}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !10, i64 84}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 120}
!17 = !{!12, !13, i64 112}
!18 = !{!12, !7, i64 72}


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