; LLVM IR from tangjz/acm-icpc :: codeforces/complete/756C.ll (Z7seg_updiiii)

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8seg_downiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6seg_upiii(i32 noundef, i32 noundef, i32 noundef) #1

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

20:                                               ; preds = %4
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.Segment, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = add nsw i32 %26, %21
  store i32 %27, ptr %25, align 8, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Segment, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = add nsw i32 %33, %28
  store i32 %34, ptr %32, align 4, !tbaa !11
  store i32 1, ptr %10, align 4
  br label %67

35:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  %39 = ashr i32 %38, 1
  store i32 %39, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = call noundef i32 @_Z7seg_idxii(i32 noundef %40, i32 noundef %41)
  store i32 %42, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = call noundef i32 @_Z7seg_idxii(i32 noundef %44, i32 noundef %45)
  store i32 %46, ptr %13, align 4, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !5
  call void @_Z8seg_downiii(i32 noundef %47, i32 noundef %48, i32 noundef %49)
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z7seg_updiiii(i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = icmp sgt i32 %54, %55
  br i1 %56, label %57, label %63

57:                                               ; preds = %35
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z7seg_updiiii(i32 noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  br label %63

63:                                               ; preds = %57, %35
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = load i32, ptr %13, align 4, !tbaa !5
  call void @_Z6seg_upiii(i32 noundef %64, i32 noundef %65, i32 noundef %66)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  store i32 0, ptr %10, align 4
  br label %67

67:                                               ; preds = %63, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %68 = load i32, ptr %10, align 4
  switch i32 %68, label %70 [
    i32 0, label %69
    i32 1, label %69
  ]

69:                                               ; preds = %67, %67
  ret void

70:                                               ; preds = %67
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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}
!11 = !{!10, !6, i64 4}


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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6seg_upiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7seg_updiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not = icmp sgt i32 %1, %2
  br i1 %.not, label %13, label %6

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

13:                                               ; preds = %4
  %14 = add nsw i32 %1, %0
  %15 = ashr i32 %14, 1
  %16 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %15)
  %17 = add nsw i32 %15, 1
  %18 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %17, i32 noundef %1)
  tail call void @_Z8seg_downiii(i32 noundef %5, i32 noundef %16, i32 noundef %18)
  tail call void @_Z7seg_updiiii(i32 noundef %0, i32 noundef %15, i32 noundef %2, i32 noundef %3)
  %19 = icmp slt i32 %15, %2
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  tail call void @_Z7seg_updiiii(i32 noundef %17, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %21

21:                                               ; preds = %20, %13
  tail call void @_Z6seg_upiii(i32 noundef %5, i32 noundef %16, i32 noundef %18)
  br label %22

22:                                               ; preds = %21, %6
  ret void
}

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

!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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass