; LLVM IR from tangjz/acm-icpc :: hdu/6070.ll (Z7seg_updiiiid)

; 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 { double, double }

@seg = external dso_local global [120003 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #1

; 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 @_Z7seg_updiiiid(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %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
  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 double %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = call noundef i32 @_Z7seg_idxii(i32 noundef %16, i32 noundef %17)
  store i32 %18, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %22, label %41

22:                                               ; preds = %5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %41

26:                                               ; preds = %22
  %27 = load double, ptr %10, align 8, !tbaa !9
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Segment, ptr %30, i32 0, i32 0
  %32 = load double, ptr %31, align 16, !tbaa !11
  %33 = fadd double %32, %27
  store double %33, ptr %31, align 16, !tbaa !11
  %34 = load double, ptr %10, align 8, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Segment, ptr %37, i32 0, i32 1
  %39 = load double, ptr %38, align 8, !tbaa !13
  %40 = fadd double %39, %34
  store double %40, ptr %38, align 8, !tbaa !13
  store i32 1, ptr %12, align 4
  br label %145

41:                                               ; preds = %22, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %45 = ashr i32 %44, 1
  store i32 %45, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %13, align 4, !tbaa !5
  %48 = call noundef i32 @_Z7seg_idxii(i32 noundef %46, i32 noundef %47)
  store i32 %48, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %49 = load i32, ptr %13, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = call noundef i32 @_Z7seg_idxii(i32 noundef %50, i32 noundef %51)
  store i32 %52, ptr %15, align 4, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.Segment, ptr %55, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !13
  %58 = call noundef i32 @_Z3sgnd(double noundef %57)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %109

60:                                               ; preds = %41
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Segment, ptr %63, i32 0, i32 1
  %65 = load double, ptr %64, align 8, !tbaa !13
  %66 = load i32, ptr %14, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.Segment, ptr %68, i32 0, i32 0
  %70 = load double, ptr %69, align 16, !tbaa !11
  %71 = fadd double %70, %65
  store double %71, ptr %69, align 16, !tbaa !11
  %72 = load i32, ptr %11, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.Segment, ptr %74, i32 0, i32 1
  %76 = load double, ptr %75, align 8, !tbaa !13
  %77 = load i32, ptr %14, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.Segment, ptr %79, i32 0, i32 1
  %81 = load double, ptr %80, align 8, !tbaa !13
  %82 = fadd double %81, %76
  store double %82, ptr %80, align 8, !tbaa !13
  %83 = load i32, ptr %11, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.Segment, ptr %85, i32 0, i32 1
  %87 = load double, ptr %86, align 8, !tbaa !13
  %88 = load i32, ptr %15, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %89
  %91 = getelementptr inbounds %struct.Segment, ptr %90, i32 0, i32 0
  %92 = load double, ptr %91, align 16, !tbaa !11
  %93 = fadd double %92, %87
  store double %93, ptr %91, align 16, !tbaa !11
  %94 = load i32, ptr %11, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.Segment, ptr %96, i32 0, i32 1
  %98 = load double, ptr %97, align 8, !tbaa !13
  %99 = load i32, ptr %15, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %100
  %102 = getelementptr inbounds %struct.Segment, ptr %101, i32 0, i32 1
  %103 = load double, ptr %102, align 8, !tbaa !13
  %104 = fadd double %103, %98
  store double %104, ptr %102, align 8, !tbaa !13
  %105 = load i32, ptr %11, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.Segment, ptr %107, i32 0, i32 1
  store double 0.000000e+00, ptr %108, align 8, !tbaa !13
  br label %109

109:                                              ; preds = %60, %41
  %110 = load i32, ptr %8, align 4, !tbaa !5
  %111 = load i32, ptr %13, align 4, !tbaa !5
  %112 = icmp sle i32 %110, %111
  br i1 %112, label %113, label %119

113:                                              ; preds = %109
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = load i32, ptr %13, align 4, !tbaa !5
  %116 = load i32, ptr %8, align 4, !tbaa !5
  %117 = load i32, ptr %9, align 4, !tbaa !5
  %118 = load double, ptr %10, align 8, !tbaa !9
  call void @_Z7seg_updiiiid(i32 noundef %114, i32 noundef %115, i32 noundef %116, i32 noundef %117, double noundef %118)
  br label %119

119:                                              ; preds = %113, %109
  %120 = load i32, ptr %13, align 4, !tbaa !5
  %121 = load i32, ptr %9, align 4, !tbaa !5
  %122 = icmp slt i32 %120, %121
  br i1 %122, label %123, label %130

123:                                              ; preds = %119
  %124 = load i32, ptr %13, align 4, !tbaa !5
  %125 = add nsw i32 %124, 1
  %126 = load i32, ptr %7, align 4, !tbaa !5
  %127 = load i32, ptr %8, align 4, !tbaa !5
  %128 = load i32, ptr %9, align 4, !tbaa !5
  %129 = load double, ptr %10, align 8, !tbaa !9
  call void @_Z7seg_updiiiid(i32 noundef %125, i32 noundef %126, i32 noundef %127, i32 noundef %128, double noundef %129)
  br label %130

130:                                              ; preds = %123, %119
  %131 = load i32, ptr %14, align 4, !tbaa !5
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %132
  %134 = getelementptr inbounds %struct.Segment, ptr %133, i32 0, i32 0
  %135 = load i32, ptr %15, align 4, !tbaa !5
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %136
  %138 = getelementptr inbounds %struct.Segment, ptr %137, i32 0, i32 0
  %139 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %134, ptr noundef nonnull align 8 dereferenceable(8) %138)
  %140 = load double, ptr %139, align 8, !tbaa !9
  %141 = load i32, ptr %11, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %142
  %144 = getelementptr inbounds %struct.Segment, ptr %143, i32 0, i32 0
  store double %140, ptr %144, align 16, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  store i32 0, ptr %12, align 4
  br label %145

145:                                              ; preds = %130, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %146 = load i32, ptr %12, align 4
  switch i32 %146, label %148 [
    i32 0, label %147
    i32 1, label %147
  ]

147:                                              ; preds = %145, %145
  ret void

148:                                              ; preds = %145
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = { 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 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS7Segment", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}


; 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 { double, double }

@seg = external dso_local global [120003 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: mustprogress nounwind uwtable
define dso_local void @_Z7seg_updiiiid(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4) local_unnamed_addr #1 {
  %6 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not = icmp sgt i32 %2, %0
  %.not44 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not44
  br i1 %or.cond, label %14, label %7

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

14:                                               ; preds = %5
  %15 = add nsw i32 %1, %0
  %16 = ashr i32 %15, 1
  %17 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %16)
  %18 = add nsw i32 %16, 1
  %19 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %18, i32 noundef %1)
  %20 = sext i32 %6 to i64
  %21 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = tail call noundef i32 @_Z3sgnd(double noundef %23)
  %.not45 = icmp eq i32 %24, 0
  br i1 %.not45, label %40, label %25

25:                                               ; preds = %14
  %26 = load double, ptr %22, align 8, !tbaa !9
  %27 = sext i32 %17 to i64
  %28 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %27
  %29 = load <2 x double>, ptr %28, align 16, !tbaa !5
  %30 = insertelement <2 x double> poison, double %26, i64 0
  %31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
  %32 = fadd <2 x double> %31, %29
  store <2 x double> %32, ptr %28, align 16, !tbaa !5
  %33 = load double, ptr %22, align 8, !tbaa !9
  %34 = sext i32 %19 to i64
  %35 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %34
  %36 = load <2 x double>, ptr %35, align 16, !tbaa !5
  %37 = insertelement <2 x double> poison, double %33, i64 0
  %38 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> zeroinitializer
  %39 = fadd <2 x double> %38, %36
  store <2 x double> %39, ptr %35, align 16, !tbaa !5
  store double 0.000000e+00, ptr %22, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %25, %14
  %.not46 = icmp slt i32 %16, %2
  br i1 %.not46, label %42, label %41

41:                                               ; preds = %40
  tail call void @_Z7seg_updiiiid(i32 noundef %0, i32 noundef %16, i32 noundef %2, i32 noundef %3, double noundef %4)
  br label %42

42:                                               ; preds = %41, %40
  %43 = icmp slt i32 %16, %3
  br i1 %43, label %44, label %45

44:                                               ; preds = %42
  tail call void @_Z7seg_updiiiid(i32 noundef %18, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4)
  br label %45

45:                                               ; preds = %44, %42
  %46 = sext i32 %17 to i64
  %47 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %46
  %48 = sext i32 %19 to i64
  %49 = getelementptr inbounds [120003 x %struct.Segment], ptr @seg, i64 0, i64 %48
  %50 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %47, ptr noundef nonnull align 8 dereferenceable(8) %49)
  %51 = load double, ptr %50, align 8, !tbaa !5
  store double %51, ptr %21, align 16, !tbaa !11
  br label %52

52:                                               ; preds = %45, %7
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = { 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 = !{!"double", !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 8}
!11 = !{!10, !6, i64 0}


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