; LLVM IR from alexzheng42/sDMD :: src (Events)

; 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.HBPotentialStr = type { double, double, double, double, double, double }
%struct.AtomStr = type { ptr, ptr }
%struct.DynamicStr = type { [4 x i32], [4 x double], [4 x double], %struct.HBStr, %struct.HBNeighborStr, %struct.InteractionEventStr }
%struct.HBStr = type { i32, i32, i8, i32 }
%struct.HBNeighborStr = type { [5 x i32], i32, i32 }
%struct.InteractionEventStr = type { i32, i64, i64, double, double, i32, i32 }
%struct.PropertyStr = type { [8 x i8], [2 x [16 x i8]], [8 x i8], i32, i32, i32, double, double, [3 x double], %struct.AtomSeqStr, ptr, ptr }
%struct.AtomSeqStr = type { i32, i32, i32 }

@HBPotential = external global %struct.HBPotentialStr, align 8

; 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

declare i32 @AtomTypeChange(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @HBBarrier(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.AtomStr, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.DynamicStr, ptr %12, i32 0, i32 3
  %14 = getelementptr inbounds %struct.HBStr, ptr %13, i32 0, i32 2
  %15 = load i8, ptr %14, align 8, !tbaa !11
  %16 = sext i8 %15 to i32
  %17 = icmp eq i32 %16, 65
  br i1 %17, label %27, label %18

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.AtomStr, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.DynamicStr, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds %struct.HBStr, ptr %22, i32 0, i32 2
  %24 = load i8, ptr %23, align 8, !tbaa !11
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 83
  br i1 %26, label %27, label %31

27:                                               ; preds = %18, %2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %29, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %27, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.AtomStr, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = getelementptr inbounds %struct.PropertyStr, ptr %34, i32 0, i32 4
  %36 = load i32, ptr %35, align 4, !tbaa !20
  %37 = call i32 @AtomTypeChange(i32 noundef %36, i32 noundef 0)
  store i32 %37, ptr %7, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.AtomStr, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = getelementptr inbounds %struct.PropertyStr, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 4, !tbaa !20
  %43 = call i32 @AtomTypeChange(i32 noundef %42, i32 noundef 0)
  store i32 %43, ptr %8, align 4, !tbaa !23
  %44 = load i32, ptr %7, align 4, !tbaa !23
  %45 = icmp eq i32 %44, 2
  br i1 %45, label %46, label %51

46:                                               ; preds = %31
  %47 = load i32, ptr %8, align 4, !tbaa !23
  %48 = icmp eq i32 %47, 26
  br i1 %48, label %49, label %51

49:                                               ; preds = %46
  %50 = load double, ptr getelementptr inbounds (%struct.HBPotentialStr, ptr @HBPotential, i32 0, i32 1), align 8, !tbaa !24
  store double %50, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %61

51:                                               ; preds = %46, %31
  %52 = load i32, ptr %7, align 4, !tbaa !23
  %53 = icmp ne i32 %52, 2
  br i1 %53, label %54, label %59

54:                                               ; preds = %51
  %55 = load i32, ptr %8, align 4, !tbaa !23
  %56 = icmp ne i32 %55, 26
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load double, ptr getelementptr inbounds (%struct.HBPotentialStr, ptr @HBPotential, i32 0, i32 3), align 8, !tbaa !26
  store double %58, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %61

59:                                               ; preds = %54, %51
  %60 = load double, ptr getelementptr inbounds (%struct.HBPotentialStr, ptr @HBPotential, i32 0, i32 5), align 8, !tbaa !27
  store double %60, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %61

61:                                               ; preds = %59, %57, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %62 = load double, ptr %3, align 8
  ret double %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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, !6, i64 8}
!10 = !{!"AtomStr", !6, i64 0, !6, i64 8}
!11 = !{!12, !7, i64 88}
!12 = !{!"DynamicStr", !7, i64 0, !7, i64 16, !7, i64 48, !13, i64 80, !15, i64 96, !16, i64 128}
!13 = !{!"HBStr", !14, i64 0, !14, i64 4, !7, i64 8, !14, i64 12}
!14 = !{!"int", !7, i64 0}
!15 = !{!"HBNeighborStr", !7, i64 0, !14, i64 20, !14, i64 24}
!16 = !{!"InteractionEventStr", !14, i64 0, !17, i64 8, !17, i64 16, !18, i64 24, !18, i64 32, !14, i64 40, !14, i64 44}
!17 = !{!"long", !7, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!10, !6, i64 0}
!20 = !{!21, !14, i64 52}
!21 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !14, i64 48, !14, i64 52, !14, i64 56, !18, i64 64, !18, i64 72, !7, i64 80, !22, i64 104, !6, i64 120, !6, i64 128}
!22 = !{!"AtomSeqStr", !14, i64 0, !14, i64 4, !14, i64 8}
!23 = !{!14, !14, i64 0}
!24 = !{!25, !18, i64 8}
!25 = !{!"HBPotentialStr", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !18, i64 32, !18, i64 40}
!26 = !{!25, !18, i64 24}
!27 = !{!25, !18, i64 40}


; 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.HBPotentialStr = type { double, double, double, double, double, double }

@HBPotential = external local_unnamed_addr global %struct.HBPotentialStr, align 8

declare i32 @AtomTypeChange(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @HBBarrier(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 88
  %6 = load i8, ptr %5, align 8, !tbaa !10
  switch i8 %6, label %8 [
    i8 65, label %7
    i8 83, label %7
  ]

7:                                                ; preds = %2, %2
  br label %8

8:                                                ; preds = %2, %7
  %.015 = phi ptr [ %0, %7 ], [ %1, %2 ]
  %.014 = phi ptr [ %1, %7 ], [ %0, %2 ]
  %9 = load ptr, ptr %.014, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %9, i64 52
  %11 = load i32, ptr %10, align 4, !tbaa !19
  %12 = tail call i32 @AtomTypeChange(i32 noundef %11, i32 noundef 0) #2
  %13 = load ptr, ptr %.015, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %13, i64 52
  %15 = load i32, ptr %14, align 4, !tbaa !19
  %16 = tail call i32 @AtomTypeChange(i32 noundef %15, i32 noundef 0) #2
  %17 = icmp eq i32 %12, 2
  %18 = icmp eq i32 %16, 26
  %or.cond = select i1 %17, i1 %18, i1 false
  %19 = icmp ne i32 %12, 2
  %20 = icmp ne i32 %16, 26
  %or.cond3 = select i1 %19, i1 %20, i1 false
  %. = select i1 %or.cond3, ptr getelementptr inbounds (i8, ptr @HBPotential, i64 24), ptr getelementptr inbounds (i8, ptr @HBPotential, i64 40)
  %.0.in = select i1 %or.cond, ptr getelementptr inbounds (i8, ptr @HBPotential, i64 8), ptr %.
  %.0 = load double, ptr %.0.in, align 8, !tbaa !22
  ret double %.0
}

attributes #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 #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 = { 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 = !{!"AtomStr", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !8, i64 88}
!11 = !{!"DynamicStr", !8, i64 0, !8, i64 16, !8, i64 48, !12, i64 80, !14, i64 96, !15, i64 128}
!12 = !{!"HBStr", !13, i64 0, !13, i64 4, !8, i64 8, !13, i64 12}
!13 = !{!"int", !8, i64 0}
!14 = !{!"HBNeighborStr", !8, i64 0, !13, i64 20, !13, i64 24}
!15 = !{!"InteractionEventStr", !13, i64 0, !16, i64 8, !16, i64 16, !17, i64 24, !17, i64 32, !13, i64 40, !13, i64 44}
!16 = !{!"long", !8, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !13, i64 52}
!20 = !{!"PropertyStr", !8, i64 0, !8, i64 8, !8, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !17, i64 64, !17, i64 72, !8, i64 80, !21, i64 104, !7, i64 120, !7, i64 128}
!21 = !{!"AtomSeqStr", !13, i64 0, !13, i64 4, !13, i64 8}
!22 = !{!17, !17, i64 0}


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