; LLVM IR from ahr9n/psolving-paradigms :: 4.dynamic-programming/21.non-classical/UVa 11753 - Creating Palindrome.ll (Z2dpiii)

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

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@a = external dso_local global [200005 x i32], align 16
@mem = external dso_local global [200005 x [21 x [21 x i32]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2dpiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = add nsw i32 %13, %14
  %16 = load i32, ptr @k, align 4, !tbaa !5
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %22

18:                                               ; preds = %3
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = add nsw i32 %19, %20
  store i32 %21, ptr %4, align 4
  br label %88

22:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sub nsw i32 %24, %25
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = sub nsw i32 %26, %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  store i32 %30, ptr %8, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = icmp sge i32 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %22
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %87

35:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [200005 x [21 x [21 x i32]]], ptr @mem, i64 0, i64 %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [21 x [21 x i32]], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [21 x i32], ptr %41, i64 0, i64 %43
  store ptr %44, ptr %10, align 8, !tbaa !9
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = xor i32 %46, -1
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %35
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %86

52:                                               ; preds = %35
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = icmp eq i32 %56, %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  br i1 %61, label %62, label %68

62:                                               ; preds = %52
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = call noundef i32 @_Z2dpiii(i32 noundef %64, i32 noundef %65, i32 noundef %66)
  br label %83

68:                                               ; preds = %52
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = call noundef i32 @_Z2dpiii(i32 noundef %70, i32 noundef %71, i32 noundef %73)
  store i32 %74, ptr %11, align 4, !tbaa !5
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = call noundef i32 @_Z2dpiii(i32 noundef %75, i32 noundef %77, i32 noundef %78)
  store i32 %79, ptr %12, align 4, !tbaa !5
  %80 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = add nsw i32 1, %81
  br label %83

83:                                               ; preds = %68, %62
  %84 = phi i32 [ %67, %62 ], [ %82, %68 ]
  %85 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %84, ptr %85, align 4, !tbaa !5
  store i32 %84, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  store i32 1, ptr %9, align 4
  br label %86

86:                                               ; preds = %83, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %87

87:                                               ; preds = %86, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %88

88:                                               ; preds = %87, %18
  %89 = load i32, ptr %4, align 4
  ret i32 %89
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [200005 x i32], align 16
@mem = external dso_local local_unnamed_addr global [200005 x [21 x [21 x i32]]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2dpiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = add nsw i32 %2, %1
  %7 = load i32, ptr @k, align 4, !tbaa !5
  %8 = icmp sgt i32 %6, %7
  br i1 %8, label %41, label %9

9:                                                ; preds = %3
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = xor i32 %0, -1
  %12 = sub i32 %11, %1
  %13 = add i32 %12, %2
  %14 = add i32 %13, %10
  %.not = icmp sgt i32 %14, %0
  br i1 %.not, label %15, label %41

15:                                               ; preds = %9
  %16 = sext i32 %0 to i64
  %17 = sext i32 %1 to i64
  %18 = sext i32 %2 to i64
  %19 = getelementptr inbounds [200005 x [21 x [21 x i32]]], ptr @mem, i64 0, i64 %16, i64 %17, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not29 = icmp eq i32 %20, -1
  br i1 %.not29, label %21, label %41

21:                                               ; preds = %15
  %22 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %16
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %14 to i64
  %25 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %23, %26
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %28 = add nsw i32 %0, 1
  br i1 %27, label %29, label %31

29:                                               ; preds = %21
  %30 = tail call noundef i32 @_Z2dpiii(i32 noundef %28, i32 noundef %1, i32 noundef %2)
  br label %39

31:                                               ; preds = %21
  %32 = add nsw i32 %2, 1
  %33 = tail call noundef i32 @_Z2dpiii(i32 noundef %28, i32 noundef %1, i32 noundef %32)
  store i32 %33, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %1, 1
  %35 = tail call noundef i32 @_Z2dpiii(i32 noundef %0, i32 noundef %34, i32 noundef %2)
  store i32 %35, ptr %5, align 4, !tbaa !5
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  br label %39

39:                                               ; preds = %31, %29
  %40 = phi i32 [ %30, %29 ], [ %38, %31 ]
  store i32 %40, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %41

41:                                               ; preds = %9, %15, %39, %3
  %.2 = phi i32 [ %6, %3 ], [ 0, %9 ], [ %40, %39 ], [ %20, %15 ]
  ret i32 %.2
}

; 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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass