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

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

@delta = external dso_local global i32, align 4
@dis = external dso_local global [55 x [110 x i64]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3updiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %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
  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
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load i32, ptr @delta, align 4, !tbaa !5
  %14 = sub nsw i32 0, %13
  store i32 %14, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %15 = load i32, ptr @delta, align 4, !tbaa !5
  %16 = sub nsw i32 0, %15
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = sub nsw i32 %16, %17
  store i32 %18, ptr %11, align 4, !tbaa !5
  %19 = 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)
  %20 = load i32, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  store i32 %20, ptr %9, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %90, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  store i32 %24, ptr %12, align 4, !tbaa !5
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr @delta, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br i1 %28, label %30, label %29

29:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %93

30:                                               ; preds = %21
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %32
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr @delta, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [110 x i64], ptr %33, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = icmp ne i64 %39, 4557430888798830399
  br i1 %40, label %41, label %89

41:                                               ; preds = %30
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %43
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = load i32, ptr @delta, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [110 x i64], ptr %44, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %54
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr @delta, align 4, !tbaa !5
  %58 = add nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [110 x i64], ptr %55, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = add nsw i64 %61, %63
  %65 = icmp sgt i64 %52, %64
  br i1 %65, label %66, label %89

66:                                               ; preds = %41
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %68
  %70 = load i32, ptr %9, align 4, !tbaa !5
  %71 = load i32, ptr @delta, align 4, !tbaa !5
  %72 = add nsw i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [110 x i64], ptr %69, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = add nsw i64 %75, %77
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %80
  %82 = load i32, ptr %9, align 4, !tbaa !5
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = add nsw i32 %82, %83
  %85 = load i32, ptr @delta, align 4, !tbaa !5
  %86 = add nsw i32 %84, %85
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [110 x i64], ptr %81, i64 0, i64 %87
  store i64 %78, ptr %88, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %66, %41, %30
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %9, align 4, !tbaa !5
  br label %21, !llvm.loop !11

93:                                               ; preds = %29
  ret void
}

; 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 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@delta = external dso_local local_unnamed_addr global i32, align 4
@dis = external dso_local local_unnamed_addr global [55 x [110 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3updiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %9 = load i32, ptr @delta, align 4, !tbaa !5
  %10 = sub nsw i32 0, %9
  store i32 %10, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %11 = add i32 %9, %2
  %12 = sub i32 0, %11
  store i32 %12, ptr %7, align 4, !tbaa !5
  %13 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %14 = load i32, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  store i32 %14, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %15 = add nsw i32 %14, %2
  store i32 %15, ptr %8, align 4, !tbaa !5
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr @delta, align 4, !tbaa !5
  %.not13 = icmp sgt i32 %17, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %19 = sext i32 %1 to i64
  %20 = sext i32 %0 to i64
  %21 = sext i32 %3 to i64
  br label %22

._crit_edge:                                      ; preds = %38, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret void

22:                                               ; preds = %.lr.ph, %38
  %23 = phi i32 [ %18, %.lr.ph ], [ %43, %38 ]
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = add nsw i32 %24, %23
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %19, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %.not12 = icmp eq i64 %28, 4557430888798830399
  br i1 %.not12, label %38, label %29

29:                                               ; preds = %22
  %30 = add i32 %23, %2
  %31 = add i32 %30, %24
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [55 x [110 x i64]], ptr @dis, i64 0, i64 %20, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = add nsw i64 %28, %21
  %36 = icmp sgt i64 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %29
  store i64 %35, ptr %33, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %22, %29, %37
  %39 = add nsw i32 %24, 1
  store i32 %39, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %40 = add nsw i32 %39, %2
  store i32 %40, ptr %8, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr @delta, align 4, !tbaa !5
  %.not = icmp sgt i32 %42, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  br i1 %.not, label %._crit_edge, label %22, !llvm.loop !11
}

; Function Attrs: mustprogress 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 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 #2

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass