; LLVM IR from tangjz/acm-icpc :: codeforces/complete/317E.ll (Z6appendv)

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

@dir = external dso_local global ptr, align 8
@_ZL2dx = external hidden constant [4 x i32], align 16
@_ZL2dy = external hidden constant [4 x i32], align 16
@sx = external dso_local global i32, align 4
@sy = external dso_local global i32, align 4
@tx = external dso_local global i32, align 4
@ty = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@adt = external dso_local global [41209 x i32], align 16
@buf = external dso_local global [1000001 x i8], 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 uwtable
define dso_local void @_Z6appendv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

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

8:                                                ; preds = %4
  store i32 2, ptr %2, align 4
  br label %89

9:                                                ; preds = %4
  %10 = load i32, ptr @sx, align 4, !tbaa !5
  %11 = load i32, ptr @tx, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %9
  %14 = load i32, ptr @sy, align 4, !tbaa !5
  %15 = load i32, ptr @ty, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  store i32 1, ptr %2, align 4
  br label %89

18:                                               ; preds = %13, %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [41209 x i32], ptr @adt, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @sx, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %23, %27
  %29 = load i32, ptr @sy, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add nsw i32 %29, %33
  %35 = call noundef zeroext i1 @_Z5checkii(i32 noundef %28, i32 noundef %34)
  br i1 %35, label %36, label %85

36:                                               ; preds = %18
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr @sx, align 4, !tbaa !5
  %42 = add nsw i32 %41, %40
  store i32 %42, ptr @sx, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr @sy, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr @sy, align 4, !tbaa !5
  %49 = load i32, ptr @tx, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %49, %53
  %55 = load i32, ptr @ty, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = add nsw i32 %55, %59
  %61 = call noundef zeroext i1 @_Z5checkii(i32 noundef %54, i32 noundef %60)
  br i1 %61, label %62, label %75

62:                                               ; preds = %36
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr @tx, align 4, !tbaa !5
  %68 = add nsw i32 %67, %66
  store i32 %68, ptr @tx, align 4, !tbaa !5
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = load i32, ptr @ty, align 4, !tbaa !5
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr @ty, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %62, %36
  %76 = load ptr, ptr @dir, align 8, !tbaa !9
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i8, ptr %76, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !11
  %81 = load i32, ptr @n, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr @n, align 4, !tbaa !5
  %83 = sext i32 %81 to i64
  %84 = getelementptr inbounds [1000001 x i8], ptr @buf, i64 0, i64 %83
  store i8 %80, ptr %84, align 1, !tbaa !11
  br label %85

85:                                               ; preds = %75, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %1, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !12

89:                                               ; preds = %17, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  %90 = load i32, ptr %2, align 4
  switch i32 %90, label %92 [
    i32 2, label %91
    i32 1, label %91
  ]

91:                                               ; preds = %89, %89
  ret void

92:                                               ; preds = %89
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkii(i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint 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 #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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@dir = external dso_local local_unnamed_addr global ptr, align 8
@_ZL2dx = external hidden local_unnamed_addr constant [4 x i32], align 16
@_ZL2dy = external hidden local_unnamed_addr constant [4 x i32], align 16
@sx = external dso_local local_unnamed_addr global i32, align 4
@sy = external dso_local local_unnamed_addr global i32, align 4
@tx = external dso_local local_unnamed_addr global i32, align 4
@ty = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@adt = external dso_local local_unnamed_addr global [41209 x i32], align 16
@buf = external dso_local local_unnamed_addr global [1000001 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6appendv() local_unnamed_addr #0 {
  %1 = load i32, ptr @m, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %42
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ 0, %0 ]
  %3 = load i32, ptr @sx, align 4, !tbaa !5
  %4 = load i32, ptr @tx, align 4, !tbaa !5
  %5 = icmp eq i32 %3, %4
  %.pre = load i32, ptr @sy, align 4, !tbaa !5
  %6 = load i32, ptr @ty, align 4
  %7 = icmp eq i32 %.pre, %6
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %._crit_edge, label %8

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds [41209 x i32], ptr @adt, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, %3
  %15 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %11
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, %.pre
  %18 = tail call noundef zeroext i1 @_Z5checkii(i32 noundef %14, i32 noundef %17)
  br i1 %18, label %19, label %42

19:                                               ; preds = %8
  %20 = load i32, ptr @sx, align 4, !tbaa !5
  %21 = add nsw i32 %20, %13
  store i32 %21, ptr @sx, align 4, !tbaa !5
  %22 = load i32, ptr @sy, align 4, !tbaa !5
  %23 = add nsw i32 %22, %16
  store i32 %23, ptr @sy, align 4, !tbaa !5
  %24 = load i32, ptr @tx, align 4, !tbaa !5
  %25 = add nsw i32 %24, %13
  %26 = load i32, ptr @ty, align 4, !tbaa !5
  %27 = add nsw i32 %26, %16
  %28 = tail call noundef zeroext i1 @_Z5checkii(i32 noundef %25, i32 noundef %27)
  br i1 %28, label %29, label %34

29:                                               ; preds = %19
  %30 = load i32, ptr @tx, align 4, !tbaa !5
  %31 = add nsw i32 %30, %13
  store i32 %31, ptr @tx, align 4, !tbaa !5
  %32 = load i32, ptr @ty, align 4, !tbaa !5
  %33 = add nsw i32 %32, %16
  store i32 %33, ptr @ty, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %29, %19
  %35 = load ptr, ptr @dir, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %35, i64 %11
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @n, align 4, !tbaa !5
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds [1000001 x i8], ptr @buf, i64 0, i64 %40
  store i8 %37, ptr %41, align 1, !tbaa !11
  br label %42

42:                                               ; preds = %34, %8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load i32, ptr @m, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next, %44
  br i1 %45, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %42, %.lr.ph, %0
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkii(i32 noundef, i32 noundef) local_unnamed_addr #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 = { inlinehint 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" }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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