; LLVM IR from cashapp/zipline :: zipline/native/common (finalization-registry)

; 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.JSClassDef = type { ptr, ptr, ptr, ptr, ptr }
%struct.JSValue = type { %union.JSValueUnion, i64 }
%union.JSValueUnion = type { double }

@finalizerClassId = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [492 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @installFinalizationRegistry(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.JSClassDef, align 8
  %9 = alloca %struct.JSValue, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.JSValue, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call ptr @JS_GetRuntime(ptr noundef %12)
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load i32, ptr @finalizerClassId, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %2
  %17 = call i32 @JS_NewClassID(ptr noundef @finalizerClassId)
  br label %18

18:                                               ; preds = %16, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store ptr @.str, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call i32 @compileAndExecuteJs(ptr noundef %19, ptr noundef %20, ptr noundef %21)
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %24, %18
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 40, i1 false)
  %26 = getelementptr inbounds %struct.JSClassDef, ptr %8, i32 0, i32 0
  store ptr @.str.1, ptr %26, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.JSClassDef, ptr %8, i32 0, i32 1
  store ptr @jsFinalizerCollected, ptr %27, align 8, !tbaa !13
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr @finalizerClassId, align 4, !tbaa !9
  %30 = call i32 @JS_NewClass(ptr noundef %28, i32 noundef %29, ptr noundef %8)
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %32, %25
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = call { i64, i64 } @JS_GetGlobalObject(ptr noundef %34)
  %36 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %37 = extractvalue { i64, i64 } %35, 0
  store i64 %37, ptr %36, align 8
  %38 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %39 = extractvalue { i64, i64 } %35, 1
  store i64 %39, ptr %38, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = call i32 @JS_NewAtom(ptr noundef %40, ptr noundef @.str.2)
  store i32 %41, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call { i64, i64 } @JS_NewCFunction(ptr noundef %42, ptr noundef @jsNewFinalizer, ptr noundef @.str.2, i32 noundef 1)
  %44 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %45 = extractvalue { i64, i64 } %43, 0
  store i64 %45, ptr %44, align 8
  %46 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %47 = extractvalue { i64, i64 } %43, 1
  store i64 %47, ptr %46, align 8
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %51 = load i64, ptr %50, align 8
  %52 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %53 = load i64, ptr %52, align 8
  %54 = call i32 @JS_HasProperty(ptr noundef %48, i64 %51, i64 %53, i32 noundef %49)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %69, label %56

56:                                               ; preds = %33
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %60 = load i64, ptr %59, align 8
  %61 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %62 = load i64, ptr %61, align 8
  %63 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %64 = load i64, ptr %63, align 8
  %65 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %66 = load i64, ptr %65, align 8
  %67 = call i32 @JS_SetProperty(ptr noundef %57, i64 %60, i64 %62, i32 noundef %58, i64 %64, i64 %66)
  %68 = icmp slt i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %56, %33
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %69, %56
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load i32, ptr %10, align 4, !tbaa !9
  call void @JS_FreeAtom(ptr noundef %71, i32 noundef %72)
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %75 = load i64, ptr %74, align 8
  %76 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %77 = load i64, ptr %76, align 8
  call void @JS_FreeValue(ptr noundef %73, i64 %75, i64 %77)
  %78 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %78
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @JS_GetRuntime(ptr noundef) #2

declare i32 @JS_NewClassID(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @compileAndExecuteJs(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden void @jsFinalizerCollected(ptr noundef, i64, i64) #0

declare i32 @JS_NewClass(ptr noundef, i32 noundef, ptr noundef) #2

declare { i64, i64 } @JS_GetGlobalObject(ptr noundef) #2

declare i32 @JS_NewAtom(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @JS_NewCFunction(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
declare hidden { i64, i64 } @jsNewFinalizer(ptr noundef, i64, i64, i32 noundef, ptr noundef) #0

declare i32 @JS_HasProperty(ptr noundef, i64, i64, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @JS_SetProperty(ptr noundef, i64, i64, i32 noundef, i64, i64) #4

declare void @JS_FreeAtom(ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @JS_FreeValue(ptr noundef, i64, i64) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"JSClassDef", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 8}


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

@finalizerClassId = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [492 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @installFinalizationRegistry(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.JSClassDef, align 8
  %4 = tail call ptr @JS_GetRuntime(ptr noundef %0) #5
  %5 = load i32, ptr @finalizerClassId, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %2
  %8 = tail call i32 @JS_NewClassID(ptr noundef nonnull @finalizerClassId) #5
  br label %9

9:                                                ; preds = %7, %2
  %10 = tail call i32 @compileAndExecuteJs(ptr noundef %0, ptr noundef %1, ptr noundef nonnull @.str)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #5
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %11, i8 0, i64 24, i1 false)
  store ptr @.str.1, ptr %3, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr @jsFinalizerCollected, ptr %12, align 8, !tbaa !12
  %13 = load i32, ptr @finalizerClassId, align 4, !tbaa !5
  %14 = call i32 @JS_NewClass(ptr noundef %4, i32 noundef %13, ptr noundef nonnull %3) #5
  %15 = call { i64, i64 } @JS_GetGlobalObject(ptr noundef %0) #5
  %16 = extractvalue { i64, i64 } %15, 0
  %17 = extractvalue { i64, i64 } %15, 1
  %18 = call i32 @JS_NewAtom(ptr noundef %0, ptr noundef nonnull @.str.2) #5
  %19 = call { i64, i64 } @JS_NewCFunction(ptr noundef %0, ptr noundef nonnull @jsNewFinalizer, ptr noundef nonnull @.str.2, i32 noundef 1)
  %20 = call i32 @JS_HasProperty(ptr noundef %0, i64 %16, i64 %17, i32 noundef %18) #5
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %21, label %27

21:                                               ; preds = %9
  %.inv = icmp sgt i32 %10, -1
  %.inv20 = icmp sgt i32 %14, -1
  %22 = select i1 %.inv20, i1 %.inv, i1 false
  %.1 = select i1 %22, i32 1, i32 -1
  %23 = extractvalue { i64, i64 } %19, 1
  %24 = extractvalue { i64, i64 } %19, 0
  %25 = call i32 @JS_SetProperty(ptr noundef %0, i64 %16, i64 %17, i32 noundef %18, i64 %24, i64 %23)
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21, %9
  br label %28

28:                                               ; preds = %27, %21
  %.2 = phi i32 [ -1, %27 ], [ %.1, %21 ]
  call void @JS_FreeAtom(ptr noundef %0, i32 noundef %18) #5
  call void @JS_FreeValue(ptr noundef %0, i64 %16, i64 %17)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #5
  ret i32 %.2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @JS_GetRuntime(ptr noundef) local_unnamed_addr #2

declare i32 @JS_NewClassID(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @compileAndExecuteJs(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden void @jsFinalizerCollected(ptr noundef, i64, i64) #0

declare i32 @JS_NewClass(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare { i64, i64 } @JS_GetGlobalObject(ptr noundef) local_unnamed_addr #2

declare i32 @JS_NewAtom(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @JS_NewCFunction(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden { i64, i64 } @jsNewFinalizer(ptr noundef, i64, i64, i32 noundef, ptr noundef) #0

declare i32 @JS_HasProperty(ptr noundef, i64, i64, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @JS_SetProperty(ptr noundef, i64, i64, i32 noundef, i64, i64) local_unnamed_addr #4

declare void @JS_FreeAtom(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @JS_FreeValue(ptr noundef, i64, i64) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { 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, !11, i64 0}
!10 = !{!"JSClassDef", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass