; LLVM IR from tangjz/acm-icpc :: codeforces/gym/100827I.ll (Z6updateiiiii)

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

%struct.Segment = type { i32, i32, i32 }

@seg = external dso_local global [2000002 x %struct.Segment], 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z7push_upR7SegmentS_S_(ptr noundef nonnull align 4 dereferenceable(12), i64, i32, i64, i32) #2

; 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) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #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
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca %struct.Segment, align 4
  %17 = alloca %struct.Segment, align 4
  %18 = alloca { i64, i32 }, align 4
  %19 = alloca { i64, i32 }, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = call noundef i32 @_Z7seg_idxii(i32 noundef %20, i32 noundef %21)
  store i32 %22, ptr %11, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %52

26:                                               ; preds = %5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %30, label %52

30:                                               ; preds = %26
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Segment, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = add nsw i32 %36, %31
  store i32 %37, ptr %35, align 4, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Segment, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = add nsw i32 %43, %38
  store i32 %44, ptr %42, align 4, !tbaa !11
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Segment, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = add nsw i32 %50, %45
  store i32 %51, ptr %49, align 4, !tbaa !12
  store i32 1, ptr %12, align 4
  br label %111

52:                                               ; preds = %26, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = add nsw i32 %53, %54
  %56 = ashr i32 %55, 1
  store i32 %56, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = load i32, ptr %13, align 4, !tbaa !5
  %59 = call noundef i32 @_Z7seg_idxii(i32 noundef %57, i32 noundef %58)
  store i32 %59, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %60 = load i32, ptr %13, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = call noundef i32 @_Z7seg_idxii(i32 noundef %61, i32 noundef %62)
  store i32 %63, ptr %15, align 4, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %65
  %67 = load i32, ptr %14, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %68
  %70 = load i32, ptr %15, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %71
  call void @_Z9push_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(12) %66, ptr noundef nonnull align 4 dereferenceable(12) %69, ptr noundef nonnull align 4 dereferenceable(12) %72)
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr %13, align 4, !tbaa !5
  %75 = icmp sle i32 %73, %74
  br i1 %75, label %76, label %82

76:                                               ; preds = %52
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %13, align 4, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6updateiiiii(i32 noundef %77, i32 noundef %78, i32 noundef %79, i32 noundef %80, i32 noundef %81)
  br label %82

82:                                               ; preds = %76, %52
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = load i32, ptr %13, align 4, !tbaa !5
  %85 = icmp sgt i32 %83, %84
  br i1 %85, label %86, label %93

86:                                               ; preds = %82
  %87 = load i32, ptr %13, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = load i32, ptr %8, align 4, !tbaa !5
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6updateiiiii(i32 noundef %88, i32 noundef %89, i32 noundef %90, i32 noundef %91, i32 noundef %92)
  br label %93

93:                                               ; preds = %86, %82
  %94 = load i32, ptr %11, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %95
  %97 = load i32, ptr %14, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %98
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %99, i64 12, i1 false), !tbaa.struct !13
  %100 = load i32, ptr %15, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %101
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %102, i64 12, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %16, i64 12, i1 false)
  %103 = getelementptr inbounds { i64, i32 }, ptr %18, i32 0, i32 0
  %104 = load i64, ptr %103, align 4
  %105 = getelementptr inbounds { i64, i32 }, ptr %18, i32 0, i32 1
  %106 = load i32, ptr %105, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 %17, i64 12, i1 false)
  %107 = getelementptr inbounds { i64, i32 }, ptr %19, i32 0, i32 0
  %108 = load i64, ptr %107, align 4
  %109 = getelementptr inbounds { i64, i32 }, ptr %19, i32 0, i32 1
  %110 = load i32, ptr %109, align 4
  call void @_Z7push_upR7SegmentS_S_(ptr noundef nonnull align 4 dereferenceable(12) %96, i64 %104, i32 %106, i64 %108, i32 %110)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  store i32 0, ptr %12, align 4
  br label %111

111:                                              ; preds = %93, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %112 = load i32, ptr %12, align 4
  switch i32 %112, label %114 [
    i32 0, label %113
    i32 1, label %113
  ]

113:                                              ; preds = %111, %111
  ret void

114:                                              ; preds = %111
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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, !6, i64 0}
!10 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}


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

%struct.Segment = type { i32, i32, i32 }

@seg = external dso_local global [2000002 x %struct.Segment], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z7push_upR7SegmentS_S_(ptr noundef nonnull align 4 dereferenceable(12), i64, i32, i64, i32) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not = icmp sgt i32 %2, %0
  %.not46 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not46
  br i1 %or.cond, label %17, label %7

7:                                                ; preds = %5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %8
  %10 = load <2 x i32>, ptr %9, align 4, !tbaa !5
  %11 = insertelement <2 x i32> poison, i32 %4, i64 0
  %12 = shufflevector <2 x i32> %11, <2 x i32> poison, <2 x i32> zeroinitializer
  %13 = add nsw <2 x i32> %10, %12
  store <2 x i32> %13, ptr %9, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %9, i64 8
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = add nsw i32 %15, %4
  store i32 %16, ptr %14, align 4, !tbaa !9
  br label %34

17:                                               ; preds = %5
  %18 = add nsw i32 %1, %0
  %19 = ashr i32 %18, 1
  %20 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %19)
  %21 = add nsw i32 %19, 1
  %22 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %21, i32 noundef %1)
  %23 = sext i32 %6 to i64
  %24 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %23
  %25 = sext i32 %20 to i64
  %26 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %25
  %27 = sext i32 %22 to i64
  %28 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %27
  tail call void @_Z9push_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(12) %24, ptr noundef nonnull align 4 dereferenceable(12) %26, ptr noundef nonnull align 4 dereferenceable(12) %28)
  %.not47 = icmp slt i32 %19, %2
  br i1 %.not47, label %30, label %29

29:                                               ; preds = %17
  tail call void @_Z6updateiiiii(i32 noundef %0, i32 noundef %19, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %30

30:                                               ; preds = %29, %17
  %31 = icmp slt i32 %19, %3
  br i1 %31, label %32, label %33

32:                                               ; preds = %30
  tail call void @_Z6updateiiiii(i32 noundef %21, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %33

33:                                               ; preds = %32, %30
  %.sroa.05.0.copyload = load i64, ptr %26, align 4
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %26, i64 8
  %.sroa.26.0.copyload = load i32, ptr %.sroa.26.0..sroa_idx, align 4, !tbaa !5
  %.sroa.03.0.copyload = load i64, ptr %28, align 4
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %28, i64 8
  %.sroa.24.0.copyload = load i32, ptr %.sroa.24.0..sroa_idx, align 4, !tbaa !5
  tail call void @_Z7push_upR7SegmentS_S_(ptr noundef nonnull align 4 dereferenceable(12) %24, i64 %.sroa.05.0.copyload, i32 %.sroa.26.0.copyload, i64 %.sroa.03.0.copyload, i32 %.sroa.24.0.copyload)
  br label %34

34:                                               ; preds = %33, %7
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z9push_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #0

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

!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, !6, i64 8}
!10 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass