; LLVM IR from Ayon-SSP/The-SDE-Prep :: 2]_Algorithms/9]_Dynamic Programming/Travelling_salesman.ll (Z3funii)

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

@dist = external dso_local global [5 x [5 x i32]], align 16
@memo = external dso_local global [5 x [32 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3funii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = shl i32 1, %10
  %12 = or i32 %11, 3
  %13 = icmp eq i32 %9, %12
  br i1 %13, label %14, label %19

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x i32], ptr getelementptr inbounds ([5 x [5 x i32]], ptr @dist, i64 0, i64 1), i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %3, align 4
  br label %84

19:                                               ; preds = %2
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [5 x [32 x i32]], ptr @memo, i64 0, i64 %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [32 x i32], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %36

28:                                               ; preds = %19
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5 x [32 x i32]], ptr @memo, i64 0, i64 %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [32 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %3, align 4
  br label %84

36:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1000000, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %73, %36
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = icmp sle i32 %38, 4
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %76

41:                                               ; preds = %37
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = shl i32 1, %43
  %45 = and i32 %42, %44
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %72

47:                                               ; preds = %41
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp ne i32 %48, %49
  br i1 %50, label %51, label %72

51:                                               ; preds = %47
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = icmp ne i32 %52, 1
  br i1 %53, label %54, label %72

54:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = shl i32 1, %57
  %59 = xor i32 %58, -1
  %60 = and i32 %56, %59
  %61 = call noundef i32 @_Z3funii(i32 noundef %55, i32 noundef %60)
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [5 x [5 x i32]], ptr @dist, i64 0, i64 %63
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [5 x i32], ptr %64, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = add nsw i32 %61, %68
  store i32 %69, ptr %8, align 4, !tbaa !5
  %70 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %71 = load i32, ptr %70, align 4, !tbaa !5
  store i32 %71, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %72

72:                                               ; preds = %54, %51, %47, %41
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !5
  br label %37, !llvm.loop !9

76:                                               ; preds = %40
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [5 x [32 x i32]], ptr @memo, i64 0, i64 %79
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [32 x i32], ptr %80, i64 0, i64 %82
  store i32 %77, ptr %83, align 4, !tbaa !5
  store i32 %77, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %84

84:                                               ; preds = %76, %28, %14
  %85 = load i32, ptr %3, align 4
  ret i32 %85
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@dist = external dso_local local_unnamed_addr global [5 x [5 x i32]], align 16
@memo = external dso_local local_unnamed_addr global [5 x [32 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3funii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = shl nuw i32 1, %0
  %6 = or i32 %5, 3
  %7 = icmp eq i32 %6, %1
  %8 = sext i32 %0 to i64
  br i1 %7, label %9, label %12

9:                                                ; preds = %2
  %10 = getelementptr inbounds [5 x i32], ptr getelementptr inbounds (i8, ptr @dist, i64 20), i64 0, i64 %8
  %11 = load i32, ptr %10, align 4, !tbaa !5
  br label %50

12:                                               ; preds = %2
  %13 = sext i32 %1 to i64
  %14 = getelementptr inbounds [5 x [32 x i32]], ptr @memo, i64 0, i64 %8, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %50

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 1000000, ptr %3, align 4, !tbaa !5
  %17 = xor i32 %5, -1
  %18 = and i32 %17, %1
  %19 = and i32 %1, 4
  %.not26.1 = icmp eq i32 %19, 0
  br i1 %.not26.1, label %28, label %20

20:                                               ; preds = %16
  %.not29 = icmp eq i32 %0, 2
  br i1 %.not29, label %.thread, label %21

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %22 = tail call noundef i32 @_Z3funii(i32 noundef 2, i32 noundef %18)
  %23 = getelementptr inbounds [5 x [5 x i32]], ptr @dist, i64 0, i64 2, i64 %8
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, %22
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %28

28:                                               ; preds = %21, %16
  %29 = phi i32 [ %27, %21 ], [ 1000000, %16 ]
  %30 = and i32 %1, 8
  %.not26.2 = icmp eq i32 %30, 0
  %.not30 = icmp eq i32 %0, 3
  %or.cond = or i1 %.not26.2, %.not30
  br i1 %or.cond, label %38, label %.thread33

.thread:                                          ; preds = %20
  %31 = and i32 %1, 8
  %.not26.232 = icmp eq i32 %31, 0
  br i1 %.not26.232, label %38, label %.thread33

.thread33:                                        ; preds = %28, %.thread
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %32 = call noundef i32 @_Z3funii(i32 noundef 3, i32 noundef %18)
  %33 = getelementptr inbounds [5 x [5 x i32]], ptr @dist, i64 0, i64 3, i64 %8
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %32
  store i32 %35, ptr %4, align 4, !tbaa !5
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %38

38:                                               ; preds = %.thread, %.thread33, %28
  %39 = phi i32 [ %37, %.thread33 ], [ %29, %28 ], [ 1000000, %.thread ]
  %40 = and i32 %1, 16
  %.not26.3 = icmp eq i32 %40, 0
  %.not31 = icmp eq i32 %0, 4
  %or.cond35 = or i1 %.not26.3, %.not31
  br i1 %or.cond35, label %48, label %41

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %42 = call noundef i32 @_Z3funii(i32 noundef 4, i32 noundef %18)
  %43 = getelementptr inbounds [5 x [5 x i32]], ptr @dist, i64 0, i64 4, i64 %8
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, %42
  store i32 %45, ptr %4, align 4, !tbaa !5
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %47 = load i32, ptr %46, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %48

48:                                               ; preds = %41, %38
  %49 = phi i32 [ %47, %41 ], [ %39, %38 ]
  store i32 %49, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %50

50:                                               ; preds = %12, %48, %9
  %.023 = phi i32 [ %11, %9 ], [ %49, %48 ], [ %15, %12 ]
  ret i32 %.023
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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++ TBAA"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass