; LLVM IR from MinaFaried3/Assiut-University-Training---Newcomers :: l-sheet9_general_medium/K-StarsDrawingEasyEdition.ll (Z6changeiii)

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

@visit = external dso_local global [1000 x [1000 x i8]], align 16

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

15:                                               ; preds = %19, %3
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %19, label %28

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %21
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000 x i8], ptr %22, i64 0, i64 %24
  store i8 49, ptr %25, align 1, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %8, align 4, !tbaa !5
  br label %15, !llvm.loop !10

28:                                               ; preds = %15
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sub nsw i32 %29, %30
  store i32 %31, ptr %7, align 4, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %32, ptr %8, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %37, %28
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = icmp sge i32 %34, %35
  br i1 %36, label %37, label %46

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %39
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000 x i8], ptr %40, i64 0, i64 %42
  store i8 49, ptr %43, align 1, !tbaa !9
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %33, !llvm.loop !12

46:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  store i32 %49, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %50 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %50, ptr %10, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %55, %46
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %55, label %64

55:                                               ; preds = %51
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000 x i8], ptr %58, i64 0, i64 %60
  store i8 49, ptr %61, align 1, !tbaa !9
  %62 = load i32, ptr %10, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !5
  br label %51, !llvm.loop !13

64:                                               ; preds = %51
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = sub nsw i32 %65, %66
  store i32 %67, ptr %9, align 4, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %68, ptr %10, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %73, %64
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = icmp sge i32 %70, %71
  br i1 %72, label %73, label %82

73:                                               ; preds = %69
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %75
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1000 x i8], ptr %76, i64 0, i64 %78
  store i8 49, ptr %79, align 1, !tbaa !9
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %10, align 4, !tbaa !5
  br label %69, !llvm.loop !14

82:                                               ; preds = %69
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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

@visit = external dso_local local_unnamed_addr global [1000 x [1000 x i8]], align 16

; Function Attrs: mustprogress nofree norecurse noreturn nosync nounwind memory(write, argmem: none) uwtable
define dso_local noundef i32 @_Z6changeiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not36 = icmp slt i32 %2, 0
  %.pre56 = sext i32 %0 to i64
  br i1 %.not36, label %._crit_edge42.._crit_edge47_crit_edge, label %.lr.ph46

._crit_edge42.._crit_edge47_crit_edge:            ; preds = %3
  %.pre = sext i32 %1 to i64
  br label %._crit_edge47

.lr.ph46:                                         ; preds = %3
  %4 = add i32 %2, %1
  %5 = mul nsw i64 %.pre56, 1000
  %6 = sext i32 %1 to i64
  %7 = getelementptr i8, ptr @visit, i64 %5
  %scevgep = getelementptr i8, ptr %7, i64 %6
  %smax = tail call i32 @llvm.smax.i32(i32 %1, i32 %4)
  %8 = sub i32 %smax, %1
  %9 = zext i32 %8 to i64
  %10 = add nuw nsw i64 %9, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 49, i64 %10, i1 false), !tbaa !5
  %11 = sub i32 %1, %2
  %12 = sext i32 %0 to i64
  %13 = mul nsw i64 %12, 1000
  %14 = sext i32 %1 to i64
  %15 = add nsw i64 %13, %14
  %smin = tail call i32 @llvm.smin.i32(i32 %1, i32 %11)
  %16 = sub i32 %1, %smin
  %17 = zext i32 %16 to i64
  %18 = sub nsw i64 %15, %17
  %scevgep49 = getelementptr i8, ptr @visit, i64 %18
  %19 = add nuw nsw i64 %17, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep49, i8 49, i64 %19, i1 false), !tbaa !5
  %20 = add i32 %2, %0
  %21 = sext i32 %1 to i64
  %22 = sext i32 %0 to i64
  %smax52 = tail call i32 @llvm.smax.i32(i32 %0, i32 %20)
  %23 = add i32 %smax52, 1
  %24 = sub i32 %23, %0
  %25 = sub i32 %smax52, %0
  %xtraiter = and i32 %24, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph46, %.prol.preheader
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.prol.preheader ], [ %22, %.lr.ph46 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph46 ]
  %26 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %indvars.iv.prol, i64 %21
  store i8 49, ptr %26, align 1, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !8

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph46
  %indvars.iv.unr = phi i64 [ %22, %.lr.ph46 ], [ %indvars.iv.next.prol, %.prol.preheader ]
  %27 = icmp ult i32 %25, 3
  br i1 %27, label %._crit_edge47, label %.lr.ph46.new

.lr.ph46.new:                                     ; preds = %.prol.loopexit, %.lr.ph46.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph46.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %28 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %indvars.iv, i64 %21
  store i8 49, ptr %28, align 1, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %29 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %indvars.iv.next, i64 %21
  store i8 49, ptr %29, align 1, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %30 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %indvars.iv.next.1, i64 %21
  store i8 49, ptr %30, align 1, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %31 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %indvars.iv.next.2, i64 %21
  store i8 49, ptr %31, align 1, !tbaa !5
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %lftr.wideiv.3 = trunc i64 %indvars.iv.next.3 to i32
  %exitcond.not.3 = icmp eq i32 %23, %lftr.wideiv.3
  br i1 %exitcond.not.3, label %._crit_edge47, label %.lr.ph46.new, !llvm.loop !10

._crit_edge47:                                    ; preds = %.prol.loopexit, %.lr.ph46.new, %._crit_edge42.._crit_edge47_crit_edge
  %.pre-phi57 = phi i64 [ %.pre56, %._crit_edge42.._crit_edge47_crit_edge ], [ %22, %.lr.ph46.new ], [ %22, %.prol.loopexit ]
  %.pre-phi = phi i64 [ %.pre, %._crit_edge42.._crit_edge47_crit_edge ], [ %21, %.lr.ph46.new ], [ %21, %.prol.loopexit ]
  %32 = sub nsw i32 %0, %2
  %33 = sext i32 %32 to i64
  br label %34

34:                                               ; preds = %34, %._crit_edge47
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %34 ], [ %.pre-phi57, %._crit_edge47 ]
  %35 = icmp sge i64 %indvars.iv53, %33
  tail call void @llvm.assume(i1 %35)
  %36 = getelementptr inbounds [1000 x [1000 x i8]], ptr @visit, i64 0, i64 %indvars.iv53, i64 %.pre-phi
  store i8 49, ptr %36, align 1, !tbaa !5
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, -1
  br label %34, !llvm.loop !12
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { mustprogress nofree norecurse noreturn nosync nounwind memory(write, argmem: 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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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.unroll.disable"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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