; LLVM IR from tangjz/acm-icpc :: hdu/6135.ll (Z7seg_queiiii)

; 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 [200003 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: 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

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

; Function Attrs: mustprogress uwtable
define dso_local { double, double } @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca %struct.Segment, align 8
  %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 %struct.Segment, align 8
  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
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %16, label %26

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

20:                                               ; preds = %16
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = call noundef i32 @_Z7seg_idxii(i32 noundef %21, i32 noundef %22)
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %24
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 16 %25, i64 16, i1 false), !tbaa.struct !9
  br label %90

26:                                               ; preds = %16, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = ashr i32 %29, 1
  store i32 %30, ptr %10, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %44

34:                                               ; preds = %26
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = call { double, double } @_Z7seg_queiiii(i32 noundef %35, i32 noundef %36, i32 noundef %37, i32 noundef %38)
  %40 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 0
  %41 = extractvalue { double, double } %39, 0
  store double %41, ptr %40, align 8
  %42 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 1
  %43 = extractvalue { double, double } %39, 1
  store double %43, ptr %42, align 8
  store i32 1, ptr %11, align 4
  br label %89

44:                                               ; preds = %26
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %59

48:                                               ; preds = %44
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = call { double, double } @_Z7seg_queiiii(i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  %55 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 0
  %56 = extractvalue { double, double } %54, 0
  store double %56, ptr %55, align 8
  %57 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 1
  %58 = extractvalue { double, double } %54, 1
  store double %58, ptr %57, align 8
  store i32 1, ptr %11, align 4
  br label %89

59:                                               ; preds = %44
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = call { double, double } @_Z7seg_queiiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %63)
  %65 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 0
  %66 = extractvalue { double, double } %64, 0
  store double %66, ptr %65, align 8
  %67 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 1
  %68 = extractvalue { double, double } %64, 1
  store double %68, ptr %67, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %69 = load i32, ptr %10, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = call { double, double } @_Z7seg_queiiii(i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73)
  %75 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %76 = extractvalue { double, double } %74, 0
  store double %76, ptr %75, align 8
  %77 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %78 = extractvalue { double, double } %74, 1
  store double %78, ptr %77, align 8
  %79 = getelementptr inbounds %struct.Segment, ptr %5, i32 0, i32 0
  %80 = getelementptr inbounds %struct.Segment, ptr %12, i32 0, i32 0
  %81 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %79, ptr noundef nonnull align 8 dereferenceable(8) %80)
  %82 = load double, ptr %81, align 8, !tbaa !10
  %83 = getelementptr inbounds %struct.Segment, ptr %5, i32 0, i32 0
  store double %82, ptr %83, align 8, !tbaa !12
  %84 = getelementptr inbounds %struct.Segment, ptr %5, i32 0, i32 1
  %85 = getelementptr inbounds %struct.Segment, ptr %12, i32 0, i32 1
  %86 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %84, ptr noundef nonnull align 8 dereferenceable(8) %85)
  %87 = load double, ptr %86, align 8, !tbaa !10
  %88 = getelementptr inbounds %struct.Segment, ptr %5, i32 0, i32 1
  store double %87, ptr %88, align 8, !tbaa !14
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  br label %89

89:                                               ; preds = %59, %48, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %90

90:                                               ; preds = %89, %20
  %91 = load { double, double }, ptr %5, align 8
  ret { double, double } %91
}

; 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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !10, i64 8, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_ZTS7Segment", !11, i64 0, !11, i64 8}
!14 = !{!13, !11, 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 local_unnamed_addr global [200003 x %struct.Segment], align 16

; Function Attrs: mustprogress 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) local_unnamed_addr #1

; Function Attrs: mustprogress 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 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 #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local { double, double } @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.Segment, align 8
  %6 = alloca %struct.Segment, align 8
  %.not = icmp sgt i32 %2, %0
  %.not34 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not34
  br i1 %or.cond, label %11, label %7

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %9
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 16 dereferenceable(16) %10, i64 16, i1 false), !tbaa.struct !5
  %.fca.1.gep.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 8
  %.fca.1.load.pre = load double, ptr %.fca.1.gep.phi.trans.insert, align 8
  br label %39

11:                                               ; preds = %4
  %12 = add nsw i32 %1, %0
  %13 = ashr i32 %12, 1
  %.not35 = icmp slt i32 %13, %3
  br i1 %.not35, label %18, label %14

14:                                               ; preds = %11
  %15 = tail call { double, double } @_Z7seg_queiiii(i32 noundef %0, i32 noundef %13, i32 noundef %2, i32 noundef %3)
  %16 = extractvalue { double, double } %15, 0
  store double %16, ptr %5, align 8
  %17 = extractvalue { double, double } %15, 1
  br label %39

18:                                               ; preds = %11
  %19 = icmp slt i32 %13, %2
  br i1 %19, label %20, label %25

20:                                               ; preds = %18
  %21 = add nsw i32 %13, 1
  %22 = tail call { double, double } @_Z7seg_queiiii(i32 noundef %21, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  %23 = extractvalue { double, double } %22, 0
  store double %23, ptr %5, align 8
  %24 = extractvalue { double, double } %22, 1
  br label %39

25:                                               ; preds = %18
  %26 = tail call { double, double } @_Z7seg_queiiii(i32 noundef %0, i32 noundef %13, i32 noundef %2, i32 noundef %3)
  %27 = extractvalue { double, double } %26, 0
  store double %27, ptr %5, align 8
  %28 = getelementptr inbounds i8, ptr %5, i64 8
  %29 = extractvalue { double, double } %26, 1
  store double %29, ptr %28, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  %30 = add nsw i32 %13, 1
  %31 = tail call { double, double } @_Z7seg_queiiii(i32 noundef %30, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  %32 = extractvalue { double, double } %31, 0
  store double %32, ptr %6, align 8
  %33 = getelementptr inbounds i8, ptr %6, i64 8
  %34 = extractvalue { double, double } %31, 1
  store double %34, ptr %33, align 8
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %36 = load double, ptr %35, align 8, !tbaa !6
  store double %36, ptr %5, align 8, !tbaa !10
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull align 8 dereferenceable(8) %33)
  %38 = load double, ptr %37, align 8, !tbaa !6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  br label %39

39:                                               ; preds = %14, %20, %25, %7
  %.fca.1.load = phi double [ %17, %14 ], [ %24, %20 ], [ %38, %25 ], [ %.fca.1.load.pre, %7 ]
  %.fca.0.load = load double, ptr %5, align 8
  %.fca.0.insert = insertvalue { double, double } poison, double %.fca.0.load, 0
  %.fca.1.insert = insertvalue { double, double } %.fca.0.insert, double %.fca.1.load, 1
  ret { double, double } %.fca.1.insert
}

; Function Attrs: mustprogress 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

attributes #0 = { mustprogress 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 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTS7Segment", !7, i64 0, !7, i64 8}


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