; LLVM IR from alexzheng42/sDMD :: src (CBT)

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

@CBT = external global %struct.EventListStr, align 8

; 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: nounwind uwtable
define dso_local void @InsertCBTRun(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %5 = load i32, ptr @CBT, align 8, !tbaa !9
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %13

7:                                                ; preds = %1
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %10 = getelementptr inbounds i32, ptr %9, i64 1
  store i32 %8, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr @CBT, align 8, !tbaa !9
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @CBT, align 8, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %48

13:                                               ; preds = %1
  %14 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %15 = load i32, ptr @CBT, align 8, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr %14, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %21 = load i32, ptr @CBT, align 8, !tbaa !9
  %22 = mul nsw i32 %21, 2
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %20, i64 %23
  store i32 %19, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %27 = load i32, ptr @CBT, align 8, !tbaa !9
  %28 = mul nsw i32 %27, 2
  %29 = add nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %26, i64 %30
  store i32 %25, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr @CBT, align 8, !tbaa !9
  %33 = mul nsw i32 %32, 2
  %34 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  store i32 %33, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr @CBT, align 8, !tbaa !9
  %39 = mul nsw i32 %38, 2
  %40 = add nsw i32 %39, 1
  %41 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  store i32 %40, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr @CBT, align 8, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @CBT, align 8, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !5
  call void @UpdateCBTRun(i32 noundef %47)
  store i32 1, ptr %4, align 4
  br label %48

48:                                               ; preds = %13, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @UpdateCBTRun(i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"EventListStr", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}


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

@CBT = external local_unnamed_addr global %struct.EventListStr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @InsertCBTRun(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @CBT, align 8, !tbaa !5
  %3 = icmp eq i32 %2, 0
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 8), align 8, !tbaa !11
  br i1 %3, label %5, label %7

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %0, ptr %6, align 4, !tbaa !12
  store i32 1, ptr @CBT, align 8, !tbaa !5
  br label %31

7:                                                ; preds = %1
  %8 = sext i32 %2 to i64
  %9 = getelementptr inbounds i32, ptr %4, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = shl nsw i32 %2, 1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr %4, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !12
  %14 = load i32, ptr @CBT, align 8, !tbaa !5
  %15 = shl nsw i32 %14, 1
  %16 = or disjoint i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %4, i64 %17
  store i32 %0, ptr %18, align 4, !tbaa !12
  %19 = load i32, ptr @CBT, align 8, !tbaa !5
  %20 = shl nsw i32 %19, 1
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 16), align 8, !tbaa !13
  %22 = sext i32 %10 to i64
  %23 = getelementptr inbounds i32, ptr %21, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !12
  %24 = load i32, ptr @CBT, align 8, !tbaa !5
  %25 = shl nsw i32 %24, 1
  %26 = or disjoint i32 %25, 1
  %27 = sext i32 %0 to i64
  %28 = getelementptr inbounds i32, ptr %21, i64 %27
  store i32 %26, ptr %28, align 4, !tbaa !12
  %29 = load i32, ptr @CBT, align 8, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @CBT, align 8, !tbaa !5
  tail call void @UpdateCBTRun(i32 noundef %10)
  br label %31

31:                                               ; preds = %7, %5
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @UpdateCBTRun(i32 noundef) local_unnamed_addr #0

attributes #0 = { 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, !7, i64 0}
!6 = !{!"EventListStr", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 16}


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