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

; 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.Operation = type { i32, i32, i32, i32 }

@n = external dso_local global i32, align 4
@fa = external dso_local global [50001 x i32], align 16
@in = external dso_local global ptr, align 8
@out = external dso_local global ptr, align 8
@top = external dso_local global ptr, align 8
@qtim = external dso_local global i32, align 4
@qtot = external dso_local global i32, align 4
@que = external dso_local global [1700017 x %struct.Operation], 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Operation, align 4
  %8 = alloca %struct.Operation, align 4
  %9 = alloca %struct.Operation, 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
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %46

12:                                               ; preds = %3
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = load ptr, ptr @in, align 8, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load ptr, ptr @in, align 8, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %14, i32 noundef %19, i32 noundef %24, i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %26 = getelementptr inbounds %struct.Operation, ptr %7, i32 0, i32 0
  %27 = load i32, ptr @qtim, align 4, !tbaa !5
  store i32 %27, ptr %26, align 4, !tbaa !11
  %28 = getelementptr inbounds %struct.Operation, ptr %7, i32 0, i32 1
  %29 = load ptr, ptr @in, align 8, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %28, align 4, !tbaa !13
  %34 = getelementptr inbounds %struct.Operation, ptr %7, i32 0, i32 2
  %35 = load ptr, ptr @in, align 8, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr %34, align 4, !tbaa !14
  %40 = getelementptr inbounds %struct.Operation, ptr %7, i32 0, i32 3
  %41 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %41, ptr %40, align 4, !tbaa !15
  %42 = load i32, ptr @qtot, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @qtot, align 4, !tbaa !5
  %44 = sext i32 %42 to i64
  %45 = getelementptr inbounds [1700017 x %struct.Operation], ptr @que, i64 0, i64 %44
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %45, ptr align 4 %7, i64 16, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %140

46:                                               ; preds = %3
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = icmp eq i32 %47, 2
  br i1 %48, label %49, label %83

49:                                               ; preds = %46
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = load ptr, ptr @in, align 8, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load ptr, ptr @out, align 8, !tbaa !9
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %51, i32 noundef %56, i32 noundef %61, i32 noundef %62)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  %63 = getelementptr inbounds %struct.Operation, ptr %8, i32 0, i32 0
  %64 = load i32, ptr @qtim, align 4, !tbaa !5
  store i32 %64, ptr %63, align 4, !tbaa !11
  %65 = getelementptr inbounds %struct.Operation, ptr %8, i32 0, i32 1
  %66 = load ptr, ptr @in, align 8, !tbaa !9
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  store i32 %70, ptr %65, align 4, !tbaa !13
  %71 = getelementptr inbounds %struct.Operation, ptr %8, i32 0, i32 2
  %72 = load ptr, ptr @out, align 8, !tbaa !9
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %72, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  store i32 %76, ptr %71, align 4, !tbaa !14
  %77 = getelementptr inbounds %struct.Operation, ptr %8, i32 0, i32 3
  %78 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %78, ptr %77, align 4, !tbaa !15
  %79 = load i32, ptr @qtot, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr @qtot, align 4, !tbaa !5
  %81 = sext i32 %79 to i64
  %82 = getelementptr inbounds [1700017 x %struct.Operation], ptr @que, i64 0, i64 %81
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %82, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  br label %139

83:                                               ; preds = %46
  br label %84

84:                                               ; preds = %129, %83
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = icmp ne i32 %85, -1
  br i1 %86, label %87, label %138

87:                                               ; preds = %84
  %88 = load i32, ptr @n, align 4, !tbaa !5
  %89 = sub nsw i32 %88, 1
  %90 = load ptr, ptr @in, align 8, !tbaa !9
  %91 = load ptr, ptr @top, align 8, !tbaa !9
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i32, ptr %91, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds i32, ptr %90, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = load ptr, ptr @in, align 8, !tbaa !9
  %100 = load i32, ptr %5, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i32, ptr %99, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %89, i32 noundef %98, i32 noundef %103, i32 noundef %104)
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  %105 = getelementptr inbounds %struct.Operation, ptr %9, i32 0, i32 0
  %106 = load i32, ptr @qtim, align 4, !tbaa !5
  store i32 %106, ptr %105, align 4, !tbaa !11
  %107 = getelementptr inbounds %struct.Operation, ptr %9, i32 0, i32 1
  %108 = load ptr, ptr @in, align 8, !tbaa !9
  %109 = load ptr, ptr @top, align 8, !tbaa !9
  %110 = load i32, ptr %5, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i32, ptr %109, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds i32, ptr %108, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  store i32 %116, ptr %107, align 4, !tbaa !13
  %117 = getelementptr inbounds %struct.Operation, ptr %9, i32 0, i32 2
  %118 = load ptr, ptr @in, align 8, !tbaa !9
  %119 = load i32, ptr %5, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds i32, ptr %118, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  store i32 %122, ptr %117, align 4, !tbaa !14
  %123 = getelementptr inbounds %struct.Operation, ptr %9, i32 0, i32 3
  %124 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %124, ptr %123, align 4, !tbaa !15
  %125 = load i32, ptr @qtot, align 4, !tbaa !5
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr @qtot, align 4, !tbaa !5
  %127 = sext i32 %125 to i64
  %128 = getelementptr inbounds [1700017 x %struct.Operation], ptr @que, i64 0, i64 %127
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %128, ptr align 4 %9, i64 16, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br label %129

129:                                              ; preds = %87
  %130 = load ptr, ptr @top, align 8, !tbaa !9
  %131 = load i32, ptr %5, align 4, !tbaa !5
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds i32, ptr %130, i64 %132
  %134 = load i32, ptr %133, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [50001 x i32], ptr @fa, i64 0, i64 %135
  %137 = load i32, ptr %136, align 4, !tbaa !5
  store i32 %137, ptr %5, align 4, !tbaa !5
  br label %84, !llvm.loop !17

138:                                              ; preds = %84
  br label %139

139:                                              ; preds = %138, %49
  br label %140

140:                                              ; preds = %139, %12
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS9Operation", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 12}
!16 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.Operation = type { i32, i32, i32, i32 }

@n = external dso_local local_unnamed_addr global i32, align 4
@fa = external dso_local local_unnamed_addr global [50001 x i32], align 16
@in = external dso_local local_unnamed_addr global ptr, align 8
@out = external dso_local local_unnamed_addr global ptr, align 8
@top = external dso_local local_unnamed_addr global ptr, align 8
@qtim = external dso_local local_unnamed_addr global i32, align 4
@qtot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local local_unnamed_addr global [1700017 x %struct.Operation], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7seg_updiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  switch i32 %0, label %.preheader [
    i32 1, label %4
    i32 2, label %14
  ]

.preheader:                                       ; preds = %3
  %.not31 = icmp eq i32 %1, -1
  br i1 %.not31, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre = load ptr, ptr @in, align 8, !tbaa !5
  %.pre33 = load ptr, ptr @top, align 8, !tbaa !5
  br label %.lr.ph

4:                                                ; preds = %3
  %5 = load i32, ptr @n, align 4, !tbaa !9
  %6 = add nsw i32 %5, -1
  %7 = load ptr, ptr @in, align 8, !tbaa !5
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds i32, ptr %7, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !9
  tail call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %6, i32 noundef %10, i32 noundef %10, i32 noundef %2)
  %11 = load ptr, ptr @in, align 8, !tbaa !5
  %12 = getelementptr inbounds i32, ptr %11, i64 %8
  %13 = load i32, ptr %12, align 4, !tbaa !9
  br label %.loopexit.sink.split

14:                                               ; preds = %3
  %15 = load i32, ptr @n, align 4, !tbaa !9
  %16 = add nsw i32 %15, -1
  %17 = load ptr, ptr @in, align 8, !tbaa !5
  %18 = sext i32 %1 to i64
  %19 = getelementptr inbounds i32, ptr %17, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load ptr, ptr @out, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 %18
  %23 = load i32, ptr %22, align 4, !tbaa !9
  tail call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %16, i32 noundef %20, i32 noundef %23, i32 noundef %2)
  %24 = load ptr, ptr @in, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i64 %18
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load ptr, ptr @out, align 8, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %27, i64 %18
  %29 = load i32, ptr %28, align 4, !tbaa !9
  br label %.loopexit.sink.split

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %30 = phi ptr [ %44, %.lr.ph ], [ %.pre33, %.lr.ph.preheader ]
  %31 = phi ptr [ %43, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.032 = phi i32 [ %59, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %32 = load i32, ptr @n, align 4, !tbaa !9
  %33 = add nsw i32 %32, -1
  %34 = sext i32 %.032 to i64
  %35 = getelementptr inbounds i32, ptr %30, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %31, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = getelementptr inbounds i32, ptr %31, i64 %34
  %41 = load i32, ptr %40, align 4, !tbaa !9
  tail call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %33, i32 noundef %39, i32 noundef %41, i32 noundef %2)
  %42 = load i32, ptr @qtim, align 4, !tbaa !9
  %43 = load ptr, ptr @in, align 8, !tbaa !5
  %44 = load ptr, ptr @top, align 8, !tbaa !5
  %45 = getelementptr inbounds i32, ptr %44, i64 %34
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %43, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = getelementptr inbounds i32, ptr %43, i64 %34
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = load i32, ptr @qtot, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr @qtot, align 4, !tbaa !9
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds [1700017 x %struct.Operation], ptr @que, i64 0, i64 %54
  store i32 %42, ptr %55, align 16, !tbaa !9
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %55, i64 4
  store i32 %49, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !9
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %55, i64 8
  store i32 %51, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !9
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %55, i64 12
  store i32 %2, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !9
  %56 = load i32, ptr %45, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [50001 x i32], ptr @fa, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %.not = icmp eq i32 %59, -1
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

.loopexit.sink.split:                             ; preds = %4, %14
  %.sink36 = phi i32 [ %26, %14 ], [ %13, %4 ]
  %.sink34 = phi i32 [ %29, %14 ], [ %13, %4 ]
  %.sink38 = load i32, ptr @qtim, align 4, !tbaa !9
  %60 = load i32, ptr @qtot, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @qtot, align 4, !tbaa !9
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds [1700017 x %struct.Operation], ptr @que, i64 0, i64 %62
  store i32 %.sink38, ptr %63, align 16, !tbaa !9
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %63, i64 4
  store i32 %.sink36, ptr %.sroa.42.0..sroa_idx, align 4, !tbaa !9
  %.sroa.53.0..sroa_idx = getelementptr inbounds i8, ptr %63, i64 8
  store i32 %.sink34, ptr %.sroa.53.0..sroa_idx, align 8, !tbaa !9
  %.sroa.64.0..sroa_idx = getelementptr inbounds i8, ptr %63, i64 12
  store i32 %2, ptr %.sroa.64.0..sroa_idx, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.loopexit.sink.split, %.preheader
  ret void
}

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

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass