; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/319 Division 1/Problem D/D.ll (Z7update2i)

; 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
@dp = external dso_local global [32 x [200 x [200 x i32]]], align 16
@ok = external dso_local global [200 x i32], align 16

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

9:                                                ; preds = %82, %1
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 31
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %85

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = shl i32 1, %15
  %17 = and i32 %14, %16
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %81

19:                                               ; preds = %13
  %20 = getelementptr inbounds [200 x i32], ptr %3, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %20, i8 0, i64 800, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %60, %19
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %63

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %55, %26
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 8, ptr %5, align 4
  br label %58

32:                                               ; preds = %27
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200 x i32], ptr @ok, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %54

38:                                               ; preds = %32
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [32 x [200 x [200 x i32]]], ptr @dp, i64 0, i64 %40
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200 x [200 x i32]], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %38
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [200 x i32], ptr %3, i64 0, i64 %52
  store i32 1, ptr %53, align 4, !tbaa !5
  store i32 8, ptr %5, align 4
  br label %58

54:                                               ; preds = %38, %32
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %7, align 4, !tbaa !5
  br label %27, !llvm.loop !9

58:                                               ; preds = %50, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !5
  br label %21, !llvm.loop !11

63:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %77, %63
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = load i32, ptr @n, align 4, !tbaa !5
  %67 = icmp sle i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %80

69:                                               ; preds = %64
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [200 x i32], ptr %3, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [200 x i32], ptr @ok, i64 0, i64 %75
  store i32 %73, ptr %76, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %69
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %8, align 4, !tbaa !5
  br label %64, !llvm.loop !12

80:                                               ; preds = %68
  br label %81

81:                                               ; preds = %80, %13
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %4, align 4, !tbaa !5
  br label %9, !llvm.loop !13

85:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 800, ptr %3) #3
  ret void
}

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; 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
@dp = external dso_local local_unnamed_addr global [32 x [200 x [200 x i32]]], align 16
@ok = external dso_local local_unnamed_addr global [200 x i32], align 16

; 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 nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7update2i(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [200 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %2) #4
  %3 = load i32, ptr @n, align 4
  %.fr = freeze i32 %3
  %.not2030 = icmp slt i32 %.fr, 1
  br i1 %.not2030, label %.split38.us, label %.split.split.preheader

.split.split.preheader:                           ; preds = %1
  %4 = add nuw i32 %.fr, 1
  %scevgep = getelementptr inbounds i8, ptr %2, i64 4
  %5 = zext nneg i32 %.fr to i64
  %6 = shl nuw nsw i64 %5, 2
  %wide.trip.count50 = zext i32 %4 to i64
  br label %.split.split

.split38.us:                                      ; preds = %..loopexit26_crit_edge, %1
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %2) #4
  ret void

.split.split:                                     ; preds = %.split.split.preheader, %..loopexit26_crit_edge
  %indvars.iv55 = phi i64 [ 0, %.split.split.preheader ], [ %indvars.iv.next56, %..loopexit26_crit_edge ]
  %7 = trunc nuw nsw i64 %indvars.iv55 to i32
  %8 = shl nuw nsw i32 1, %7
  %9 = and i32 %8, %0
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %..loopexit26_crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %.split.split
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800) %2, i8 0, i64 800, i1 false)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %..loopexit_crit_edge
  %indvars.iv47 = phi i64 [ 1, %.preheader.lr.ph ], [ %indvars.iv.next48, %..loopexit_crit_edge ]
  br label %10

10:                                               ; preds = %.preheader, %18
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %18 ]
  %11 = getelementptr inbounds [200 x i32], ptr @ok, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not23 = icmp eq i32 %12, 0
  br i1 %.not23, label %18, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds [32 x [200 x [200 x i32]]], ptr @dp, i64 0, i64 %indvars.iv55, i64 %indvars.iv, i64 %indvars.iv47
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not24 = icmp eq i32 %15, 0
  br i1 %.not24, label %18, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds [200 x i32], ptr %2, i64 0, i64 %indvars.iv47
  store i32 1, ptr %17, align 4, !tbaa !5
  br label %..loopexit_crit_edge

18:                                               ; preds = %10, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count50
  br i1 %exitcond.not, label %..loopexit_crit_edge, label %10, !llvm.loop !9

..loopexit_crit_edge:                             ; preds = %18, %16
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count50
  br i1 %exitcond51.not, label %..preheader25_crit_edge.split.preheader, label %.preheader, !llvm.loop !11

..preheader25_crit_edge.split.preheader:          ; preds = %..loopexit_crit_edge
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @ok, i64 4), ptr nonnull align 4 %scevgep, i64 %6, i1 false), !tbaa !5
  br label %..loopexit26_crit_edge

..loopexit26_crit_edge:                           ; preds = %..preheader25_crit_edge.split.preheader, %.split.split
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond58.not = icmp eq i64 %indvars.iv.next56, 31
  br i1 %exitcond58.not, label %.split38.us, label %.split.split, !llvm.loop !12
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass