; LLVM IR from DionysiosB/CodeForces :: 0700-0799/770D-DrawBrackets.ll (Z3prtiiii)

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

@ans = external dso_local global [333 x [555 x i8]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prtiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %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
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %11 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %11, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %34, %4
  %13 = load i32, ptr %10, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %37

17:                                               ; preds = %12
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %21
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [555 x i8], ptr %22, i64 0, i64 %24
  store i8 124, ptr %25, align 1, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = sub nsw i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %29
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [555 x i8], ptr %30, i64 0, i64 %32
  store i8 124, ptr %33, align 1, !tbaa !9
  br label %34

34:                                               ; preds = %17
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %10, align 4, !tbaa !5
  br label %12, !llvm.loop !10

37:                                               ; preds = %16
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %41
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [555 x i8], ptr %42, i64 0, i64 %44
  store i8 43, ptr %45, align 1, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sub nsw i32 %46, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %49
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [555 x i8], ptr %50, i64 0, i64 %52
  store i8 43, ptr %53, align 1, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = add nsw i32 %54, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %57
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [555 x i8], ptr %58, i64 0, i64 %62
  store i8 45, ptr %63, align 1, !tbaa !9
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sub nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %67
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = add nsw i32 %69, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [555 x i8], ptr %68, i64 0, i64 %72
  store i8 45, ptr %73, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@ans = external dso_local local_unnamed_addr global [333 x [555 x i8]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3prtiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %1, 0
  %6 = sext i32 %3 to i64
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %7 = sext i32 %0 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %1, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %23

._crit_edge.loopexit.unr-lcssa:                   ; preds = %23, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %9 = add nsw i64 %indvars.iv.unr, %7
  %10 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %9, i64 %6
  store i8 124, ptr %10, align 1, !tbaa !5
  %11 = sub nsw i64 %7, %indvars.iv.unr
  %12 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %11, i64 %6
  store i8 124, ptr %12, align 1, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %4
  %13 = add nsw i32 %1, %0
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %14, i64 %6
  store i8 43, ptr %15, align 1, !tbaa !5
  %16 = sub nsw i32 %0, %1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %17, i64 %6
  store i8 43, ptr %18, align 1, !tbaa !5
  %19 = add nsw i32 %3, %2
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %14, i64 %20
  store i8 45, ptr %21, align 1, !tbaa !5
  %22 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %17, i64 %20
  store i8 45, ptr %22, align 1, !tbaa !5
  ret void

23:                                               ; preds = %23, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %23 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %23 ]
  %24 = add nsw i64 %indvars.iv, %7
  %25 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %24, i64 %6
  store i8 124, ptr %25, align 1, !tbaa !5
  %26 = sub nsw i64 %7, %indvars.iv
  %27 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %26, i64 %6
  store i8 124, ptr %27, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %28 = add nsw i64 %indvars.iv.next, %7
  %29 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %28, i64 %6
  store i8 124, ptr %29, align 1, !tbaa !5
  %30 = sub nsw i64 %7, %indvars.iv.next
  %31 = getelementptr inbounds [333 x [555 x i8]], ptr @ans, i64 0, i64 %30, i64 %6
  store i8 124, ptr %31, align 1, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %23, !llvm.loop !8
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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