; LLVM IR from microsoft/LightAIMD :: src (molecule)

; 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.molecule = type { i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.vec3d = type { double, double, double }

@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [29 x i8], align 1
@ELEMENTS = external global [0 x ptr], align 8
@.str.9 = external hidden unnamed_addr constant [41 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @write_forces(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.molecule, ptr %9, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef @.str.5, i64 noundef %11) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str.9, i64 noundef %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %58, %3
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.molecule, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i64 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %61

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.molecule, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds i64, ptr %27, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds [0 x ptr], ptr @ELEMENTS, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.molecule, ptr %33, i32 0, i32 7
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.vec3d, ptr %35, i64 %36
  %38 = getelementptr inbounds %struct.vec3d, ptr %37, i32 0, i32 0
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = fmul double %39, 0x3FFE3C5175FAA1CE
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.molecule, ptr %41, i32 0, i32 7
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.vec3d, ptr %43, i64 %44
  %46 = getelementptr inbounds %struct.vec3d, ptr %45, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !18
  %48 = fmul double %47, 0x3FFE3C5175FAA1CE
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.molecule, ptr %49, i32 0, i32 7
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.vec3d, ptr %51, i64 %52
  %54 = getelementptr inbounds %struct.vec3d, ptr %53, i32 0, i32 2
  %55 = load double, ptr %54, align 8, !tbaa !19
  %56 = fmul double %55, 0x3FFE3C5175FAA1CE
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.7, ptr noundef %32, double noundef %40, double noundef %48, double noundef %56) #3
  br label %58

58:                                               ; preds = %23
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %7, align 8, !tbaa !9
  br label %16, !llvm.loop !20

61:                                               ; preds = %22
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"molecule", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !6, i64 72}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 56}
!15 = !{!16, !17, i64 0}
!16 = !{!"vec3d", !17, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"double", !7, i64 0}
!18 = !{!16, !17, i64 8}
!19 = !{!16, !17, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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

@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [29 x i8], align 1
@ELEMENTS = external local_unnamed_addr global [0 x ptr], align 8
@.str.9 = external hidden unnamed_addr constant [41 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @write_forces(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.5, i64 noundef %4) #2
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.9, i64 noundef %2) #2
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = getelementptr inbounds i8, ptr %1, i64 56
  br label %10

._crit_edge:                                      ; preds = %10, %3
  ret void

10:                                               ; preds = %.lr.ph, %10
  %.015 = phi i64 [ 0, %.lr.ph ], [ %27, %10 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !11
  %12 = getelementptr inbounds i64, ptr %11, i64 %.015
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds [0 x ptr], ptr @ELEMENTS, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr %9, align 8, !tbaa !14
  %17 = getelementptr inbounds %struct.vec3d, ptr %16, i64 %.015
  %18 = load double, ptr %17, align 8, !tbaa !15
  %19 = fmul double %18, 0x3FFE3C5175FAA1CE
  %20 = getelementptr inbounds i8, ptr %17, i64 8
  %21 = load double, ptr %20, align 8, !tbaa !18
  %22 = fmul double %21, 0x3FFE3C5175FAA1CE
  %23 = getelementptr inbounds i8, ptr %17, i64 16
  %24 = load double, ptr %23, align 8, !tbaa !19
  %25 = fmul double %24, 0x3FFE3C5175FAA1CE
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.7, ptr noundef %15, double noundef %19, double noundef %22, double noundef %25) #2
  %27 = add nuw i64 %.015, 1
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %10, label %._crit_edge, !llvm.loop !20
}

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 = { nofree 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 0}
!6 = !{!"molecule", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 56}
!15 = !{!16, !17, i64 0}
!16 = !{!"vec3d", !17, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"double", !8, i64 0}
!18 = !{!16, !17, i64 8}
!19 = !{!16, !17, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass