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

@particles = external dso_local global [100000 x %struct.sparticle], align 16
@xsize = external dso_local global double, align 8
@ysize = external dso_local global double, align 8
@zsize = external dso_local global double, align 8
@.str.31 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [35 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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #1

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @writelast() #3 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [200 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 200, ptr %4) #4
  %5 = getelementptr inbounds [200 x i8], ptr %4, i64 0, i64 0
  %6 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %5, ptr noundef @.str.42) #4
  %7 = getelementptr inbounds [200 x i8], ptr %4, i64 0, i64 0
  %8 = call noalias ptr @fopen(ptr noundef %7, ptr noundef @.str.31)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load double, ptr @xsize, align 8, !tbaa !9
  %11 = load double, ptr @ysize, align 8, !tbaa !9
  %12 = load double, ptr @zsize, align 8, !tbaa !9
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str.43, i32 noundef 100000, double noundef %10, double noundef %11, double noundef %12) #4
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %40, %0
  %15 = load i32, ptr %1, align 4, !tbaa !11
  %16 = icmp slt i32 %15, 100000
  br i1 %16, label %17, label %43

17:                                               ; preds = %14
  %18 = load i32, ptr %1, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100000 x %struct.sparticle], ptr @particles, i64 0, i64 %19
  store ptr %20, ptr %2, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.sparticle, ptr %22, i32 0, i32 28
  %24 = load i8, ptr %23, align 4, !tbaa !13
  %25 = zext i8 %24 to i32
  %26 = add nsw i32 97, %25
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sparticle, ptr %27, i32 0, i32 0
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.sparticle, ptr %30, i32 0, i32 1
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sparticle, ptr %33, i32 0, i32 2
  %35 = load double, ptr %34, align 8, !tbaa !17
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.sparticle, ptr %36, i32 0, i32 13
  %38 = load double, ptr %37, align 8, !tbaa !18
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.44, i32 noundef %26, double noundef %29, double noundef %32, double noundef %35, double noundef %38) #4
  br label %40

40:                                               ; preds = %17
  %41 = load i32, ptr %1, align 4, !tbaa !11
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %1, align 4, !tbaa !11
  br label %14, !llvm.loop !19

43:                                               ; preds = %14
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i32 @fclose(ptr noundef %44)
  call void @llvm.lifetime.end.p0(i64 200, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  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 = { "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 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 #4 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 364}
!14 = !{!"sparticle", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !7, i64 80, !7, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !7, i64 312, !7, i64 313, !7, i64 314, !7, i64 315, !12, i64 316, !12, i64 320, !12, i64 324, !6, i64 328, !12, i64 336, !6, i64 344, !6, i64 352, !12, i64 360, !7, i64 364}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!14, !10, i64 16}
!18 = !{!14, !10, i64 288}
!19 = distinct !{!19, !20}
!20 = !{!"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.sparticle = type { double, double, double, double, double, double, double, double, double, double, [24 x ptr], i8, double, double, double, double, i8, i8, i8, i8, i32, i32, i32, ptr, i32, ptr, ptr, i32, i8 }

@particles = external dso_local local_unnamed_addr global [100000 x %struct.sparticle], align 16
@xsize = external dso_local local_unnamed_addr global double, align 8
@ysize = external dso_local local_unnamed_addr global double, align 8
@zsize = external dso_local local_unnamed_addr global double, align 8
@.str.31 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [35 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local void @writelast() local_unnamed_addr #2 {
  %1 = alloca [200 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %1) #3
  %2 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.42) #3
  %3 = call noalias ptr @fopen(ptr noundef nonnull %1, ptr noundef nonnull @.str.31)
  %4 = load double, ptr @xsize, align 8, !tbaa !5
  %5 = load double, ptr @ysize, align 8, !tbaa !5
  %6 = load double, ptr @zsize, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.43, i32 noundef 100000, double noundef %4, double noundef %5, double noundef %6) #3
  br label %8

8:                                                ; preds = %0, %8
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %8 ]
  %9 = getelementptr inbounds [100000 x %struct.sparticle], ptr @particles, i64 0, i64 %indvars.iv
  %10 = getelementptr inbounds i8, ptr %9, i64 364
  %11 = load i8, ptr %10, align 4, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = add nuw nsw i32 %12, 97
  %14 = load double, ptr %9, align 16, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %9, i64 8
  %16 = load double, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %9, i64 16
  %18 = load double, ptr %17, align 16, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %9, i64 288
  %20 = load double, ptr %19, align 16, !tbaa !16
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.44, i32 noundef %13, double noundef %14, double noundef %16, double noundef %18, double noundef %20) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100000
  br i1 %exitcond.not, label %22, label %8, !llvm.loop !17

22:                                               ; preds = %8
  %23 = tail call i32 @fclose(ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %1) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 364}
!10 = !{!"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, !6, i64 72, !7, i64 80, !7, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !7, i64 312, !7, i64 313, !7, i64 314, !7, i64 315, !11, i64 316, !11, i64 320, !11, i64 324, !12, i64 328, !11, i64 336, !12, i64 344, !12, i64 352, !11, i64 360, !7, i64 364}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !6, i64 288}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass