; LLVM IR from FSmallenburg/EDMD :: Grow (mdgrow)

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

@time = external dso_local global double, align 8
@maxt = external dso_local global double, align 8
@stop = external dso_local global i32, align 4
@root = external dso_local global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [13 x i8], align 1

; 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 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local void @makeneighborlist(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @thermostat(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @step() #2 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %2 = load ptr, ptr @root, align 8, !tbaa !5
  %3 = getelementptr inbounds %struct.sevent, ptr %2, i32 0, i32 2
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  store ptr %4, ptr %1, align 8, !tbaa !5
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %11

7:                                                ; preds = %0
  call void @addnexteventlist()
  %8 = load ptr, ptr @root, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.sevent, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %1, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %7, %0
  br label %12

12:                                               ; preds = %17, %11
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.sevent, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %21

17:                                               ; preds = %12
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.sevent, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  store ptr %20, ptr %1, align 8, !tbaa !5
  br label %12, !llvm.loop !14

21:                                               ; preds = %12
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.sevent, ptr %22, i32 0, i32 0
  %24 = load double, ptr %23, align 8, !tbaa !16
  %25 = load double, ptr @maxt, align 8, !tbaa !17
  %26 = fcmp ogt double %24, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load double, ptr @maxt, align 8, !tbaa !17
  store double %28, ptr @time, align 8, !tbaa !17
  call void @write()
  call void @writelast()
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  store i32 1, ptr @stop, align 4, !tbaa !18
  br label %30

30:                                               ; preds = %27, %21
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.sevent, ptr %31, i32 0, i32 8
  %33 = load i8, ptr %32, align 8, !tbaa !19
  %34 = zext i8 %33 to i32
  %35 = icmp eq i32 %34, 100
  br i1 %35, label %36, label %41

36:                                               ; preds = %30
  %37 = load ptr, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.sevent, ptr %37, i32 0, i32 0
  %39 = load double, ptr %38, align 8, !tbaa !16
  store double %39, ptr @time, align 8, !tbaa !17
  %40 = load ptr, ptr %1, align 8, !tbaa !5
  call void @removeevent(ptr noundef %40)
  call void @write()
  br label %67

41:                                               ; preds = %30
  %42 = load ptr, ptr %1, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.sevent, ptr %42, i32 0, i32 8
  %44 = load i8, ptr %43, align 8, !tbaa !19
  %45 = zext i8 %44 to i32
  %46 = icmp eq i32 %45, 200
  br i1 %46, label %47, label %49

47:                                               ; preds = %41
  %48 = load ptr, ptr %1, align 8, !tbaa !5
  call void @thermostat(ptr noundef %48)
  br label %66

49:                                               ; preds = %41
  %50 = load ptr, ptr %1, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.sevent, ptr %50, i32 0, i32 8
  %52 = load i8, ptr %51, align 8, !tbaa !19
  %53 = zext i8 %52 to i32
  %54 = icmp eq i32 %53, 8
  br i1 %54, label %55, label %63

55:                                               ; preds = %49
  %56 = load ptr, ptr %1, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.sevent, ptr %56, i32 0, i32 0
  %58 = load double, ptr %57, align 8, !tbaa !16
  store double %58, ptr @time, align 8, !tbaa !17
  %59 = load ptr, ptr %1, align 8, !tbaa !5
  call void @removeevent(ptr noundef %59)
  %60 = load ptr, ptr %1, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.sevent, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  call void @makeneighborlist(ptr noundef %62, i32 noundef 0)
  br label %65

63:                                               ; preds = %49
  %64 = load ptr, ptr %1, align 8, !tbaa !5
  call void @collision(ptr noundef %64)
  br label %65

65:                                               ; preds = %63, %55
  br label %66

66:                                               ; preds = %65, %47
  br label %67

67:                                               ; preds = %66, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @removeevent(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @collision(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @addnexteventlist() #2

; Function Attrs: nounwind uwtable
declare dso_local void @write() #2

; Function Attrs: nounwind uwtable
declare dso_local void @writelast() #2

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 16}
!10 = !{!"sevent", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !12, i64 68, !12, i64 72}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !11, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !7, i64 64}
!20 = !{!10, !6, i64 32}


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

@time = external dso_local local_unnamed_addr global double, align 8
@maxt = external dso_local local_unnamed_addr global double, align 8
@stop = external dso_local local_unnamed_addr global i32, align 4
@root = external dso_local local_unnamed_addr global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @makeneighborlist(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @thermostat(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @step() local_unnamed_addr #1 {
  %1 = load ptr, ptr @root, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !9
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %.preheader

5:                                                ; preds = %0
  tail call void @addnexteventlist()
  %6 = load ptr, ptr @root, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  br label %.preheader

.preheader:                                       ; preds = %5, %0
  %.1.ph = phi ptr [ %3, %0 ], [ %8, %5 ]
  br label %9

9:                                                ; preds = %.preheader, %9
  %.1 = phi ptr [ %11, %9 ], [ %.1.ph, %.preheader ]
  %10 = getelementptr inbounds i8, ptr %.1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %12, label %9, !llvm.loop !14

12:                                               ; preds = %9
  %13 = load double, ptr %.1, align 8, !tbaa !16
  %14 = load double, ptr @maxt, align 8, !tbaa !17
  %15 = fcmp ogt double %13, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  store double %14, ptr @time, align 8, !tbaa !17
  tail call void @write()
  tail call void @writelast()
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  store i32 1, ptr @stop, align 4, !tbaa !18
  br label %18

18:                                               ; preds = %16, %12
  %19 = getelementptr inbounds i8, ptr %.1, i64 64
  %20 = load i8, ptr %19, align 8, !tbaa !19
  switch i8 %20, label %28 [
    i8 100, label %21
    i8 -56, label %23
    i8 8, label %24
  ]

21:                                               ; preds = %18
  %22 = load double, ptr %.1, align 8, !tbaa !16
  store double %22, ptr @time, align 8, !tbaa !17
  tail call void @removeevent(ptr noundef nonnull %.1)
  tail call void @write()
  br label %29

23:                                               ; preds = %18
  tail call void @thermostat(ptr noundef nonnull %.1)
  br label %29

24:                                               ; preds = %18
  %25 = load double, ptr %.1, align 8, !tbaa !16
  store double %25, ptr @time, align 8, !tbaa !17
  tail call void @removeevent(ptr noundef nonnull %.1)
  %26 = getelementptr inbounds i8, ptr %.1, i64 32
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  tail call void @makeneighborlist(ptr noundef %27, i32 noundef 0)
  br label %29

28:                                               ; preds = %18
  tail call void @collision(ptr noundef nonnull %.1)
  br label %29

29:                                               ; preds = %23, %28, %24, %21
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @removeevent(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @collision(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @addnexteventlist() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @write() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @writelast() local_unnamed_addr #1

attributes #0 = { nofree nounwind "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" }

!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 16}
!10 = !{!"sevent", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !12, i64 68, !12, i64 72}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !11, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !7, i64 64}
!20 = !{!10, !6, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass