; LLVM IR from tangjz/acm-icpc :: codeforces/gym/102012E.ll (Z8seg_findiiiix)

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

@seg = external dso_local global ptr, align 8

; 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 uwtable
declare dso_local void @_Z8seg_downii(i32 noundef, i32 noundef) #2

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

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

26:                                               ; preds = %22
  %27 = load ptr, ptr @seg, align 8, !tbaa !11
  %28 = load i32, ptr %12, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.Segment, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.Segment, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !13
  %33 = load i64, ptr %11, align 8, !tbaa !9
  %34 = icmp sgt i64 %32, %33
  br i1 %34, label %35, label %40

35:                                               ; preds = %26
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = call noundef i32 @_Z8seg_findiix(i32 noundef %36, i32 noundef %37, i64 noundef %38)
  br label %41

40:                                               ; preds = %26
  br label %41

41:                                               ; preds = %40, %35
  %42 = phi i32 [ %39, %35 ], [ 100001, %40 ]
  store i32 %42, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %80

43:                                               ; preds = %22, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = ashr i32 %46, 1
  store i32 %47, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 100001, ptr %15, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z8seg_downii(i32 noundef %48, i32 noundef %49)
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = load i32, ptr %14, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %53, label %63

53:                                               ; preds = %43
  %54 = load i32, ptr %15, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 100001
  br i1 %55, label %56, label %63

56:                                               ; preds = %53
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %14, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = call noundef i32 @_Z8seg_findiiiix(i32 noundef %57, i32 noundef %58, i32 noundef %59, i32 noundef %60, i64 noundef %61)
  store i32 %62, ptr %15, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %56, %53, %43
  %64 = load i32, ptr %14, align 4, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %78

67:                                               ; preds = %63
  %68 = load i32, ptr %15, align 4, !tbaa !5
  %69 = icmp eq i32 %68, 100001
  br i1 %69, label %70, label %78

70:                                               ; preds = %67
  %71 = load i32, ptr %14, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = load i32, ptr %10, align 4, !tbaa !5
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = call noundef i32 @_Z8seg_findiiiix(i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75, i64 noundef %76)
  store i32 %77, ptr %15, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %70, %67, %63
  %79 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %79, ptr %6, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %80

80:                                               ; preds = %78, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %81 = load i32, ptr %6, align 4
  ret i32 %81
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8seg_findiix(i32 noundef, i32 noundef, i64 noundef) #2

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 = { inlinehint 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}


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

@seg = external dso_local local_unnamed_addr global ptr, align 8

; 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 uwtable
declare dso_local void @_Z8seg_downii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8seg_findiiiix(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i64 noundef %4) local_unnamed_addr #2 {
  %6 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not52 = icmp sgt i32 %2, %0
  %.not44 = icmp sgt i32 %1, %3
  %or.cond53 = or i1 %.not44, %.not52
  br i1 %or.cond53, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %5
  br i1 %.not44, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr54.us = phi i32 [ %9, %tailrecurse.us ], [ %0, %.lr.ph ]
  %7 = add nsw i32 %.tr54.us, %1
  %8 = ashr i32 %7, 1
  tail call void @_Z8seg_downii(i32 noundef %.tr54.us, i32 noundef %1)
  %.not45.us = icmp slt i32 %8, %2
  br i1 %.not45.us, label %13, label %11

tailrecurse.us:                                   ; preds = %13
  %9 = add nsw i32 %8, 1
  %10 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %9, i32 noundef %1)
  br label %.lr.ph.split.us

11:                                               ; preds = %.lr.ph.split.us
  %12 = tail call noundef i32 @_Z8seg_findiiiix(i32 noundef %.tr54.us, i32 noundef %8, i32 noundef %2, i32 noundef %3, i64 noundef %4)
  br label %13

13:                                               ; preds = %11, %.lr.ph.split.us
  %.0.us = phi i32 [ %12, %11 ], [ 100001, %.lr.ph.split.us ]
  %14 = icmp slt i32 %8, %3
  %15 = icmp eq i32 %.0.us, 100001
  %or.cond3.us = and i1 %14, %15
  br i1 %or.cond3.us, label %tailrecurse.us, label %.loopexit

tailrecurse:                                      ; preds = %29
  %16 = add nsw i32 %26, 1
  %17 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %16, i32 noundef %1)
  %.not = icmp slt i32 %16, %2
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %16, %tailrecurse ]
  %.lcssa = phi i32 [ %6, %5 ], [ %17, %tailrecurse ]
  %18 = load ptr, ptr @seg, align 8, !tbaa !5
  %19 = sext i32 %.lcssa to i64
  %20 = getelementptr inbounds %struct.Segment, ptr %18, i64 %19, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp sgt i64 %21, %4
  br i1 %22, label %23, label %.loopexit

23:                                               ; preds = %tailrecurse._crit_edge
  %24 = tail call noundef i32 @_Z8seg_findiix(i32 noundef %.tr.lcssa, i32 noundef %1, i64 noundef %4)
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr54 = phi i32 [ %16, %tailrecurse ], [ %0, %.lr.ph ]
  %25 = add nsw i32 %.tr54, %1
  %26 = ashr i32 %25, 1
  tail call void @_Z8seg_downii(i32 noundef %.tr54, i32 noundef %1)
  %.not45 = icmp slt i32 %26, %2
  br i1 %.not45, label %29, label %27

27:                                               ; preds = %.lr.ph.split
  %28 = tail call noundef i32 @_Z8seg_findiiiix(i32 noundef %.tr54, i32 noundef %26, i32 noundef %2, i32 noundef %3, i64 noundef %4)
  br label %29

29:                                               ; preds = %27, %.lr.ph.split
  %.0 = phi i32 [ %28, %27 ], [ 100001, %.lr.ph.split ]
  %30 = icmp slt i32 %26, %3
  %31 = icmp eq i32 %.0, 100001
  %or.cond3 = and i1 %30, %31
  br i1 %or.cond3, label %tailrecurse, label %.loopexit

.loopexit:                                        ; preds = %29, %13, %23, %tailrecurse._crit_edge
  %.036 = phi i32 [ %24, %23 ], [ 100001, %tailrecurse._crit_edge ], [ %.0.us, %13 ], [ %.0, %29 ]
  ret i32 %.036
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8seg_findiix(i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

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 = { inlinehint 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 = { 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass