; LLVM IR from tangjz/acm-icpc :: 51nod/1555.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 { i32, i32, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #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 %10, 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 %42

22:                                               ; preds = %4
  %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 %42

26:                                               ; preds = %22
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Segment, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %39

33:                                               ; preds = %26
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Segment, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !11
  br label %40

39:                                               ; preds = %26
  br label %40

40:                                               ; preds = %39, %33
  %41 = phi i32 [ %38, %33 ], [ 0, %39 ]
  store i32 %41, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %100

42:                                               ; preds = %22, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = add nsw i32 %43, %44
  %46 = ashr i32 %45, 1
  store i32 %46, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = call noundef i32 @_Z7seg_idxii(i32 noundef %47, i32 noundef %48)
  store i32 %49, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = call noundef i32 @_Z7seg_idxii(i32 noundef %51, i32 noundef %52)
  store i32 %53, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = load i32, ptr %13, align 4, !tbaa !5
  %56 = load i32, ptr %14, align 4, !tbaa !5
  call void @_Z8seg_downiii(i32 noundef %54, i32 noundef %55, i32 noundef %56)
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %12, align 4, !tbaa !5
  %59 = icmp sle i32 %57, %58
  br i1 %59, label %60, label %75

60:                                               ; preds = %42
  %61 = load i32, ptr %13, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Segment, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = icmp slt i32 %65, 2
  br i1 %66, label %67, label %75

67:                                               ; preds = %60
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = load i32, ptr %12, align 4, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = call noundef i32 @_Z7seg_queiiii(i32 noundef %68, i32 noundef %69, i32 noundef %70, i32 noundef %71)
  %73 = load i32, ptr %15, align 4, !tbaa !5
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr %15, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %67, %60, %42
  %76 = load i32, ptr %12, align 4, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %95

79:                                               ; preds = %75
  %80 = load i32, ptr %14, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.Segment, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 4, !tbaa !9
  %85 = icmp slt i32 %84, 2
  br i1 %85, label %86, label %95

86:                                               ; preds = %79
  %87 = load i32, ptr %12, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = load i32, ptr %8, align 4, !tbaa !5
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = call noundef i32 @_Z7seg_queiiii(i32 noundef %88, i32 noundef %89, i32 noundef %90, i32 noundef %91)
  %93 = load i32, ptr %15, align 4, !tbaa !5
  %94 = add nsw i32 %93, %92
  store i32 %94, ptr %15, align 4, !tbaa !5
  br label %95

95:                                               ; preds = %86, %79, %75
  %96 = load i32, ptr %10, align 4, !tbaa !5
  %97 = load i32, ptr %13, align 4, !tbaa !5
  %98 = load i32, ptr %14, align 4, !tbaa !5
  call void @_Z6seg_upiii(i32 noundef %96, i32 noundef %97, i32 noundef %98)
  %99 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %99, ptr %5, align 4
  store i32 1, ptr %11, align 4
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %100

100:                                              ; preds = %95, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %101 = load i32, ptr %5, align 4
  ret i32 %101
}

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


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

@seg = external dso_local local_unnamed_addr global [600001 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z6seg_upiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7seg_queiiii(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 %2, %0
  %.not42 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not42
  br i1 %or.cond, label %14, label %6

6:                                                ; preds = %4
  %7 = sext i32 %5 to i64
  %8 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %38

12:                                               ; preds = %6
  %13 = load i32, ptr %8, align 4, !tbaa !10
  br label %38

14:                                               ; preds = %4
  %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)
  tail call void @_Z8seg_downiii(i32 noundef %5, i32 noundef %17, i32 noundef %19)
  %.not43 = icmp slt i32 %16, %2
  br i1 %.not43, label %27, label %20

20:                                               ; preds = %14
  %21 = sext i32 %17 to i64
  %22 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %21, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 2
  br i1 %24, label %25, label %27

25:                                               ; preds = %20
  %26 = tail call noundef i32 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %16, i32 noundef %2, i32 noundef %3)
  br label %27

27:                                               ; preds = %25, %20, %14
  %.0 = phi i32 [ %26, %25 ], [ 0, %20 ], [ 0, %14 ]
  %28 = icmp slt i32 %16, %3
  br i1 %28, label %29, label %37

29:                                               ; preds = %27
  %30 = sext i32 %19 to i64
  %31 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %30, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 2
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = tail call noundef i32 @_Z7seg_queiiii(i32 noundef %18, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  %36 = add nsw i32 %35, %.0
  br label %37

37:                                               ; preds = %34, %29, %27
  %.1 = phi i32 [ %36, %34 ], [ %.0, %29 ], [ %.0, %27 ]
  tail call void @_Z6seg_upiii(i32 noundef %5, i32 noundef %17, i32 noundef %19)
  br label %38

38:                                               ; preds = %12, %6, %37
  %.038 = phi i32 [ %.1, %37 ], [ %13, %12 ], [ 0, %6 ]
  ret i32 %.038
}

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, !7, i64 4}
!6 = !{!"_ZTS7Segment", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}


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