; LLVM IR from tangjz/acm-icpc :: usaco/Training/Chapter 1 Getting started/transfrom.ll (Z10transform1v)

; 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
@init = external dso_local global [11 x [11 x i8]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5matchv() #0

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z10transform1v() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [11 x [11 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 121, ptr %3) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %31, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %34

8:                                                ; preds = %4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %27, %8
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %30

13:                                               ; preds = %9
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [11 x [11 x i8]], ptr @init, i64 0, i64 %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [11 x i8], ptr %16, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [11 x [11 x i8]], ptr %3, i64 0, i64 %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [11 x i8], ptr %23, i64 0, i64 %25
  store i8 %20, ptr %26, align 1, !tbaa !9
  br label %27

27:                                               ; preds = %13
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !10

30:                                               ; preds = %9
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !12

34:                                               ; preds = %4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %65, %34
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %68

39:                                               ; preds = %35
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %61, %39
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %64

44:                                               ; preds = %40
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sub nsw i32 %45, %46
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [11 x [11 x i8]], ptr %3, i64 0, i64 %49
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [11 x i8], ptr %50, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [11 x [11 x i8]], ptr @init, i64 0, i64 %56
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [11 x i8], ptr %57, i64 0, i64 %59
  store i8 %54, ptr %60, align 1, !tbaa !9
  br label %61

61:                                               ; preds = %44
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %40, !llvm.loop !13

64:                                               ; preds = %40
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %1, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %1, align 4, !tbaa !5
  br label %35, !llvm.loop !14

68:                                               ; preds = %35
  %69 = call noundef zeroext i1 @_Z5matchv()
  call void @llvm.lifetime.end.p0(i64 121, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i1 %69
}

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"

@n = external dso_local local_unnamed_addr global i32, align 4
@init = external dso_local local_unnamed_addr global [11 x [11 x i8]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5matchv() local_unnamed_addr #0

; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z10transform1v() local_unnamed_addr #0 {
  %1 = alloca [11 x [11 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 121, ptr nonnull %1) #3
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader20.us.preheader, label %._crit_edge25

.preheader20.us.preheader:                        ; preds = %0
  %4 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %4, 3
  %5 = icmp ult i32 %2, 4
  br i1 %5, label %.preheader19.unr-lcssa, label %.preheader20.us.preheader.new

.preheader20.us.preheader.new:                    ; preds = %.preheader20.us.preheader
  %unroll_iter = and i64 %4, 2147483644
  br label %.preheader20.us

.preheader20.us:                                  ; preds = %.preheader20.us, %.preheader20.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader20.us.preheader.new ], [ %indvar.next.3, %.preheader20.us ]
  %niter = phi i64 [ 0, %.preheader20.us.preheader.new ], [ %niter.next.3, %.preheader20.us ]
  %6 = mul nuw nsw i64 %indvar, 11
  %scevgep = getelementptr i8, ptr %1, i64 %6
  %scevgep27 = getelementptr i8, ptr @init, i64 %6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %scevgep, ptr align 4 %scevgep27, i64 %4, i1 false), !tbaa !9
  %7 = mul nuw i64 %indvar, 11
  %8 = add nuw i64 %7, 11
  %scevgep.1 = getelementptr i8, ptr %1, i64 %8
  %scevgep27.1 = getelementptr i8, ptr @init, i64 %8
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %scevgep.1, ptr align 1 %scevgep27.1, i64 %4, i1 false), !tbaa !9
  %9 = mul nuw i64 %indvar, 11
  %10 = add nuw i64 %9, 22
  %scevgep.2 = getelementptr i8, ptr %1, i64 %10
  %scevgep27.2 = getelementptr i8, ptr @init, i64 %10
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %scevgep.2, ptr align 2 %scevgep27.2, i64 %4, i1 false), !tbaa !9
  %11 = mul nuw i64 %indvar, 11
  %12 = add nuw i64 %11, 33
  %scevgep.3 = getelementptr i8, ptr %1, i64 %12
  %scevgep27.3 = getelementptr i8, ptr @init, i64 %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %scevgep.3, ptr align 1 %scevgep27.3, i64 %4, i1 false), !tbaa !9
  %indvar.next.3 = add nuw nsw i64 %indvar, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader19.unr-lcssa, label %.preheader20.us, !llvm.loop !10

.preheader19.unr-lcssa:                           ; preds = %.preheader20.us, %.preheader20.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader20.us.preheader ], [ %indvar.next.3, %.preheader20.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader19, label %.preheader20.us.epil

.preheader20.us.epil:                             ; preds = %.preheader19.unr-lcssa, %.preheader20.us.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader20.us.epil ], [ %indvar.unr, %.preheader19.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader20.us.epil ], [ 0, %.preheader19.unr-lcssa ]
  %13 = mul nuw nsw i64 %indvar.epil, 11
  %scevgep.epil = getelementptr i8, ptr %1, i64 %13
  %scevgep27.epil = getelementptr i8, ptr @init, i64 %13
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %scevgep.epil, ptr align 1 %scevgep27.epil, i64 %4, i1 false), !tbaa !9
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader19, label %.preheader20.us.epil, !llvm.loop !12

.preheader19:                                     ; preds = %.preheader20.us.epil, %.preheader19.unr-lcssa
  br i1 %3, label %.preheader.us.preheader, label %._crit_edge25

.preheader.us.preheader:                          ; preds = %.preheader19
  %14 = zext nneg i32 %2 to i64
  %wide.trip.count36 = zext nneg i32 %2 to i64
  %xtraiter38 = and i64 %4, 1
  %15 = icmp eq i32 %2, 1
  %unroll_iter41 = and i64 %4, 2147483646
  %lcmp.mod40.not = icmp eq i64 %xtraiter38, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us26
  %indvars.iv33 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next34, %._crit_edge.us26 ]
  br i1 %15, label %._crit_edge.us26.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter42 = phi i64 [ %niter42.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %16 = xor i64 %indvars.iv, -1
  %17 = add nsw i64 %14, %16
  %18 = getelementptr inbounds [11 x [11 x i8]], ptr %1, i64 0, i64 %17, i64 %indvars.iv33
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = getelementptr inbounds [11 x [11 x i8]], ptr @init, i64 0, i64 %indvars.iv33, i64 %indvars.iv
  store i8 %19, ptr %20, align 1, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = xor i64 %indvars.iv, -2
  %22 = add nsw i64 %21, %14
  %23 = getelementptr inbounds [11 x [11 x i8]], ptr %1, i64 0, i64 %22, i64 %indvars.iv33
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = getelementptr inbounds [11 x [11 x i8]], ptr @init, i64 0, i64 %indvars.iv33, i64 %indvars.iv.next
  store i8 %24, ptr %25, align 1, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter42.next.1 = add i64 %niter42, 2
  %niter42.ncmp.1 = icmp eq i64 %niter42.next.1, %unroll_iter41
  br i1 %niter42.ncmp.1, label %._crit_edge.us26.unr-lcssa, label %.preheader.us.new, !llvm.loop !14

._crit_edge.us26.unr-lcssa:                       ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %.preheader.us.new ]
  br i1 %lcmp.mod40.not, label %._crit_edge.us26, label %._crit_edge.us26.epilog-lcssa

._crit_edge.us26.epilog-lcssa:                    ; preds = %._crit_edge.us26.unr-lcssa
  %26 = xor i64 %indvars.iv.unr, -1
  %27 = add nsw i64 %14, %26
  %28 = getelementptr inbounds [11 x [11 x i8]], ptr %1, i64 0, i64 %27, i64 %indvars.iv33
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = getelementptr inbounds [11 x [11 x i8]], ptr @init, i64 0, i64 %indvars.iv33, i64 %indvars.iv.unr
  store i8 %29, ptr %30, align 1, !tbaa !9
  br label %._crit_edge.us26

._crit_edge.us26:                                 ; preds = %._crit_edge.us26.unr-lcssa, %._crit_edge.us26.epilog-lcssa
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge25, label %.preheader.us, !llvm.loop !15

._crit_edge25:                                    ; preds = %._crit_edge.us26, %0, %.preheader19
  %31 = tail call noundef zeroext i1 @_Z5matchv()
  call void @llvm.lifetime.end.p0(i64 121, ptr nonnull %1) #3
  ret i1 %31
}

; 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) #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}


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