; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-29/A - Block Compaction - lzy.ll (Z3queiii)

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

@S = external dso_local global [400009 x %struct.Seg], align 16

; 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)) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3queiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %15
  %17 = getelementptr inbounds %struct.Seg, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 16, !tbaa !9
  %19 = icmp sle i32 %13, %18
  br i1 %19, label %20, label %34

20:                                               ; preds = %3
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.Seg, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %20
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Seg, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !12
  store i32 %33, ptr %4, align 4
  br label %119

34:                                               ; preds = %20, %3
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Seg, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %79

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.Seg, ptr %44, i32 0, i32 3
  store ptr %45, ptr %8, align 8, !tbaa !14
  %46 = load ptr, ptr %8, align 8, !tbaa !14
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = mul nsw i32 2, %48
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Seg, ptr %52, i32 0, i32 2
  store i32 %47, ptr %53, align 8, !tbaa !12
  %54 = load ptr, ptr %8, align 8, !tbaa !14
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = mul nsw i32 2, %56
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.Seg, ptr %60, i32 0, i32 3
  store i32 %55, ptr %61, align 4, !tbaa !13
  %62 = load ptr, ptr %8, align 8, !tbaa !14
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = mul nsw i32 2, %64
  %66 = add nsw i32 %65, 2
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.Seg, ptr %68, i32 0, i32 2
  store i32 %63, ptr %69, align 8, !tbaa !12
  %70 = load ptr, ptr %8, align 8, !tbaa !14
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = mul nsw i32 2, %72
  %74 = add nsw i32 %73, 2
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %75
  %77 = getelementptr inbounds %struct.Seg, ptr %76, i32 0, i32 3
  store i32 %71, ptr %77, align 4, !tbaa !13
  %78 = load ptr, ptr %8, align 8, !tbaa !14
  store i32 0, ptr %78, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %79

79:                                               ; preds = %41, %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.Seg, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 16, !tbaa !9
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %86
  %88 = getelementptr inbounds %struct.Seg, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %88, align 4, !tbaa !11
  %90 = add nsw i32 %84, %89
  %91 = sdiv i32 %90, 2
  store i32 %91, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = icmp sle i32 %92, %93
  br i1 %94, label %95, label %104

95:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = mul nsw i32 2, %96
  %98 = add nsw i32 %97, 1
  %99 = load i32, ptr %6, align 4, !tbaa !5
  %100 = load i32, ptr %7, align 4, !tbaa !5
  %101 = call noundef i32 @_Z3queiii(i32 noundef %98, i32 noundef %99, i32 noundef %100)
  store i32 %101, ptr %11, align 4, !tbaa !5
  %102 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %103 = load i32, ptr %102, align 4, !tbaa !5
  store i32 %103, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %104

104:                                              ; preds = %95, %79
  %105 = load i32, ptr %7, align 4, !tbaa !5
  %106 = load i32, ptr %9, align 4, !tbaa !5
  %107 = icmp sgt i32 %105, %106
  br i1 %107, label %108, label %117

108:                                              ; preds = %104
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %109 = load i32, ptr %5, align 4, !tbaa !5
  %110 = mul nsw i32 2, %109
  %111 = add nsw i32 %110, 2
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = load i32, ptr %7, align 4, !tbaa !5
  %114 = call noundef i32 @_Z3queiii(i32 noundef %111, i32 noundef %112, i32 noundef %113)
  store i32 %114, ptr %12, align 4, !tbaa !5
  %115 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %116 = load i32, ptr %115, align 4, !tbaa !5
  store i32 %116, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %117

117:                                              ; preds = %108, %104
  %118 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %118, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %119

119:                                              ; preds = %117, %28
  %120 = load i32, ptr %4, align 4
  ret i32 %120
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 0}
!10 = !{!"_ZTS3Seg", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, 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.Seg = type { i32, i32, i32, i32 }

@S = external dso_local local_unnamed_addr global [400009 x %struct.Seg], align 16

; 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 #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3queiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %7
  %9 = load i32, ptr %8, align 16, !tbaa !5
  %.not = icmp slt i32 %9, %1
  br i1 %.not, label %16, label %10

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %8, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %.not31 = icmp sgt i32 %12, %2
  br i1 %.not31, label %16, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %8, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !11
  br label %54

16:                                               ; preds = %10, %3
  %17 = getelementptr inbounds i8, ptr %8, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %.not32 = icmp eq i32 %18, 0
  br i1 %.not32, label %32, label %19

19:                                               ; preds = %16
  %20 = shl nsw i32 %0, 1
  %21 = or disjoint i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  store i32 %18, ptr %24, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %23, i64 12
  store i32 %18, ptr %25, align 4, !tbaa !13
  %26 = load i32, ptr %17, align 4, !tbaa !12
  %27 = add nsw i32 %20, 2
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %28
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  store i32 %26, ptr %30, align 8, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %29, i64 12
  store i32 %26, ptr %31, align 4, !tbaa !13
  store i32 0, ptr %17, align 4, !tbaa !12
  br label %32

32:                                               ; preds = %19, %16
  %33 = getelementptr inbounds i8, ptr %8, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !10
  %35 = add nsw i32 %34, %9
  %36 = sdiv i32 %35, 2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 0, ptr %4, align 4, !tbaa !12
  %.not33 = icmp slt i32 %36, %1
  br i1 %.not33, label %43, label %37

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %38 = shl nsw i32 %0, 1
  %39 = or disjoint i32 %38, 1
  %40 = tail call noundef i32 @_Z3queiii(i32 noundef %39, i32 noundef %1, i32 noundef %2)
  store i32 %40, ptr %5, align 4, !tbaa !12
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %42 = load i32, ptr %41, align 4, !tbaa !12
  store i32 %42, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %43

43:                                               ; preds = %37, %32
  %44 = phi i32 [ %42, %37 ], [ 0, %32 ]
  %45 = icmp slt i32 %36, %2
  br i1 %45, label %46, label %52

46:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %47 = shl nsw i32 %0, 1
  %48 = add nsw i32 %47, 2
  %49 = call noundef i32 @_Z3queiii(i32 noundef %48, i32 noundef %1, i32 noundef %2)
  store i32 %49, ptr %6, align 4, !tbaa !12
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %51 = load i32, ptr %50, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %52

52:                                               ; preds = %46, %43
  %53 = phi i32 [ %51, %46 ], [ %44, %43 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %54

54:                                               ; preds = %52, %13
  %.0 = phi i32 [ %15, %13 ], [ %53, %52 ]
  ret i32 %.0
}

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_ZTS3Seg", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 12}


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