; LLVM IR from fcimeson/cbTSP :: cbLKH/SRC (Genetic)

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

@Fitness = external dso_local global ptr, align 8
@PopulationSize = external dso_local global i32, align 4
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1
@Optimum = external dso_local global i64, align 8
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 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 void @printff(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @PrintPopulation() #2 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void (ptr, ...) @printff(ptr noundef @.str.6)
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %33, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = load i32, ptr @PopulationSize, align 4, !tbaa !5
  %5 = icmp slt i32 %3, %4
  br i1 %5, label %6, label %36

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  %9 = load ptr, ptr @Fitness, align 8, !tbaa !9
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i64, ptr %9, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !11
  call void (ptr, ...) @printff(ptr noundef @.str.7, i32 noundef %8, i64 noundef %13)
  %14 = load i64, ptr @Optimum, align 8, !tbaa !11
  %15 = icmp ne i64 %14, -9223372036854775808
  br i1 %15, label %16, label %32

16:                                               ; preds = %6
  %17 = load i64, ptr @Optimum, align 8, !tbaa !11
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %32

19:                                               ; preds = %16
  %20 = load ptr, ptr @Fitness, align 8, !tbaa !9
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i64, ptr %20, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = load i64, ptr @Optimum, align 8, !tbaa !11
  %26 = sub nsw i64 %24, %25
  %27 = sitofp i64 %26 to double
  %28 = fmul double 1.000000e+02, %27
  %29 = load i64, ptr @Optimum, align 8, !tbaa !11
  %30 = sitofp i64 %29 to double
  %31 = fdiv double %28, %30
  call void (ptr, ...) @printff(ptr noundef @.str.8, double noundef %31)
  br label %32

32:                                               ; preds = %19, %16, %6
  call void (ptr, ...) @printff(ptr noundef @.str.9)
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !13

36:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@Fitness = external dso_local local_unnamed_addr global ptr, align 8
@PopulationSize = external dso_local local_unnamed_addr global i32, align 4
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1
@Optimum = external dso_local local_unnamed_addr global i64, align 8
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

declare void @printff(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @PrintPopulation() local_unnamed_addr #1 {
  tail call void (ptr, ...) @printff(ptr noundef nonnull @.str.6) #2
  %1 = load i32, ptr @PopulationSize, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %18
  %indvars.iv = phi i64 [ %indvars.iv.next, %18 ], [ 0, %0 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %3 = load ptr, ptr @Fitness, align 8, !tbaa !9
  %4 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = trunc nuw nsw i64 %indvars.iv.next to i32
  tail call void (ptr, ...) @printff(ptr noundef nonnull @.str.7, i32 noundef %6, i64 noundef %5) #2
  %7 = load i64, ptr @Optimum, align 8
  %8 = and i64 %7, 9223372036854775807
  %or.cond.not = icmp eq i64 %8, 0
  br i1 %or.cond.not, label %18, label %9

9:                                                ; preds = %.lr.ph
  %10 = load ptr, ptr @Fitness, align 8, !tbaa !9
  %11 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = sub nsw i64 %12, %7
  %14 = sitofp i64 %13 to double
  %15 = fmul double %14, 1.000000e+02
  %16 = sitofp i64 %7 to double
  %17 = fdiv double %15, %16
  tail call void (ptr, ...) @printff(ptr noundef nonnull @.str.8, double noundef %17) #2
  br label %18

18:                                               ; preds = %9, %.lr.ph
  tail call void (ptr, ...) @printff(ptr noundef nonnull @.str.9) #2
  %19 = load i32, ptr @PopulationSize, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %18, %0
  ret void
}

attributes #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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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