; 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
declare dso_local void @UpdateCBTRun(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @DeleteCBTRun(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 slt i32 %5, 2
  br i1 %6, label %7, label %14

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

14:                                               ; preds = %1
  %15 = load i32, ptr @CBT, align 8, !tbaa !9
  %16 = mul nsw i32 %15, 2
  %17 = sub nsw i32 %16, 1
  store i32 %17, ptr %3, align 4, !tbaa !5
  %18 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %18, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %55

26:                                               ; preds = %14
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sdiv i32 %27, 2
  %29 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %30 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %30, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %29, i64 %36
  store i32 %28, ptr %37, align 4, !tbaa !5
  %38 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sdiv i32 %45, 2
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %44, i64 %47
  store i32 %43, ptr %48, align 4, !tbaa !5
  %49 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %49, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  call void @UpdateCBTRun(i32 noundef %54)
  br label %83

55:                                               ; preds = %14
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sdiv i32 %56, 2
  %58 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %59 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %58, i64 %64
  store i32 %57, ptr %65, align 4, !tbaa !5
  %66 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %67 = load i32, ptr %3, 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
  %71 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sdiv i32 %72, 2
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %71, i64 %74
  store i32 %70, ptr %75, align 4, !tbaa !5
  %76 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %76, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  call void @UpdateCBTRun(i32 noundef %80)
  %81 = load i32, ptr @CBT, align 8, !tbaa !9
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr @CBT, align 8, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %126

83:                                               ; preds = %26
  %84 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr %84, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = icmp ne i32 %88, %89
  br i1 %90, label %91, label %123

91:                                               ; preds = %83
  %92 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i32, ptr %92, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %98 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i32, ptr %98, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i32, ptr %97, i64 %103
  store i32 %96, ptr %104, align 4, !tbaa !5
  %105 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %106 = load i32, ptr %2, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds i32, ptr %105, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 2), align 8, !tbaa !13
  %111 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %112 = load i32, ptr %3, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds i32, ptr %111, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds i32, ptr %110, i64 %116
  store i32 %109, ptr %117, align 4, !tbaa !5
  %118 = load ptr, ptr getelementptr inbounds (%struct.EventListStr, ptr @CBT, i32 0, i32 1), align 8, !tbaa !12
  %119 = load i32, ptr %3, 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
  call void @UpdateCBTRun(i32 noundef %122)
  br label %123

123:                                              ; preds = %91, %83
  %124 = load i32, ptr @CBT, align 8, !tbaa !9
  %125 = add nsw i32 %124, -1
  store i32 %125, ptr @CBT, align 8, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %126

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

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
declare dso_local void @UpdateCBTRun(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @DeleteCBTRun(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @CBT, align 8, !tbaa !5
  %3 = icmp slt i32 %2, 2
  br i1 %3, label %4, label %8

4:                                                ; preds = %1
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 8), align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 0, ptr %6, align 4, !tbaa !12
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 16), align 8, !tbaa !13
  store i32 1, ptr %7, align 4, !tbaa !12
  br label %49

8:                                                ; preds = %1
  %9 = shl nuw nsw i32 %2, 1
  %10 = add nsw i32 %9, -1
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 8), align 8, !tbaa !11
  %12 = zext nneg i32 %9 to i64
  %13 = getelementptr i32, ptr %11, i64 %12
  %14 = getelementptr i8, ptr %13, i64 -8
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %.not = icmp eq i32 %15, %0
  %16 = lshr i32 %10, 1
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 16), align 8, !tbaa !13
  br i1 %.not, label %28, label %18

18:                                               ; preds = %8
  %19 = sext i32 %15 to i64
  %20 = getelementptr inbounds i32, ptr %17, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !12
  %21 = load i32, ptr %14, align 4, !tbaa !12
  %22 = zext nneg i32 %16 to i64
  %23 = getelementptr inbounds i32, ptr %11, i64 %22
  store i32 %21, ptr %23, align 4, !tbaa !12
  tail call void @UpdateCBTRun(i32 noundef %21)
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 8), align 8, !tbaa !11
  %25 = zext nneg i32 %10 to i64
  %26 = getelementptr inbounds i32, ptr %24, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %.not22 = icmp eq i32 %27, %0
  br i1 %.not22, label %49, label %37

28:                                               ; preds = %8
  %29 = zext nneg i32 %10 to i64
  %30 = getelementptr inbounds i32, ptr %11, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %17, i64 %32
  store i32 %16, ptr %33, align 4, !tbaa !12
  %34 = load i32, ptr %30, align 4, !tbaa !12
  %35 = zext nneg i32 %16 to i64
  %36 = getelementptr inbounds i32, ptr %11, i64 %35
  store i32 %34, ptr %36, align 4, !tbaa !12
  tail call void @UpdateCBTRun(i32 noundef %34)
  br label %49

37:                                               ; preds = %18
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @CBT, i64 16), align 8, !tbaa !13
  %39 = sext i32 %0 to i64
  %40 = getelementptr inbounds i32, ptr %38, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !12
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %24, i64 %42
  store i32 %27, ptr %43, align 4, !tbaa !12
  %44 = load i32, ptr %40, align 4, !tbaa !12
  %45 = load i32, ptr %26, align 4, !tbaa !12
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %38, i64 %46
  store i32 %44, ptr %47, align 4, !tbaa !12
  %48 = load i32, ptr %26, align 4, !tbaa !12
  tail call void @UpdateCBTRun(i32 noundef %48)
  br label %49

49:                                               ; preds = %18, %37, %28, %4
  %50 = load i32, ptr @CBT, align 8, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @CBT, align 8, !tbaa !5
  ret void
}

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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass