; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK70/Problem D/brute.ll (Z7get_lcsiiii)

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

; 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z5shashii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7get_lcsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %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 i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  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
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %10, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %60, %4
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = sub nsw i32 %16, %17
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %20, label %62

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  %24 = ashr i32 %23, 1
  store i32 %24, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = sub nsw i32 %25, %26
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  %31 = call noundef i64 @_Z5shashii(i32 noundef %28, i32 noundef %30)
  store i64 %31, ptr %12, align 8, !tbaa !9
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  %36 = add nsw i32 %35, 1
  %37 = icmp sge i32 %36, 0
  br i1 %37, label %38, label %59

38:                                               ; preds = %20
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  %42 = add nsw i32 %41, 1
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = call noundef i64 @_Z5shashii(i32 noundef %42, i32 noundef %44)
  %46 = load i64, ptr %12, align 8, !tbaa !9
  %47 = icmp eq i64 %45, %46
  br i1 %47, label %48, label %59

48:                                               ; preds = %38
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = sub nsw i32 %50, %51
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = call noundef i64 @_Z5shashii(i32 noundef %53, i32 noundef %55)
  %57 = icmp eq i64 %49, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %48
  br label %60

59:                                               ; preds = %48, %38, %20
  br label %60

60:                                               ; preds = %59, %58
  %61 = phi ptr [ %9, %58 ], [ %10, %59 ]
  store i32 %32, ptr %61, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %15, !llvm.loop !11

62:                                               ; preds = %15
  %63 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret i32 %63
}

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

; 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z5shashii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7get_lcsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5)
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6)
  %7 = add nsw i32 %3, 1
  store i32 %7, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %3, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %9 = add i32 %1, 1
  %10 = add nsw i32 %0, 1
  %11 = add i32 %2, 1
  br label %12

12:                                               ; preds = %.lr.ph, %28
  %.0..0.823 = phi i32 [ 0, %.lr.ph ], [ %.0..0..0..0.8, %28 ]
  %.0..0.22 = phi i32 [ %7, %.lr.ph ], [ %.0..0..0..0., %28 ]
  %13 = add nsw i32 %.0..0.823, %.0..0.22
  %14 = ashr i32 %13, 1
  %15 = sub i32 %9, %14
  %16 = tail call noundef i64 @_Z5shashii(i32 noundef %15, i32 noundef %9)
  %17 = sub nsw i32 %0, %14
  %18 = icmp sgt i32 %17, -2
  br i1 %18, label %19, label %27

19:                                               ; preds = %12
  %20 = add nsw i32 %17, 1
  %21 = tail call noundef i64 @_Z5shashii(i32 noundef %20, i32 noundef %10)
  %22 = icmp eq i64 %21, %16
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = sub i32 %11, %14
  %25 = tail call noundef i64 @_Z5shashii(i32 noundef %24, i32 noundef %11)
  %26 = icmp eq i64 %16, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23, %19, %12
  br label %28

28:                                               ; preds = %23, %27
  %29 = phi ptr [ %6, %27 ], [ %5, %23 ]
  store i32 %14, ptr %29, align 4, !tbaa !5
  %.0..0..0..0. = load i32, ptr %6, align 4, !tbaa !5
  %.0..0..0..0.8 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sub nsw i32 %.0..0..0..0., %.0..0..0..0.8
  %31 = icmp sgt i32 %30, 1
  br i1 %31, label %12, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %28, %4
  %.0..0.8.lcssa = phi i32 [ 0, %4 ], [ %.0..0..0..0.8, %28 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5)
  ret i32 %.0..0.8.lcssa
}

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

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass