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

; 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: mustprogress uwtable
define dso_local void @_Z3coniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.Seg, ptr %10, i32 0, i32 0
  store i32 %7, ptr %11, align 16, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.Seg, ptr %15, i32 0, i32 1
  store i32 %12, ptr %16, align 4, !tbaa !11
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Seg, ptr %19, i32 0, i32 3
  store i32 0, ptr %20, align 4, !tbaa !12
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %3
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Seg, ptr %27, i32 0, i32 2
  store i32 0, ptr %28, align 8, !tbaa !13
  br label %65

29:                                               ; preds = %3
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = mul nsw i32 2, %30
  %32 = add nsw i32 %31, 1
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = sdiv i32 %36, 2
  call void @_Z3coniii(i32 noundef %32, i32 noundef %33, i32 noundef %37)
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = mul nsw i32 2, %38
  %40 = add nsw i32 %39, 2
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = sdiv i32 %43, 2
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3coniii(i32 noundef %40, i32 noundef %45, i32 noundef %46)
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = mul nsw i32 2, %47
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Seg, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = mul nsw i32 2, %53
  %55 = add nsw i32 %54, 2
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Seg, ptr %57, i32 0, i32 2
  %59 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %52, ptr noundef nonnull align 4 dereferenceable(4) %58)
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Seg, ptr %63, i32 0, i32 2
  store i32 %60, ptr %64, align 8, !tbaa !13
  br label %65

65:                                               ; preds = %29, %24
  ret void
}

; 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

attributes #0 = { 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 #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" }

!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 12}
!13 = !{!10, !6, i64 8}


; 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 global [400009 x %struct.Seg], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3coniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %4
  store i32 %1, ptr %5, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 %2, ptr %6, align 4, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 0, ptr %7, align 4, !tbaa !11
  %8 = icmp eq i32 %1, %2
  br i1 %8, label %common.ret, label %10

common.ret:                                       ; preds = %3, %10
  %.sink = phi i32 [ %22, %10 ], [ 0, %3 ]
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %.sink, ptr %9, align 8
  ret void

10:                                               ; preds = %3
  %11 = shl nsw i32 %0, 1
  %12 = or disjoint i32 %11, 1
  %13 = add nsw i32 %2, %1
  %14 = sdiv i32 %13, 2
  tail call void @_Z3coniii(i32 noundef %12, i32 noundef %1, i32 noundef %14)
  %15 = add nsw i32 %11, 2
  %16 = add nsw i32 %14, 1
  tail call void @_Z3coniii(i32 noundef %15, i32 noundef %16, i32 noundef %2)
  %17 = sext i32 %12 to i64
  %18 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %17, i32 2
  %19 = sext i32 %15 to i64
  %20 = getelementptr inbounds [400009 x %struct.Seg], ptr @S, i64 0, i64 %19, i32 2
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %18, ptr noundef nonnull align 4 dereferenceable(4) %20)
  %22 = load i32, ptr %21, align 4, !tbaa !12
  br label %common.ret
}

; 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

attributes #0 = { 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 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 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 12}
!12 = !{!7, !7, i64 0}


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