; LLVM IR from marcobambini/gravity :: src/compiler (gravity_compiler)

; 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.gravity_compiler_t = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.void_r = type { i64, i64, ptr }
%struct.gravity_class_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, i8, i8, i8, i8, ptr, ptr, ptr, ptr, i32, ptr }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%struct.gravity_closure_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, ptr, ptr, i32 }
%struct.gravity_function_t = type { ptr, %struct.gravity_gc_s, ptr, ptr, i16, i16, i16, i16, i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { %struct.gravity_value_r, %struct.gravity_value_r, %struct.gravity_value_r, i32, ptr, ptr, float, i8 }
%struct.gravity_value_r = type { i64, i64, ptr }

@gravity_class_closure = external global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; 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 @gravity_compiler_transfer(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.gravity_compiler_t, ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %2
  br label %79

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_gc_setenabled(ptr noundef %16, i1 noundef zeroext false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gravity_compiler_t, ptr %17, i32 0, i32 5
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.void_r, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !11
  store i64 %21, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !14
  br label %22

22:                                               ; preds = %74, %15
  %23 = load i64, ptr %6, align 8, !tbaa !14
  %24 = load i64, ptr %5, align 8, !tbaa !14
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %77

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.gravity_compiler_t, ptr %28, i32 0, i32 5
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.void_r, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gravity_compiler_t, ptr %33, i32 0, i32 5
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.void_r, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = add i64 %37, -1
  store i64 %38, ptr %36, align 8, !tbaa !11
  %39 = getelementptr inbounds ptr, ptr %32, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gravity_vm_transfer(ptr noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gravity_class_s, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr @gravity_class_closure, align 8, !tbaa !5
  %47 = icmp eq ptr %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %27
  store i32 4, ptr %7, align 4
  br label %71

49:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %50, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.gravity_closure_s, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = getelementptr inbounds %struct.gravity_function_t, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !23
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %70

57:                                               ; preds = %49
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gravity_closure_s, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !21
  %61 = getelementptr inbounds %struct.gravity_function_t, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = call i32 @strcmp(ptr noundef %62, ptr noundef @.str) #5
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %57
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.gravity_closure_s, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  call void @gravity_vm_initmodule(ptr noundef %66, ptr noundef %69)
  br label %70

70:                                               ; preds = %65, %57, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  store i32 0, ptr %7, align 4
  br label %71

71:                                               ; preds = %70, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %72 = load i32, ptr %7, align 4
  switch i32 %72, label %80 [
    i32 0, label %73
    i32 4, label %74
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73, %71
  %75 = load i64, ptr %6, align 8, !tbaa !14
  %76 = add i64 %75, 1
  store i64 %76, ptr %6, align 8, !tbaa !14
  br label %22, !llvm.loop !26

77:                                               ; preds = %26
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_gc_setenabled(ptr noundef %78, i1 noundef zeroext true)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %79

79:                                               ; preds = %77, %14
  ret void

80:                                               ; preds = %71
  unreachable
}

declare void @gravity_gc_setenabled(ptr noundef, i1 noundef zeroext) #2

declare void @gravity_vm_transfer(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

declare void @gravity_vm_initmodule(ptr noundef, ptr noundef) #2

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 = { "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 = { nounwind willreturn memory(read) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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, !6, i64 40}
!10 = !{!"gravity_compiler_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 16}
!16 = !{!17, !6, i64 0}
!17 = !{!"gravity_class_s", !6, i64 0, !18, i64 8, !6, i64 48, !6, i64 56, !19, i64 64, !19, i64 65, !19, i64 66, !19, i64 67, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !20, i64 104, !6, i64 112}
!18 = !{!"gravity_gc_s", !19, i64 0, !19, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!22, !6, i64 56}
!22 = !{!"gravity_closure_s", !6, i64 0, !18, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !20, i64 80}
!23 = !{!24, !6, i64 56}
!24 = !{!"", !6, i64 0, !18, i64 8, !6, i64 48, !6, i64 56, !25, i64 64, !25, i64 66, !25, i64 68, !25, i64 70, !20, i64 72, !7, i64 80}
!25 = !{!"short", !7, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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"

@gravity_class_closure = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_compiler_transfer(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %29, label %5

5:                                                ; preds = %2
  tail call void @gravity_gc_setenabled(ptr noundef %1, i1 noundef zeroext false) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %6, align 8, !tbaa !10
  %.not19 = icmp eq i64 %7, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %27, %5
  tail call void @gravity_gc_setenabled(ptr noundef %1, i1 noundef zeroext true) #3
  br label %29

.lr.ph:                                           ; preds = %5, %27
  %.018 = phi i64 [ %28, %27 ], [ 0, %5 ]
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = load i64, ptr %8, align 8, !tbaa !10
  %12 = add i64 %11, -1
  store i64 %12, ptr %8, align 8, !tbaa !10
  %13 = getelementptr inbounds ptr, ptr %10, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  tail call void @gravity_vm_transfer(ptr noundef %1, ptr noundef %14) #3
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = load ptr, ptr @gravity_class_closure, align 8, !tbaa !14
  %17 = icmp eq ptr %15, %16
  br i1 %17, label %18, label %27

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %14, i64 56
  %20 = load ptr, ptr %19, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %20, i64 56
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %.not17 = icmp eq ptr %22, null
  br i1 %.not17, label %27, label %23

23:                                               ; preds = %18
  %24 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %22, ptr noundef nonnull dereferenceable(1) @.str) #4
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  tail call void @gravity_vm_initmodule(ptr noundef %1, ptr noundef nonnull %20) #3
  br label %27

27:                                               ; preds = %18, %23, %26, %.lr.ph
  %28 = add nuw i64 %.018, 1
  %exitcond.not = icmp eq i64 %28, %7
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !25

29:                                               ; preds = %2, %._crit_edge
  ret void
}

declare void @gravity_gc_setenabled(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare void @gravity_vm_transfer(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

declare void @gravity_vm_initmodule(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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 40}
!6 = !{!"gravity_compiler_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!11, !7, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"gravity_class_s", !7, i64 0, !17, i64 8, !7, i64 48, !7, i64 56, !18, i64 64, !18, i64 65, !18, i64 66, !18, i64 67, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !19, i64 104, !7, i64 112}
!17 = !{!"gravity_gc_s", !18, i64 0, !18, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{!"int", !8, i64 0}
!20 = !{!21, !7, i64 56}
!21 = !{!"gravity_closure_s", !7, i64 0, !17, i64 8, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !19, i64 80}
!22 = !{!23, !7, i64 56}
!23 = !{!"", !7, i64 0, !17, i64 8, !7, i64 48, !7, i64 56, !24, i64 64, !24, i64 66, !24, i64 68, !24, i64 70, !19, i64 72, !8, i64 80}
!24 = !{!"short", !8, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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