; LLVM IR from dssgabriel/lattice-boltzmann-method :: v0-base/src (display)

; 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.lbm_data_file_s = type { ptr, %struct.lbm_file_header_s, ptr }
%struct.lbm_file_header_s = type { i32, i32, i32, i32 }
%struct.lbm_file_entry_s = type { float, float }

@checksum = external dso_local global double, align 8
@.str.13 = external hidden unnamed_addr constant [10 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
define dso_local void @do_checksum(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %58, %1
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.lbm_data_file_s, ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds %struct.lbm_file_header_s, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %8, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %7
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %61

16:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %54, %16
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.lbm_data_file_s, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds %struct.lbm_file_header_s, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = icmp ult i64 %18, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %17
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %57

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lbm_data_file_s, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %struct.lbm_file_header_s, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = zext i32 %30 to i64
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = mul i64 %31, %32
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = add i64 %33, %34
  store i64 %35, ptr %6, align 8, !tbaa !9
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lbm_data_file_s, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.lbm_file_entry_s, ptr %38, i64 %39
  %41 = getelementptr inbounds %struct.lbm_file_entry_s, ptr %40, i32 0, i32 1
  %42 = load float, ptr %41, align 4, !tbaa !17
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lbm_data_file_s, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.lbm_file_entry_s, ptr %45, i64 %46
  %48 = getelementptr inbounds %struct.lbm_file_entry_s, ptr %47, i32 0, i32 0
  %49 = load float, ptr %48, align 4, !tbaa !20
  %50 = fadd float %42, %49
  %51 = fpext float %50 to double
  %52 = load double, ptr @checksum, align 8, !tbaa !21
  %53 = fadd double %52, %51
  store double %53, ptr @checksum, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %54

54:                                               ; preds = %26
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %5, align 8, !tbaa !9
  br label %17, !llvm.loop !23

57:                                               ; preds = %25
  br label %58

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

61:                                               ; preds = %15
  %62 = load double, ptr @checksum, align 8, !tbaa !21
  %63 = fptoui double %62 to i64
  %64 = load double, ptr @checksum, align 8, !tbaa !21
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i64 noundef %63, double noundef %64)
  ret void
}

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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !14, i64 12}
!12 = !{!"lbm_data_file_s", !6, i64 0, !13, i64 8, !6, i64 24}
!13 = !{!"lbm_file_header_s", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 16}
!16 = !{!12, !6, i64 24}
!17 = !{!18, !19, i64 4}
!18 = !{!"lbm_file_entry_s", !19, i64 0, !19, i64 4}
!19 = !{!"float", !7, i64 0}
!20 = !{!18, !19, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"double", !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


; 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.lbm_file_entry_s = type { float, float }

@checksum = external dso_local local_unnamed_addr global double, align 8
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @do_checksum(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = zext i32 %3 to i64
  %checksum.promoted15 = load double, ptr @checksum, align 8, !tbaa !12
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge20, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !14
  %7 = zext i32 %6 to i64
  %.not21 = icmp eq i32 %6, 0
  br i1 %.not21, label %._crit_edge20, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %xtraiter = and i64 %7, 3
  %10 = icmp ult i32 %6, 4
  %unroll_iter = and i64 %7, 4294967292
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %.019.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %55, %._crit_edge.us ]
  %.lcssa1718.us = phi double [ %checksum.promoted15, %.preheader.lr.ph.split.us ], [ %.lcssa, %._crit_edge.us ]
  %11 = mul nuw i64 %.019.us, %7
  %12 = getelementptr %struct.lbm_file_entry_s, ptr %9, i64 %11
  br i1 %10, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.01214.us = phi i64 [ %45, %.preheader.us.new ], [ 0, %.preheader.us ]
  %13 = phi double [ %44, %.preheader.us.new ], [ %.lcssa1718.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %14 = getelementptr %struct.lbm_file_entry_s, ptr %12, i64 %.01214.us
  %15 = getelementptr inbounds i8, ptr %14, i64 4
  %16 = load float, ptr %15, align 4, !tbaa !16
  %17 = load float, ptr %14, align 4, !tbaa !19
  %18 = fadd float %16, %17
  %19 = fpext float %18 to double
  %20 = fadd double %13, %19
  %21 = or disjoint i64 %.01214.us, 1
  %22 = getelementptr %struct.lbm_file_entry_s, ptr %12, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %24 = load float, ptr %23, align 4, !tbaa !16
  %25 = load float, ptr %22, align 4, !tbaa !19
  %26 = fadd float %24, %25
  %27 = fpext float %26 to double
  %28 = fadd double %20, %27
  %29 = or disjoint i64 %.01214.us, 2
  %30 = getelementptr %struct.lbm_file_entry_s, ptr %12, i64 %29
  %31 = getelementptr inbounds i8, ptr %30, i64 4
  %32 = load float, ptr %31, align 4, !tbaa !16
  %33 = load float, ptr %30, align 4, !tbaa !19
  %34 = fadd float %32, %33
  %35 = fpext float %34 to double
  %36 = fadd double %28, %35
  %37 = or disjoint i64 %.01214.us, 3
  %38 = getelementptr %struct.lbm_file_entry_s, ptr %12, i64 %37
  %39 = getelementptr inbounds i8, ptr %38, i64 4
  %40 = load float, ptr %39, align 4, !tbaa !16
  %41 = load float, ptr %38, align 4, !tbaa !19
  %42 = fadd float %40, %41
  %43 = fpext float %42 to double
  %44 = fadd double %36, %43
  %45 = add nuw nsw i64 %.01214.us, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !20

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa.ph = phi double [ poison, %.preheader.us ], [ %44, %.preheader.us.new ]
  %.01214.us.unr = phi i64 [ 0, %.preheader.us ], [ %45, %.preheader.us.new ]
  %.unr = phi double [ %.lcssa1718.us, %.preheader.us ], [ %44, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.01214.us.epil = phi i64 [ %54, %.epil.preheader ], [ %.01214.us.unr, %._crit_edge.us.unr-lcssa ]
  %46 = phi double [ %53, %.epil.preheader ], [ %.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %47 = getelementptr %struct.lbm_file_entry_s, ptr %12, i64 %.01214.us.epil
  %48 = getelementptr inbounds i8, ptr %47, i64 4
  %49 = load float, ptr %48, align 4, !tbaa !16
  %50 = load float, ptr %47, align 4, !tbaa !19
  %51 = fadd float %49, %50
  %52 = fpext float %51 to double
  %53 = fadd double %46, %52
  %54 = add nuw nsw i64 %.01214.us.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !22

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %53, %.epil.preheader ]
  %55 = add nuw nsw i64 %.019.us, 1
  %exitcond22.not = icmp eq i64 %55, %4
  br i1 %exitcond22.not, label %._crit_edge20.split.us, label %.preheader.us, !llvm.loop !24

._crit_edge20.split.us:                           ; preds = %._crit_edge.us
  store double %.lcssa, ptr @checksum, align 8, !tbaa !12
  br label %._crit_edge20

._crit_edge20:                                    ; preds = %.preheader.lr.ph, %._crit_edge20.split.us, %1
  %56 = phi double [ %.lcssa, %._crit_edge20.split.us ], [ %checksum.promoted15, %1 ], [ %checksum.promoted15, %.preheader.lr.ph ]
  %57 = fptoui double %56 to i64
  %58 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i64 noundef %57, double noundef %56)
  ret void
}

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

!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, !11, i64 12}
!6 = !{!"lbm_data_file_s", !7, i64 0, !10, i64 8, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"lbm_file_header_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !7, i64 24}
!16 = !{!17, !18, i64 4}
!17 = !{!"lbm_file_entry_s", !18, i64 0, !18, i64 4}
!18 = !{!"float", !8, i64 0}
!19 = !{!17, !18, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}
!24 = distinct !{!24, !21}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass