; LLVM IR from tangjz/acm-icpc :: codeforces/280D.ll (Z7seg_queiiRKiS0_)

; 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 { i8, [2 x ptr] }
%struct.Info = type { i32, i32, i32, i32, i32, i32, i32, i32 }

@tail = external dso_local global ptr, align 8
@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 uwtable
declare dso_local void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %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 ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %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 ptr, ptr %8, align 8, !tbaa !9
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %23, label %42

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

28:                                               ; preds = %23
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Segment, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Segment, ptr %35, i32 0, i32 0
  %37 = load i8, ptr %36, align 8, !tbaa !11, !range !14, !noundef !15
  %38 = trunc i8 %37 to i1
  %39 = zext i1 %38 to i64
  %40 = getelementptr inbounds [2 x ptr], ptr %32, i64 0, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  store ptr %41, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %112

42:                                               ; preds = %23, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %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) #5
  %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) #5
  %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
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %55
  %57 = load i32, ptr %13, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %58
  %60 = load i32, ptr %14, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %61
  call void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24) %56, ptr noundef nonnull align 8 dereferenceable(24) %59, ptr noundef nonnull align 8 dereferenceable(24) %62)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %63 = load ptr, ptr %9, align 8, !tbaa !9
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = icmp sle i32 %64, %65
  br i1 %66, label %67, label %73

67:                                               ; preds = %42
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = load i32, ptr %12, align 4, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !9
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %68, i32 noundef %69, ptr noundef nonnull align 4 dereferenceable(4) %70, ptr noundef nonnull align 4 dereferenceable(4) %71)
  store ptr %72, ptr %15, align 8, !tbaa !9
  br label %101

73:                                               ; preds = %42
  %74 = load i32, ptr %12, align 4, !tbaa !5
  %75 = load ptr, ptr %8, align 8, !tbaa !9
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = icmp slt i32 %74, %76
  br i1 %77, label %78, label %85

78:                                               ; preds = %73
  %79 = load i32, ptr %12, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = load ptr, ptr %8, align 8, !tbaa !9
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  %84 = call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %80, i32 noundef %81, ptr noundef nonnull align 4 dereferenceable(4) %82, ptr noundef nonnull align 4 dereferenceable(4) %83)
  store ptr %84, ptr %15, align 8, !tbaa !9
  br label %100

85:                                               ; preds = %73
  %86 = load ptr, ptr @tail, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.Info, ptr %86, i32 1
  store ptr %87, ptr @tail, align 8, !tbaa !9
  store ptr %86, ptr %15, align 8, !tbaa !9
  %88 = load ptr, ptr %15, align 8, !tbaa !9
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = load i32, ptr %12, align 4, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  %93 = call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %89, i32 noundef %90, ptr noundef nonnull align 4 dereferenceable(4) %91, ptr noundef nonnull align 4 dereferenceable(4) %92)
  %94 = load i32, ptr %12, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = load ptr, ptr %8, align 8, !tbaa !9
  %98 = load ptr, ptr %9, align 8, !tbaa !9
  %99 = call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %95, i32 noundef %96, ptr noundef nonnull align 4 dereferenceable(4) %97, ptr noundef nonnull align 4 dereferenceable(4) %98)
  call void @_ZN4Info6updateERKS_S1_(ptr noundef nonnull align 4 dereferenceable(32) %88, ptr noundef nonnull align 4 dereferenceable(32) %93, ptr noundef nonnull align 4 dereferenceable(32) %99)
  br label %100

100:                                              ; preds = %85, %78
  br label %101

101:                                              ; preds = %100, %67
  %102 = load i32, ptr %10, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %103
  %105 = load i32, ptr %13, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %106
  %108 = load i32, ptr %14, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %109
  call void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24) %104, ptr noundef nonnull align 8 dereferenceable(24) %107, ptr noundef nonnull align 8 dereferenceable(24) %110)
  %111 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %111, ptr %5, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %112

112:                                              ; preds = %101, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %113 = load ptr, ptr %5, align 8
  ret ptr %113
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Info6updateERKS_S1_(ptr noundef nonnull align 4 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(32)) #4 align 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 = { 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 #5 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS7Segment", !13, i64 0, !7, i64 8}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}


; 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 { i8, [2 x ptr] }

@tail = external dso_local local_unnamed_addr global ptr, align 8
@seg = external dso_local global [200003 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 uwtable
declare dso_local void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) local_unnamed_addr #2 {
  %5 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp sgt i32 %6, %0
  %7 = load i32, ptr %3, align 4
  %.not44 = icmp slt i32 %7, %1
  %or.cond = select i1 %.not, i1 true, i1 %.not44
  br i1 %or.cond, label %16, label %8

8:                                                ; preds = %4
  %9 = sext i32 %5 to i64
  %10 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i8, ptr %10, align 8, !tbaa !9, !range !12, !noundef !13
  %13 = zext nneg i8 %12 to i64
  %14 = getelementptr inbounds [2 x ptr], ptr %11, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  br label %42

16:                                               ; preds = %4
  %17 = add nsw i32 %1, %0
  %18 = ashr i32 %17, 1
  %19 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %18)
  %20 = add nsw i32 %18, 1
  %21 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %20, i32 noundef %1)
  %22 = sext i32 %5 to i64
  %23 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %22
  %24 = sext i32 %19 to i64
  %25 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %24
  %26 = sext i32 %21 to i64
  %27 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %26
  tail call void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24) %23, ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef nonnull align 8 dereferenceable(24) %27)
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %.not45 = icmp sgt i32 %28, %18
  br i1 %.not45, label %31, label %29

29:                                               ; preds = %16
  %30 = tail call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %0, i32 noundef %18, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  br label %41

31:                                               ; preds = %16
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp slt i32 %18, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = tail call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %20, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  br label %41

36:                                               ; preds = %31
  %37 = load ptr, ptr @tail, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %37, i64 32
  store ptr %38, ptr @tail, align 8, !tbaa !14
  %39 = tail call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %0, i32 noundef %18, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %40 = tail call noundef ptr @_Z7seg_queiiRKiS0_(i32 noundef %20, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  tail call void @_ZN4Info6updateERKS_S1_(ptr noundef nonnull align 4 dereferenceable(32) %37, ptr noundef nonnull align 4 dereferenceable(32) %39, ptr noundef nonnull align 4 dereferenceable(32) %40)
  br label %41

41:                                               ; preds = %34, %36, %29
  %.0 = phi ptr [ %30, %29 ], [ %35, %34 ], [ %37, %36 ]
  tail call void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24) %23, ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef nonnull align 8 dereferenceable(24) %27)
  br label %42

42:                                               ; preds = %41, %8
  %.042 = phi ptr [ %15, %8 ], [ %.0, %41 ]
  ret ptr %.042
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Info6updateERKS_S1_(ptr noundef nonnull align 4 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(32)) local_unnamed_addr #3 align 2

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" }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS7Segment", !11, i64 0, !7, i64 8}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}


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