; LLVM IR from DionysiosB/CodeForces :: 1100-1199/1151C-ProblemForNazar.ll (Z1fx)

; 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 nounwind uwtable
define dso_local noundef i32 @_Z1fx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca [2 x i64], align 16
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #2
  %7 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  store i64 0, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  store i64 0, ptr %8, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %39, %1
  %10 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %11 = load i64, ptr %10, align 16, !tbaa !5
  %12 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = add nsw i64 %11, %13
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %44

18:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %21 = load i64, ptr %20, align 16, !tbaa !5
  %22 = sub nsw i64 %19, %21
  %23 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = sub nsw i64 %22, %24
  store i64 %25, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %18
  %30 = load i64, ptr %6, align 8, !tbaa !5
  br label %33

31:                                               ; preds = %18
  %32 = load i64, ptr %4, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %29
  %34 = phi i64 [ %30, %29 ], [ %32, %31 ]
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = add nsw i64 %37, %34
  store i64 %38, ptr %36, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %39

39:                                               ; preds = %33
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = mul nsw i64 %40, 2
  store i64 %41, ptr %4, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = sub nsw i64 1, %42
  store i64 %43, ptr %5, align 8, !tbaa !5
  br label %9, !llvm.loop !9

44:                                               ; preds = %17
  %45 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %46 = load i64, ptr %45, align 16, !tbaa !5
  %47 = srem i64 %46, 1000000007
  store i64 %47, ptr %45, align 16, !tbaa !5
  %48 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = srem i64 %49, 1000000007
  store i64 %50, ptr %48, align 8, !tbaa !5
  %51 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %52 = load i64, ptr %51, align 16, !tbaa !5
  %53 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %54 = load i64, ptr %53, align 16, !tbaa !5
  %55 = mul nsw i64 %52, %54
  %56 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %59 = load i64, ptr %58, align 8, !tbaa !5
  %60 = mul nsw i64 %57, %59
  %61 = add nsw i64 %55, %60
  %62 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = add nsw i64 %61, %63
  %65 = srem i64 %64, 1000000007
  %66 = trunc i64 %65 to i32
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #2
  ret i32 %66
}

; 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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef range(i32 -1000000006, 1000000007) i32 @_Z1fx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca [2 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  %4 = icmp sgt i64 %0, 0
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %5 = srem i64 %21, 1000000007
  %6 = srem i64 %22, 1000000007
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.lcssa11 = phi i64 [ 0, %1 ], [ %5, %._crit_edge.loopexit ]
  %.lcssa = phi i64 [ 0, %1 ], [ %6, %._crit_edge.loopexit ]
  %7 = mul nsw i64 %.lcssa11, %.lcssa11
  %8 = mul nsw i64 %.lcssa, %.lcssa
  %9 = add nsw i64 %.lcssa, %7
  %10 = add nsw i64 %9, %8
  %11 = srem i64 %10, 1000000007
  %12 = trunc nsw i64 %11 to i32
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  ret i32 %12

.lr.ph:                                           ; preds = %1, %.lr.ph
  %13 = phi i64 [ %23, %.lr.ph ], [ 0, %1 ]
  %.013 = phi i64 [ %19, %.lr.ph ], [ 1, %1 ]
  %.0912 = phi i64 [ %20, %.lr.ph ], [ 0, %1 ]
  %14 = sub i64 %0, %13
  %15 = tail call i64 @llvm.smin.i64(i64 %14, i64 %.013)
  %16 = getelementptr inbounds [2 x i64], ptr %2, i64 0, i64 %.0912
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = add nsw i64 %17, %15
  store i64 %18, ptr %16, align 8, !tbaa !5
  %19 = shl nsw i64 %.013, 1
  %20 = sub nuw nsw i64 1, %.0912
  %21 = load i64, ptr %2, align 16, !tbaa !5
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = add nsw i64 %22, %21
  %24 = icmp slt i64 %23, %0
  br i1 %24, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9
}

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass