; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 3/1238. Folding.ll (Z2dpii)

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

@calced = external dso_local global [105 x [105 x i32]], align 16
@folds = external dso_local global [105 x [105 x i32]], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  br label %118

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [105 x [105 x i32]], ptr @calced, i64 0, i64 %19
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [105 x i32], ptr %20, i64 0, i64 %22
  store ptr %23, ptr %6, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, -1
  br i1 %26, label %27, label %30

27:                                               ; preds = %17
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %117

30:                                               ; preds = %17
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 1073741823, ptr %31, align 4, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = call noundef i32 @_Z2dpii(i32 noundef %34, i32 noundef %35)
  %37 = add nsw i32 1, %36
  store i32 %37, ptr %8, align 4, !tbaa !5
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %32, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %39, ptr %40, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = call noundef i32 @_Z2dpii(i32 noundef %42, i32 noundef %44)
  %46 = add nsw i32 1, %45
  store i32 %46, ptr %9, align 4, !tbaa !5
  %47 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %41, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %48, ptr %49, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %50 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %50, ptr %10, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %69, %30
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %72

56:                                               ; preds = %51
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = call noundef i32 @_Z2dpii(i32 noundef %58, i32 noundef %59)
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = call noundef i32 @_Z2dpii(i32 noundef %62, i32 noundef %63)
  %65 = add nsw i32 %60, %64
  store i32 %65, ptr %11, align 4, !tbaa !5
  %66 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %57, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %67, ptr %68, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %69

69:                                               ; preds = %56
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %10, align 4, !tbaa !5
  br label %51, !llvm.loop !11

72:                                               ; preds = %55
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [105 x [105 x i32]], ptr @folds, i64 0, i64 %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [105 x i32], ptr %75, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = icmp sgt i32 %79, 1
  br i1 %80, label %81, label %114

81:                                               ; preds = %72
  %82 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [105 x [105 x i32]], ptr @folds, i64 0, i64 %84
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [105 x i32], ptr %85, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = call noundef i32 @_Z4gnumi(i32 noundef %89)
  %91 = add nsw i32 %90, 1
  %92 = load i32, ptr %4, align 4, !tbaa !5
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = sub nsw i32 %94, %95
  %97 = add nsw i32 %96, 1
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [105 x [105 x i32]], ptr @folds, i64 0, i64 %99
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [105 x i32], ptr %100, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = sdiv i32 %97, %104
  %106 = add nsw i32 %93, %105
  %107 = sub nsw i32 %106, 1
  %108 = call noundef i32 @_Z2dpii(i32 noundef %92, i32 noundef %107)
  %109 = add nsw i32 %91, %108
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %12, align 4, !tbaa !5
  %111 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %82, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %112, ptr %113, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %114

114:                                              ; preds = %81, %72
  %115 = load ptr, ptr %6, align 8, !tbaa !9
  %116 = load i32, ptr %115, align 4, !tbaa !5
  store i32 %116, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %117

117:                                              ; preds = %114, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %118

118:                                              ; preds = %117, %16
  %119 = load i32, ptr %3, align 4
  ret i32 %119
}

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

; 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)) #3

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

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

@calced = external dso_local global [105 x [105 x i32]], align 16
@folds = external dso_local local_unnamed_addr global [105 x [105 x i32]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = icmp eq i32 %0, %1
  br i1 %7, label %47, label %8

8:                                                ; preds = %2
  %9 = sext i32 %0 to i64
  %10 = sext i32 %1 to i64
  %11 = getelementptr inbounds [105 x [105 x i32]], ptr @calced, i64 0, i64 %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not = icmp eq i32 %12, -1
  br i1 %.not, label %13, label %47

13:                                               ; preds = %8
  store i32 1073741823, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %14 = add nsw i32 %0, 1
  %15 = tail call noundef i32 @_Z2dpii(i32 noundef %14, i32 noundef %1)
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %3, align 4, !tbaa !5
  %17 = 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) %3)
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %19 = add nsw i32 %1, -1
  %20 = call noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %19)
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %4, align 4, !tbaa !5
  %22 = 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) %4)
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  %24 = icmp slt i32 %0, %1
  br i1 %24, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %13
  %25 = phi i32 [ %23, %13 ], [ %34, %.lr.ph ]
  %26 = getelementptr inbounds [105 x [105 x i32]], ptr @folds, i64 0, i64 %9, i64 %10
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 1
  br i1 %28, label %35, label %47

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.042 = phi i32 [ %30, %.lr.ph ], [ %0, %13 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %29 = call noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %.042)
  %30 = add i32 %.042, 1
  %31 = call noundef i32 @_Z2dpii(i32 noundef %30, i32 noundef %1)
  %32 = add nsw i32 %31, %29
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = 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) %5)
  %34 = load i32, ptr %33, align 4, !tbaa !5
  store i32 %34, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %exitcond.not = icmp eq i32 %30, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

35:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %36 = call noundef i32 @_Z4gnumi(i32 noundef %27)
  %reass.sub = sub i32 %1, %0
  %37 = add i32 %reass.sub, 1
  %38 = load i32, ptr %26, align 4, !tbaa !5
  %39 = sdiv i32 %37, %38
  %40 = add i32 %0, -1
  %41 = add i32 %40, %39
  %42 = call noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %41)
  %43 = add i32 %36, 2
  %44 = add i32 %43, %42
  store i32 %44, ptr %6, align 4, !tbaa !5
  %45 = 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) %6)
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %47

47:                                               ; preds = %._crit_edge, %35, %8, %2
  %.1 = phi i32 [ 1, %2 ], [ %12, %8 ], [ %46, %35 ], [ %25, %._crit_edge ]
  ret i32 %.1
}

; 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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