; LLVM IR from tangjz/acm-icpc :: 51nod/1555.ll (Z7seg_updiiiii)

; 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: mustprogress uwtable
define dso_local void @_Z7seg_updiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %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
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #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 %11, 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 %41

22:                                               ; preds = %5
  %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 %41

26:                                               ; preds = %22
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Segment, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = add nsw i32 %32, %27
  store i32 %33, ptr %31, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Segment, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = add nsw i32 %39, %34
  store i32 %40, ptr %38, align 4, !tbaa !11
  store i32 1, ptr %12, align 4
  br label %80

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

59:                                               ; preds = %41
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %13, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z7seg_updiiiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64)
  br label %65

65:                                               ; preds = %59, %41
  %66 = load i32, ptr %13, align 4, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %76

69:                                               ; preds = %65
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %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
  call void @_Z7seg_updiiiii(i32 noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75)
  br label %76

76:                                               ; preds = %69, %65
  %77 = load i32, ptr %11, align 4, !tbaa !5
  %78 = load i32, ptr %14, align 4, !tbaa !5
  %79 = load i32, ptr %15, align 4, !tbaa !5
  call void @_Z6seg_upiii(i32 noundef %77, i32 noundef %78, i32 noundef %79)
  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
  store i32 0, ptr %12, align 4
  br label %80

80:                                               ; preds = %76, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %81 = load i32, ptr %12, align 4
  switch i32 %81, label %83 [
    i32 0, label %82
    i32 1, label %82
  ]

82:                                               ; preds = %80, %80
  ret void

83:                                               ; preds = %80
  unreachable
}

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

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 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.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: mustprogress nounwind uwtable
define dso_local void @_Z7seg_updiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not = icmp sgt i32 %2, %0
  %.not38 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not38
  br i1 %or.cond, label %14, label %7

7:                                                ; preds = %5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [600001 x %struct.Segment], ptr @seg, i64 0, i64 %8, i32 1
  %10 = load <2 x i32>, ptr %9, align 4, !tbaa !5
  %11 = insertelement <2 x i32> poison, i32 %4, i64 0
  %12 = shufflevector <2 x i32> %11, <2 x i32> poison, <2 x i32> zeroinitializer
  %13 = add nsw <2 x i32> %10, %12
  store <2 x i32> %13, ptr %9, align 4, !tbaa !5
  br label %25

14:                                               ; preds = %5
  %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 %6, i32 noundef %17, i32 noundef %19)
  %.not39 = icmp slt i32 %16, %2
  br i1 %.not39, label %21, label %20

20:                                               ; preds = %14
  tail call void @_Z7seg_updiiiii(i32 noundef %0, i32 noundef %16, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %21

21:                                               ; preds = %20, %14
  %22 = icmp slt i32 %16, %3
  br i1 %22, label %23, label %24

23:                                               ; preds = %21
  tail call void @_Z7seg_updiiiii(i32 noundef %18, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %24

24:                                               ; preds = %23, %21
  tail call void @_Z6seg_upiii(i32 noundef %6, i32 noundef %17, i32 noundef %19)
  br label %25

25:                                               ; preds = %24, %7
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z8seg_downiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #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 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"}


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