; LLVM IR from tangjz/acm-icpc :: lydsy/1036.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.Seg = type { i32, i32 }

@seg = external dso_local global [60003 x %struct.Seg], 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: 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) #2

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

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

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

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

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

35:                                               ; preds = %27
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = call i64 @_Z7seg_queiiii(i32 noundef %36, i32 noundef %37, i32 noundef %38, i32 noundef %39)
  store i64 %40, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %75

41:                                               ; preds = %27
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %52

45:                                               ; preds = %41
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = call i64 @_Z7seg_queiiii(i32 noundef %47, i32 noundef %48, i32 noundef %49, i32 noundef %50)
  store i64 %51, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %75

52:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = call i64 @_Z7seg_queiiii(i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  store i64 %57, ptr %12, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = call i64 @_Z7seg_queiiii(i32 noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  store i64 %63, ptr %13, align 4
  %64 = getelementptr inbounds %struct.Seg, ptr %5, i32 0, i32 0
  %65 = getelementptr inbounds %struct.Seg, ptr %12, i32 0, i32 0
  %66 = getelementptr inbounds %struct.Seg, ptr %13, i32 0, i32 0
  %67 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %65, ptr noundef nonnull align 4 dereferenceable(4) %66)
  %68 = load i32, ptr %67, align 4, !tbaa !5
  store i32 %68, ptr %64, align 4, !tbaa !10
  %69 = getelementptr inbounds %struct.Seg, ptr %5, i32 0, i32 1
  %70 = getelementptr inbounds %struct.Seg, ptr %12, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !12
  %72 = getelementptr inbounds %struct.Seg, ptr %13, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !12
  %74 = add nsw i32 %71, %73
  store i32 %74, ptr %69, align 4, !tbaa !12
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %75

75:                                               ; preds = %52, %45, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %76

76:                                               ; preds = %75, %21
  %77 = load i64, ptr %5, align 4
  ret i64 %77
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 4, !5, i64 4, i64 4, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTS3Seg", !6, i64 0, !6, i64 4}
!12 = !{!11, !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.Seg = type { i32, i32 }

@seg = external dso_local local_unnamed_addr global [60003 x %struct.Seg], 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: 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 i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local i64 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.Seg, align 8
  %6 = alloca %struct.Seg, align 8
  %.not = icmp sgt i32 %2, %0
  %.not37 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not37
  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 [60003 x %struct.Seg], ptr @seg, i64 0, i64 %9
  %.sroa.0.0.copyload = load i32, ptr %10, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 4
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  br label %32

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

14:                                               ; preds = %11
  %15 = tail call i64 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %13, i32 noundef %2, i32 noundef %3)
  %.sroa.0.0.extract.trunc = trunc i64 %15 to i32
  %.sroa.5.0.extract.shift = lshr i64 %15, 32
  %.sroa.5.0.extract.trunc = trunc nuw i64 %.sroa.5.0.extract.shift to i32
  br label %32

16:                                               ; preds = %11
  %17 = icmp slt i32 %13, %2
  br i1 %17, label %18, label %21

18:                                               ; preds = %16
  %19 = add nsw i32 %13, 1
  %20 = tail call i64 @_Z7seg_queiiii(i32 noundef %19, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  %.sroa.0.0.extract.trunc28 = trunc i64 %20 to i32
  %.sroa.5.0.extract.shift29 = lshr i64 %20, 32
  %.sroa.5.0.extract.trunc30 = trunc nuw i64 %.sroa.5.0.extract.shift29 to i32
  br label %32

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %22 = tail call i64 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %13, i32 noundef %2, i32 noundef %3)
  store i64 %22, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %23 = add nsw i32 %13, 1
  %24 = tail call i64 @_Z7seg_queiiii(i32 noundef %23, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  store i64 %24, ptr %6, align 8
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %5, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %6, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = add nsw i32 %30, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %32

32:                                               ; preds = %14, %18, %21, %7
  %.sroa.0.1 = phi i32 [ %.sroa.0.0.copyload, %7 ], [ %.sroa.0.0.extract.trunc, %14 ], [ %.sroa.0.0.extract.trunc28, %18 ], [ %26, %21 ]
  %.sroa.5.1 = phi i32 [ %.sroa.5.0.copyload, %7 ], [ %.sroa.5.0.extract.trunc, %14 ], [ %.sroa.5.0.extract.trunc30, %18 ], [ %31, %21 ]
  %.sroa.5.0.insert.ext = zext i32 %.sroa.5.1 to i64
  %.sroa.5.0.insert.shift = shl nuw i64 %.sroa.5.0.insert.ext, 32
  %.sroa.0.0.insert.ext = zext i32 %.sroa.0.1 to i64
  %.sroa.0.0.insert.insert = or disjoint i64 %.sroa.5.0.insert.shift, %.sroa.0.0.insert.ext
  ret i64 %.sroa.0.0.insert.insert
}

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


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