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

; 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

; 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_lcpiiii(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 = %54, %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 %56

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 %6, align 4, !tbaa !5
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = call noundef i64 @_Z5shashii(i32 noundef %25, i32 noundef %28)
  store i64 %29, ptr %12, align 8, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = add nsw i32 %31, %32
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %53

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

44:                                               ; preds = %36
  %45 = load i64, ptr %12, align 8, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = call noundef i64 @_Z5shashii(i32 noundef %46, i32 noundef %49)
  %51 = icmp eq i64 %45, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  br label %54

53:                                               ; preds = %44, %36, %20
  br label %54

54:                                               ; preds = %53, %52
  %55 = phi ptr [ %9, %52 ], [ %10, %53 ]
  store i32 %30, ptr %55, 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

56:                                               ; preds = %15
  %57 = 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 %57
}

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"

@n = external dso_local local_unnamed_addr global i32, align 4

; 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_lcpiiii(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, %23
  %.0..0.823 = phi i32 [ %.0..0..0..0.8, %23 ], [ 0, %4 ]
  %.0..0.22 = phi i32 [ %.0..0..0..0., %23 ], [ %7, %4 ]
  %9 = add nsw i32 %.0..0.823, %.0..0.22
  %10 = ashr i32 %9, 1
  %11 = add nsw i32 %10, %1
  %12 = tail call noundef i64 @_Z5shashii(i32 noundef %1, i32 noundef %11)
  %13 = add nsw i32 %10, %2
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp sgt i32 %13, %14
  br i1 %.not, label %22, label %15

15:                                               ; preds = %.lr.ph
  %16 = add nsw i32 %10, %0
  %17 = tail call noundef i64 @_Z5shashii(i32 noundef %0, i32 noundef %16)
  %18 = icmp eq i64 %17, %12
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = tail call noundef i64 @_Z5shashii(i32 noundef %2, i32 noundef %13)
  %21 = icmp eq i64 %12, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %19, %15, %.lr.ph
  br label %23

23:                                               ; preds = %19, %22
  %24 = phi ptr [ %6, %22 ], [ %5, %19 ]
  store i32 %10, ptr %24, 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
  %25 = sub nsw i32 %.0..0..0..0., %.0..0..0..0.8
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %23, %4
  %.0..0.8.lcssa = phi i32 [ 0, %4 ], [ %.0..0..0..0.8, %23 ]
  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,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass