; LLVM IR from Izaron/ACM-ICPC :: Russian Council of School Olympiads (R.S.O.Sh.)/Zaoch/2017/strudel.ll (Z4calcxxx)

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

20:                                               ; preds = %69, %3
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = icmp ne i64 %21, %22
  br i1 %23, label %24, label %70

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %25 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %26 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %26, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %27 = load i64, ptr %7, align 8, !tbaa !5
  %28 = load i64, ptr %8, align 8, !tbaa !5
  %29 = add nsw i64 %27, %28
  %30 = sdiv i64 %29, 2
  store i64 %30, ptr %11, align 8, !tbaa !5
  %31 = load i64, ptr %11, align 8, !tbaa !5
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = sub nsw i64 %33, %34
  %36 = sdiv i64 %35, 2
  %37 = sub nsw i64 %31, %36
  %38 = sub nsw i64 %37, 1
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = icmp sge i64 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %24
  %42 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %42, ptr %8, align 8, !tbaa !5
  br label %45

43:                                               ; preds = %24
  %44 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %44, ptr %7, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %43, %41
  %46 = load i64, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %7, align 8, !tbaa !5
  %48 = icmp eq i64 %46, %47
  br i1 %48, label %49, label %69

49:                                               ; preds = %45
  %50 = load i64, ptr %10, align 8, !tbaa !5
  %51 = load i64, ptr %8, align 8, !tbaa !5
  %52 = icmp eq i64 %50, %51
  br i1 %52, label %53, label %69

53:                                               ; preds = %49
  %54 = load i64, ptr %7, align 8, !tbaa !5
  %55 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = sub nsw i64 %56, %57
  %59 = sdiv i64 %58, 2
  %60 = sub nsw i64 %54, %59
  %61 = sub nsw i64 %60, 1
  %62 = load i64, ptr %4, align 8, !tbaa !5
  %63 = icmp sge i64 %61, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %53
  %65 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %65, ptr %8, align 8, !tbaa !5
  br label %68

66:                                               ; preds = %53
  %67 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %67, ptr %7, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %66, %64
  br label %69

69:                                               ; preds = %68, %49, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %20, !llvm.loop !9

70:                                               ; preds = %20
  %71 = load i64, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %71
}

; 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 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = !{!"long long", !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"

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

.lr.ph:                                           ; preds = %3, %30
  %11 = phi i64 [ %22, %30 ], [ %0, %3 ]
  %.021 = phi i64 [ %.1, %30 ], [ %10, %3 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %12 = add nsw i64 %11, %.021
  %13 = sdiv i64 %12, 2
  store i64 %13, ptr %6, align 8, !tbaa !5
  %14 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = sub nsw i64 %15, %1
  %.neg = sdiv i64 %16, -2
  %17 = add nsw i64 %.neg, %13
  %.not17.not = icmp sgt i64 %17, %0
  %18 = load i64, ptr %6, align 8, !tbaa !5
  br i1 %.not17.not, label %19, label %20

19:                                               ; preds = %.lr.ph
  %.pre = load i64, ptr %5, align 8, !tbaa !5
  br label %21

20:                                               ; preds = %.lr.ph
  store i64 %18, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %20, %19
  %22 = phi i64 [ %.pre, %19 ], [ %18, %20 ]
  %.1 = phi i64 [ %18, %19 ], [ %.021, %20 ]
  %23 = icmp eq i64 %11, %22
  %24 = icmp eq i64 %.021, %.1
  %or.cond = select i1 %23, i1 %24, i1 false
  br i1 %or.cond, label %.thread, label %30

.thread:                                          ; preds = %21
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = sub nsw i64 %26, %1
  %.neg18 = sdiv i64 %27, -2
  %28 = add i64 %.neg18, %11
  %.not19.not = icmp sgt i64 %28, %0
  %29 = load i64, ptr %5, align 8
  %.ph = select i1 %.not19.not, i64 %29, i64 %.021
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  br label %._crit_edge

30:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  %.not = icmp eq i64 %22, %.1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %30, %.thread, %3
  %.lcssa = phi i64 [ %0, %3 ], [ %.ph, %.thread ], [ %22, %30 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.lcssa
}

; 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 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = !{!"long long", !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,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass