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

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

@seg = external dso_local global [200004 x %struct.Segment], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3updiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %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 [200004 x %struct.Segment], ptr @seg, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Segment, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !9
  %33 = add nsw i32 %32, %27
  store i32 %33, ptr %31, align 8, !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 [200004 x %struct.Segment], ptr @seg, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Segment, ptr %37, i32 0, i32 1
  %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 %144

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 = sext i32 %53 to i64
  %55 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.Segment, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !11
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %108

59:                                               ; preds = %41
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.Segment, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !11
  %65 = load i32, ptr %14, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.Segment, ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !9
  %70 = add nsw i32 %69, %64
  store i32 %70, ptr %68, align 8, !tbaa !9
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.Segment, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !11
  %76 = load i32, ptr %14, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.Segment, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !11
  %81 = add nsw i32 %80, %75
  store i32 %81, ptr %79, align 4, !tbaa !11
  %82 = load i32, ptr %11, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.Segment, ptr %84, i32 0, i32 1
  %86 = load i32, ptr %85, align 4, !tbaa !11
  %87 = load i32, ptr %15, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %88
  %90 = getelementptr inbounds %struct.Segment, ptr %89, i32 0, i32 0
  %91 = load i32, ptr %90, align 8, !tbaa !9
  %92 = add nsw i32 %91, %86
  store i32 %92, ptr %90, align 8, !tbaa !9
  %93 = load i32, ptr %11, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.Segment, ptr %95, i32 0, i32 1
  %97 = load i32, ptr %96, align 4, !tbaa !11
  %98 = load i32, ptr %15, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.Segment, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 4, !tbaa !11
  %103 = add nsw i32 %102, %97
  store i32 %103, ptr %101, align 4, !tbaa !11
  %104 = load i32, ptr %11, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %105
  %107 = getelementptr inbounds %struct.Segment, ptr %106, i32 0, i32 1
  store i32 0, ptr %107, align 4, !tbaa !11
  br label %108

108:                                              ; preds = %59, %41
  %109 = load i32, ptr %8, align 4, !tbaa !5
  %110 = load i32, ptr %13, align 4, !tbaa !5
  %111 = icmp sle i32 %109, %110
  br i1 %111, label %112, label %118

112:                                              ; preds = %108
  %113 = load i32, ptr %6, align 4, !tbaa !5
  %114 = load i32, ptr %13, align 4, !tbaa !5
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = load i32, ptr %9, align 4, !tbaa !5
  %117 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z3updiiiii(i32 noundef %113, i32 noundef %114, i32 noundef %115, i32 noundef %116, i32 noundef %117)
  br label %118

118:                                              ; preds = %112, %108
  %119 = load i32, ptr %9, align 4, !tbaa !5
  %120 = load i32, ptr %13, align 4, !tbaa !5
  %121 = icmp sgt i32 %119, %120
  br i1 %121, label %122, label %129

122:                                              ; preds = %118
  %123 = load i32, ptr %13, align 4, !tbaa !5
  %124 = add nsw i32 %123, 1
  %125 = load i32, ptr %7, align 4, !tbaa !5
  %126 = load i32, ptr %8, align 4, !tbaa !5
  %127 = load i32, ptr %9, align 4, !tbaa !5
  %128 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z3updiiiii(i32 noundef %124, i32 noundef %125, i32 noundef %126, i32 noundef %127, i32 noundef %128)
  br label %129

129:                                              ; preds = %122, %118
  %130 = load i32, ptr %14, align 4, !tbaa !5
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %131
  %133 = getelementptr inbounds %struct.Segment, ptr %132, i32 0, i32 0
  %134 = load i32, ptr %15, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %135
  %137 = getelementptr inbounds %struct.Segment, ptr %136, i32 0, i32 0
  %138 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %133, ptr noundef nonnull align 4 dereferenceable(4) %137)
  %139 = load i32, ptr %138, align 4, !tbaa !5
  %140 = load i32, ptr %11, align 4, !tbaa !5
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %141
  %143 = getelementptr inbounds %struct.Segment, ptr %142, i32 0, i32 0
  store i32 %139, ptr %143, align 8, !tbaa !9
  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 %144

144:                                              ; preds = %129, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %145 = load i32, ptr %12, align 4
  switch i32 %145, label %147 [
    i32 0, label %146
    i32 1, label %146
  ]

146:                                              ; preds = %144, %144
  ret void

147:                                              ; preds = %144
  unreachable
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


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

@seg = external dso_local global [200004 x %struct.Segment], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3updiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not = icmp sgt i32 %2, %0
  %.not46 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not46
  br i1 %or.cond, label %14, label %7

7:                                                ; preds = %5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %8
  %10 = load <2 x i32>, ptr %9, align 8, !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 8, !tbaa !5
  br label %50

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)
  %20 = sext i32 %6 to i64
  %21 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %.not47 = icmp eq i32 %23, 0
  br i1 %.not47, label %38, label %24

24:                                               ; preds = %14
  %25 = sext i32 %17 to i64
  %26 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %25
  %27 = load <2 x i32>, ptr %26, align 8, !tbaa !5
  %28 = insertelement <2 x i32> poison, i32 %23, i64 0
  %29 = shufflevector <2 x i32> %28, <2 x i32> poison, <2 x i32> zeroinitializer
  %30 = add nsw <2 x i32> %27, %29
  store <2 x i32> %30, ptr %26, align 8, !tbaa !5
  %31 = load i32, ptr %22, align 4, !tbaa !9
  %32 = sext i32 %19 to i64
  %33 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %32
  %34 = load <2 x i32>, ptr %33, align 8, !tbaa !5
  %35 = insertelement <2 x i32> poison, i32 %31, i64 0
  %36 = shufflevector <2 x i32> %35, <2 x i32> poison, <2 x i32> zeroinitializer
  %37 = add nsw <2 x i32> %34, %36
  store <2 x i32> %37, ptr %33, align 8, !tbaa !5
  store i32 0, ptr %22, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %24, %14
  %.not48 = icmp slt i32 %16, %2
  br i1 %.not48, label %40, label %39

39:                                               ; preds = %38
  tail call void @_Z3updiiiii(i32 noundef %0, i32 noundef %16, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %40

40:                                               ; preds = %39, %38
  %41 = icmp slt i32 %16, %3
  br i1 %41, label %42, label %43

42:                                               ; preds = %40
  tail call void @_Z3updiiiii(i32 noundef %18, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %43

43:                                               ; preds = %42, %40
  %44 = sext i32 %17 to i64
  %45 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %44
  %46 = sext i32 %19 to i64
  %47 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %46
  %48 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %45, ptr noundef nonnull align 4 dereferenceable(4) %47)
  %49 = load i32, ptr %48, align 4, !tbaa !5
  store i32 %49, ptr %21, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %43, %7
  ret void
}

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

; 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, !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}
!11 = !{!10, !6, i64 0}


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