; LLVM IR from tangjz/acm-icpc :: lydsy/4540.ll (Z8addEventiiii)

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

@n = external dso_local global i32, align 4
@etot = external dso_local global i32, align 4
@ord = external dso_local global [800009 x i32], align 16
@eve = external dso_local global [800009 x %struct.Event], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8addEventiiii(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 %struct.Event, align 8
  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
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %26, label %12

12:                                               ; preds = %4
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %26, label %16

16:                                               ; preds = %12
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 1
  br i1 %18, label %26, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp sgt i32 %20, %21
  br i1 %22, label %26, label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23, %19, %16, %12, %4
  br label %45

27:                                               ; preds = %23
  %28 = load i32, ptr @etot, align 4, !tbaa !5
  %29 = load i32, ptr @etot, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [800009 x i32], ptr @ord, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #3
  %32 = getelementptr inbounds %struct.Event, ptr %9, i32 0, i32 0
  %33 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %33, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.Event, ptr %9, i32 0, i32 1
  %35 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %35, ptr %34, align 4, !tbaa !12
  %36 = getelementptr inbounds %struct.Event, ptr %9, i32 0, i32 2
  %37 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %37, ptr %36, align 8, !tbaa !13
  %38 = getelementptr inbounds %struct.Event, ptr %9, i32 0, i32 3
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  store i64 %40, ptr %38, align 8, !tbaa !14
  %41 = load i32, ptr @etot, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr @etot, align 4, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds [800009 x %struct.Event], ptr @eve, i64 0, i64 %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %9, i64 24, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #3
  br label %45

45:                                               ; preds = %27, %26
  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: 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

; Function Attrs: 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"_ZTS5Event", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !11, i64 16}
!15 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 16, i64 8, !16}
!16 = !{!11, !11, i64 0}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@etot = external dso_local local_unnamed_addr global i32, align 4
@ord = external dso_local local_unnamed_addr global [800009 x i32], align 16
@eve = external dso_local local_unnamed_addr global [800009 x %struct.Event], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z8addEventiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %1, 1
  br i1 %5, label %20, label %6

6:                                                ; preds = %4
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp slt i32 %7, %1
  %9 = icmp slt i32 %2, 1
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %20, label %10

10:                                               ; preds = %6
  %11 = icmp uge i32 %7, %2
  %12 = icmp ne i32 %3, 0
  %or.cond3 = and i1 %12, %11
  br i1 %or.cond3, label %13, label %20

13:                                               ; preds = %10
  %14 = load i32, ptr @etot, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [800009 x i32], ptr @ord, i64 0, i64 %15
  store i32 %14, ptr %16, align 4, !tbaa !5
  %17 = sext i32 %3 to i64
  %18 = add nsw i32 %14, 1
  store i32 %18, ptr @etot, align 4, !tbaa !5
  %19 = getelementptr inbounds [800009 x %struct.Event], ptr @eve, i64 0, i64 %15
  store i32 %0, ptr %19, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 4
  store i32 %1, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 8
  store i32 %2, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.64.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 16
  store i64 %17, ptr %.sroa.64.0..sroa_idx, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %4, %6, %10, %13
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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