; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Feb 2016/Plat/16 Feb P1.ll (Z5solveii)

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

@t = external dso_local global [2 x [262144 x i32]], align 16
@c1 = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5queryiiiiib(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7computei(i32 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5solveii(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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sub nsw i32 %14, %15
  %17 = icmp slt i32 %16, 2
  br i1 %17, label %18, label %25

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = call noundef i32 @_Z7computei(i32 noundef %19)
  store i32 %20, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = call noundef i32 @_Z7computei(i32 noundef %21)
  store i32 %22, ptr %7, align 4, !tbaa !5
  %23 = 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) %7)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %89

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = sdiv i32 %28, 2
  store i32 %29, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %30 = load i32, ptr @c1, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = call noundef i32 @_Z5queryiiiiib(i32 noundef 1, i32 noundef 1, i32 noundef %30, i32 noundef 1, i32 noundef %31, i1 noundef zeroext false)
  store i32 %32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %33 = load i32, ptr @c1, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = call noundef i32 @_Z5queryiiiiib(i32 noundef 1, i32 noundef 1, i32 noundef %33, i32 noundef 1, i32 noundef %34, i1 noundef zeroext true)
  store i32 %35, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %36 = load i32, ptr getelementptr inbounds ([262144 x i32], ptr @t, i64 0, i64 1), align 4, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = sub nsw i32 %36, %37
  store i32 %38, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %39 = load i32, ptr getelementptr inbounds ([262144 x i32], ptr getelementptr inbounds ([2 x [262144 x i32]], ptr @t, i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  store i32 %41, ptr %12, align 4, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = icmp sgt i32 %42, %43
  br i1 %44, label %45, label %65

45:                                               ; preds = %25
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = call noundef i32 @_Z5solveii(i32 noundef %50, i32 noundef %51)
  store i32 %52, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %88

53:                                               ; preds = %45
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !5
  %56 = icmp sgt i32 %54, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %53
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = call noundef i32 @_Z5solveii(i32 noundef %58, i32 noundef %59)
  store i32 %60, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %88

61:                                               ; preds = %53
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = call noundef i32 @_Z5solveii(i32 noundef %62, i32 noundef %63)
  store i32 %64, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %88

65:                                               ; preds = %25
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = icmp sgt i32 %66, %67
  br i1 %68, label %69, label %82

69:                                               ; preds = %65
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = icmp sgt i32 %70, %71
  br i1 %72, label %73, label %77

73:                                               ; preds = %69
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = call noundef i32 @_Z5solveii(i32 noundef %74, i32 noundef %75)
  br label %81

77:                                               ; preds = %69
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = call noundef i32 @_Z5solveii(i32 noundef %78, i32 noundef %79)
  store i32 %80, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %88

81:                                               ; preds = %73
  br label %86

82:                                               ; preds = %65
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = call noundef i32 @_Z5solveii(i32 noundef %83, i32 noundef %84)
  store i32 %85, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %88

86:                                               ; preds = %81
  br label %87

87:                                               ; preds = %86
  unreachable

88:                                               ; preds = %82, %77, %61, %57, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %89

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

; 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

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


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

@t = external dso_local local_unnamed_addr global [2 x [262144 x i32]], align 16
@c1 = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5queryiiiiib(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7computei(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5solveii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse.outer.backedge, %2
  %.tr.ph = phi i32 [ %0, %2 ], [ %.tr.ph.be, %tailrecurse.outer.backedge ]
  %.tr37.ph = phi i32 [ %1, %2 ], [ %.tr37.ph.be, %tailrecurse.outer.backedge ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %25
  %.tr37 = phi i32 [ %14, %25 ], [ %.tr37.ph, %tailrecurse.outer ]
  %5 = sub nsw i32 %.tr37, %.tr.ph
  %6 = icmp slt i32 %5, 2
  br i1 %6, label %7, label %12

7:                                                ; preds = %tailrecurse
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %8 = tail call noundef i32 @_Z7computei(i32 noundef %.tr.ph)
  store i32 %8, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %9 = tail call noundef i32 @_Z7computei(i32 noundef %.tr37)
  store i32 %9, ptr %4, align 4, !tbaa !5
  %10 = 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)
  %11 = load i32, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %11

12:                                               ; preds = %tailrecurse
  %13 = add nsw i32 %.tr37, %.tr.ph
  %14 = sdiv i32 %13, 2
  %15 = load i32, ptr @c1, align 4, !tbaa !5
  %16 = tail call noundef i32 @_Z5queryiiiiib(i32 noundef 1, i32 noundef 1, i32 noundef %15, i32 noundef 1, i32 noundef %14, i1 noundef zeroext false)
  %17 = load i32, ptr @c1, align 4, !tbaa !5
  %18 = tail call noundef i32 @_Z5queryiiiiib(i32 noundef 1, i32 noundef 1, i32 noundef %17, i32 noundef 1, i32 noundef %14, i1 noundef zeroext true)
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @t, i64 4), align 4, !tbaa !5
  %20 = sub nsw i32 %19, %16
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @t, i64 1048580), align 4, !tbaa !5
  %22 = sub nsw i32 %21, %18
  %23 = icmp sgt i32 %16, %20
  %24 = icmp sgt i32 %18, %22
  br i1 %23, label %25, label %28

25:                                               ; preds = %12
  br i1 %24, label %tailrecurse, label %26

26:                                               ; preds = %25
  %27 = icmp sgt i32 %16, %22
  %.tr. = select i1 %27, i32 %.tr.ph, i32 %14
  %..tr37 = select i1 %27, i32 %14, i32 %.tr37
  br label %tailrecurse.outer.backedge

tailrecurse.outer.backedge:                       ; preds = %26, %28
  %.tr.ph.be = phi i32 [ %14, %28 ], [ %.tr., %26 ]
  %.tr37.ph.be = phi i32 [ %.tr37, %28 ], [ %..tr37, %26 ]
  br label %tailrecurse.outer

28:                                               ; preds = %12
  %29 = icmp sgt i32 %18, %20
  %or.cond = and i1 %29, %24
  br i1 %or.cond, label %30, label %tailrecurse.outer.backedge

30:                                               ; preds = %28
  %31 = tail call noundef i32 @_Z5solveii(i32 noundef %.tr.ph, i32 noundef %14)
  unreachable
}

; 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

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 = { 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: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass