; LLVM IR from tangjz/acm-icpc :: hdu/5709.ll (Z7col_mixRiS_iii)

; 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
@tot = external dso_local global i32, align 4
@lch = external dso_local global [10200103 x i32], align 16
@rch = external dso_local global [10200103 x i32], align 16
@val = external dso_local global [10200103 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef, i32 noundef, i32 noundef) #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 uwtable
define dso_local void @_Z7col_mixRiS_iii(ptr noundef nonnull align 4 dereferenceable(4) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %17, %5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = add nsw i32 %22, %23
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %24, ptr %25, align 4, !tbaa !9
  br label %104

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %11, align 4, !tbaa !9
  %29 = load i32, ptr @tot, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @tot, align 4, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %30, ptr %31, align 4, !tbaa !9
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %38
  store i32 %35, ptr %39, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %46
  store i32 %43, ptr %47, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = icmp eq i32 %48, %49
  br i1 %50, label %51, label %74

51:                                               ; preds = %26
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %53
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %56
  %58 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %54, ptr noundef nonnull align 4 dereferenceable(4) %57)
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %62
  store i32 %59, ptr %63, align 4, !tbaa !9
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i32, ptr @n, align 4, !tbaa !9
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %67
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %70
  %72 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %68, ptr noundef nonnull align 4 dereferenceable(4) %71)
  %73 = load i32, ptr %72, align 4, !tbaa !9
  call void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %64, i32 noundef 1, i32 noundef %65, i32 noundef %73, i32 noundef -1)
  store i32 1, ptr %12, align 4
  br label %102

74:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = add nsw i32 %75, %76
  %78 = ashr i32 %77, 1
  store i32 %78, ptr %13, align 4, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %80, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %82
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = load i32, ptr %13, align 4, !tbaa !9
  call void @_Z7col_mixRiS_iii(ptr noundef nonnull align 4 dereferenceable(4) %79, ptr noundef nonnull align 4 dereferenceable(4) %83, i32 noundef %87, i32 noundef %88, i32 noundef %89)
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %93
  %95 = load i32, ptr %8, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !9
  %99 = load i32, ptr %13, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  %101 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z7col_mixRiS_iii(ptr noundef nonnull align 4 dereferenceable(4) %90, ptr noundef nonnull align 4 dereferenceable(4) %94, i32 noundef %98, i32 noundef %100, i32 noundef %101)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  store i32 0, ptr %12, align 4
  br label %102

102:                                              ; preds = %74, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %103 = load i32, ptr %12, align 4
  switch i32 %103, label %105 [
    i32 0, label %104
    i32 1, label %104
  ]

104:                                              ; preds = %102, %102, %20
  ret void

105:                                              ; preds = %102
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; 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
@tot = external dso_local local_unnamed_addr global i32, align 4
@lch = external dso_local global [10200103 x i32], align 16
@rch = external dso_local local_unnamed_addr global [10200103 x i32], align 16
@val = external dso_local global [10200103 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7col_mixRiS_iii(ptr noundef nonnull align 4 dereferenceable(4) %0, ptr nocapture noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  %8 = icmp ne i32 %2, 0
  %or.cond42 = and i1 %8, %7
  br i1 %or.cond42, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr34.lcssa = phi ptr [ %1, %5 ], [ %46, %tailrecurse ]
  %.tr35.lcssa = phi i32 [ %2, %5 ], [ %48, %tailrecurse ]
  %.lcssa = phi i32 [ %6, %5 ], [ %50, %tailrecurse ]
  %9 = add nsw i32 %.lcssa, %.tr35.lcssa
  store i32 %9, ptr %.tr34.lcssa, align 4, !tbaa !5
  br label %53

.lr.ph:                                           ; preds = %5, %tailrecurse
  %10 = phi i32 [ %50, %tailrecurse ], [ %6, %5 ]
  %.tr3645 = phi i32 [ %49, %tailrecurse ], [ %3, %5 ]
  %.tr3544 = phi i32 [ %48, %tailrecurse ], [ %2, %5 ]
  %.tr3443 = phi ptr [ %46, %tailrecurse ], [ %1, %5 ]
  %11 = load i32, ptr @tot, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @tot, align 4, !tbaa !5
  store i32 %12, ptr %.tr3443, align 4, !tbaa !5
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %12 to i64
  %17 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %16
  store i32 %15, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %13
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr %.tr3443, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %21
  store i32 %19, ptr %22, align 4, !tbaa !5
  %23 = icmp eq i32 %.tr3645, %4
  br i1 %23, label %24, label %tailrecurse

24:                                               ; preds = %.lr.ph
  %25 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %13
  %26 = sext i32 %.tr3544 to i64
  %27 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %26
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %25, ptr noundef nonnull align 4 dereferenceable(4) %27)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %.tr3443, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %25, ptr noundef nonnull align 4 dereferenceable(4) %27)
  %35 = load i32, ptr %34, align 4, !tbaa !5
  tail call void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef 1, i32 noundef %33, i32 noundef %35, i32 noundef -1)
  br label %53

tailrecurse:                                      ; preds = %.lr.ph
  %36 = add nsw i32 %.tr3645, %4
  %37 = ashr i32 %36, 1
  %38 = load i32, ptr %.tr3443, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %39
  %41 = sext i32 %.tr3544 to i64
  %42 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  tail call void @_Z7col_mixRiS_iii(ptr noundef nonnull align 4 dereferenceable(4) %0, ptr noundef nonnull align 4 dereferenceable(4) %40, i32 noundef %43, i32 noundef %.tr3645, i32 noundef %37)
  %44 = load i32, ptr %.tr3443, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %45
  %47 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %41
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %37, 1
  %50 = load i32, ptr %46, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  %52 = icmp ne i32 %48, 0
  %or.cond = and i1 %52, %51
  br i1 %or.cond, label %.lr.ph, label %tailrecurse._crit_edge

53:                                               ; preds = %24, %tailrecurse._crit_edge
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { 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 #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"}


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