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

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

@atomnum = external global i32, align 4
@connectionMap = external global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [2 x i8], align 1
@currenttime = external global double, align 8
@.str.74 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [7 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 uwtable
declare dso_local void @BackupFile(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @SaveConnectionMap(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.FileStr, ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  %11 = xor i1 %10, true
  %12 = xor i1 %11, true
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void @BackupFile(ptr noundef %18)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  call void @GenerateFile(ptr noundef %19)
  br label %20

20:                                               ; preds = %17, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.FileStr, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  store ptr %23, ptr %3, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load double, ptr @currenttime, align 8, !tbaa !12
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.74, double noundef %25) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !14
  br label %27

27:                                               ; preds = %69, %20
  %28 = load i32, ptr %4, align 4, !tbaa !14
  %29 = load i32, ptr @atomnum, align 4, !tbaa !14
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %72

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %63, %32
  %34 = load i32, ptr %6, align 4, !tbaa !14
  %35 = load i32, ptr @atomnum, align 4, !tbaa !14
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %66

38:                                               ; preds = %33
  %39 = load ptr, ptr @connectionMap, align 8, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !14
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !14
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %49, label %62

49:                                               ; preds = %38
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i32, ptr %6, align 4, !tbaa !14
  %52 = load ptr, ptr @connectionMap, align 8, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !14
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !14
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !14
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.75, i32 noundef %51, i32 noundef %60) #5
  br label %62

62:                                               ; preds = %49, %38
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %6, align 4, !tbaa !14
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !14
  br label %33, !llvm.loop !15

66:                                               ; preds = %37
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.15) #5
  br label %69

69:                                               ; preds = %66
  %70 = load i32, ptr %4, align 4, !tbaa !14
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !14
  br label %27, !llvm.loop !17

72:                                               ; preds = %31
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = call i32 @fflush(ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

declare i32 @fflush(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { "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 #5 = { 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 264}
!10 = !{!"FileStr", !11, i64 0, !7, i64 4, !6, i64 264}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@atomnum = external local_unnamed_addr global i32, align 4
@connectionMap = external local_unnamed_addr global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [2 x i8], align 1
@currenttime = external local_unnamed_addr global double, align 8
@.str.74 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @SaveConnectionMap(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 264
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6, !prof !11

5:                                                ; preds = %1
  tail call void @BackupFile(ptr noundef nonnull %0)
  tail call void @GenerateFile(ptr noundef nonnull %0)
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %1
  %7 = phi ptr [ %.pre, %5 ], [ %3, %1 ]
  %8 = load double, ptr @currenttime, align 8, !tbaa !12
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.74, double noundef %8) #2
  %10 = load i32, ptr @atomnum, align 4, !tbaa !14
  %.not21 = icmp slt i32 %10, 1
  br i1 %.not21, label %._crit_edge23, label %.preheader

.preheader:                                       ; preds = %6, %._crit_edge
  %11 = phi i32 [ %14, %._crit_edge ], [ %10, %6 ]
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %._crit_edge ], [ 1, %6 ]
  %.not1819 = icmp slt i32 %11, 1
  br i1 %.not1819, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %.pre29 = load ptr, ptr @connectionMap, align 8, !tbaa !15
  br label %16

._crit_edge23:                                    ; preds = %._crit_edge, %6
  %12 = tail call i32 @fflush(ptr noundef %7)
  ret void

._crit_edge:                                      ; preds = %27, %.preheader
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.15) #2
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %14 = load i32, ptr @atomnum, align 4, !tbaa !14
  %15 = sext i32 %14 to i64
  %.not.not = icmp slt i64 %indvars.iv25, %15
  br i1 %.not.not, label %.preheader, label %._crit_edge23, !llvm.loop !16

16:                                               ; preds = %.lr.ph, %27
  %17 = phi i32 [ %11, %.lr.ph ], [ %28, %27 ]
  %18 = phi ptr [ %.pre29, %.lr.ph ], [ %29, %27 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %19 = getelementptr inbounds ptr, ptr %18, i64 %indvars.iv25
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = getelementptr inbounds i32, ptr %20, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %16
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.75, i32 noundef %25, i32 noundef %22) #2
  %.pre28 = load ptr, ptr @connectionMap, align 8, !tbaa !15
  %.pre30 = load i32, ptr @atomnum, align 4, !tbaa !14
  br label %27

27:                                               ; preds = %16, %24
  %28 = phi i32 [ %17, %16 ], [ %.pre30, %24 ]
  %29 = phi ptr [ %18, %16 ], [ %.pre28, %24 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = sext i32 %28 to i64
  %.not18.not = icmp slt i64 %indvars.iv, %30
  br i1 %.not18.not, label %16, label %._crit_edge, !llvm.loop !18
}

; 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 @fflush(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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, !10, i64 264}
!6 = !{!"FileStr", !7, i64 0, !8, i64 4, !10, i64 264}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass