; LLVM IR from tangjz/acm-icpc :: lydsy/2993.ll (Z8seg_initii)

; 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 { [3 x i32], i32 }

@a = external dso_local global [300001 x i32], align 16
@seg = external dso_local global [600003 x %struct.Segment], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6seg_upR7SegmentRKS_S2_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8seg_initii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = call noundef i32 @_Z7seg_idxii(i32 noundef %8, i32 noundef %9)
  store i32 %10, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.Segment, ptr %13, i32 0, i32 1
  store i32 0, ptr %14, align 4, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %18, label %44

18:                                               ; preds = %2
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.Segment, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [3 x i32], ptr %22, i64 0, i64 2
  store i32 0, ptr %23, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.Segment, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [3 x i32], ptr %27, i64 0, i64 1
  store i32 0, ptr %28, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Segment, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [3 x i32], ptr %32, i64 0, i64 0
  store i32 0, ptr %33, align 16, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Segment, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [300001 x i32], ptr @a, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [3 x i32], ptr %37, i64 0, i64 %42
  store i32 1, ptr %43, align 4, !tbaa !5
  store i32 1, ptr %6, align 4
  br label %68

44:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = ashr i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z8seg_initii(i32 noundef %49, i32 noundef %50)
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z8seg_initii(i32 noundef %52, i32 noundef %53)
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %55
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = call noundef i32 @_Z7seg_idxii(i32 noundef %57, i32 noundef %58)
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %60
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = call noundef i32 @_Z7seg_idxii(i32 noundef %63, i32 noundef %64)
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %66
  call void @_Z6seg_upR7SegmentRKS_S2_(ptr noundef nonnull align 4 dereferenceable(16) %56, ptr noundef nonnull align 4 dereferenceable(16) %61, ptr noundef nonnull align 4 dereferenceable(16) %67)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  store i32 0, ptr %6, align 4
  br label %68

68:                                               ; preds = %44, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %69 = load i32, ptr %6, align 4
  switch i32 %69, label %71 [
    i32 0, label %70
    i32 1, label %70
  ]

70:                                               ; preds = %68, %68
  ret void

71:                                               ; preds = %68
  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 12}
!10 = !{!"_ZTS7Segment", !7, i64 0, !6, i64 12}


; 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 { [3 x i32], i32 }

@a = external dso_local local_unnamed_addr global [300001 x i32], align 16
@seg = external dso_local global [600003 x %struct.Segment], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8seg_initii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 0, ptr %6, align 4, !tbaa !5
  %7 = icmp eq i32 %0, %1
  br i1 %7, label %common.ret, label %15

common.ret:                                       ; preds = %2
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 0, ptr %8, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 0, ptr %9, align 4, !tbaa !10
  store i32 0, ptr %5, align 16, !tbaa !10
  %10 = sext i32 %0 to i64
  %11 = getelementptr inbounds [300001 x i32], ptr @a, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [3 x i32], ptr %5, i64 0, i64 %13
  store i32 1, ptr %14, align 4, !tbaa !10
  br label %common.ret22

common.ret22:                                     ; preds = %15, %common.ret
  ret void

15:                                               ; preds = %2
  %16 = add nsw i32 %1, %0
  %17 = ashr i32 %16, 1
  tail call void @_Z8seg_initii(i32 noundef %0, i32 noundef %17)
  %18 = add nsw i32 %17, 1
  tail call void @_Z8seg_initii(i32 noundef %18, i32 noundef %1)
  %19 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %17)
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %20
  %22 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %18, i32 noundef %1)
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %23
  tail call void @_Z6seg_upR7SegmentRKS_S2_(ptr noundef nonnull align 4 dereferenceable(16) %5, ptr noundef nonnull align 4 dereferenceable(16) %21, ptr noundef nonnull align 4 dereferenceable(16) %24)
  br label %common.ret22
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(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, !9, i64 12}
!6 = !{!"_ZTS7Segment", !7, i64 0, !9, i64 12}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}


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