; 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 }

declare ptr @void_array_create() #0

; Function Attrs: nounwind uwtable
declare hidden void @gravity_compiler_reset(ptr noundef, i1 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_compiler_run(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i1 noundef zeroext %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %16 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !11
  %17 = zext i1 %4 to i8
  store i8 %17, ptr %12, align 1, !tbaa !13
  %18 = zext i1 %5 to i8
  store i8 %18, ptr %13, align 1, !tbaa !13
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %24, label %21

21:                                               ; preds = %6
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21, %6
  store ptr null, ptr %7, align 8
  br label %146

25:                                               ; preds = %21
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gravity_compiler_t, ptr %26, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %34

30:                                               ; preds = %25
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.gravity_compiler_t, ptr %31, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  call void @gnode_free(ptr noundef %33)
  br label %34

34:                                               ; preds = %30, %25
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.gravity_compiler_t, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = icmp ne ptr %37, null
  br i1 %38, label %43, label %39

39:                                               ; preds = %34
  %40 = call ptr @void_array_create()
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.gravity_compiler_t, ptr %41, i32 0, i32 5
  store ptr %40, ptr %42, align 8, !tbaa !17
  br label %43

43:                                               ; preds = %39, %34
  %44 = call ptr @gravity_vm_newmini()
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.gravity_compiler_t, ptr %45, i32 0, i32 3
  store ptr %44, ptr %46, align 8, !tbaa !18
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gravity_compiler_t, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gravity_vm_setdata(ptr noundef %49, ptr noundef %50)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.gravity_compiler_t, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  call void @gravity_vm_set_callbacks(ptr noundef %53, ptr noundef @internal_vm_transfer, ptr noundef @internal_vm_cleanup)
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gravity_compiler_t, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  call void @gravity_core_register(ptr noundef %56)
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !11
  %60 = load i8, ptr %12, align 1, !tbaa !13, !range !19, !noundef !20
  %61 = trunc i8 %60 to i1
  %62 = call ptr @gravity_parser_create(ptr noundef %57, i64 noundef %58, i32 noundef %59, i1 noundef zeroext %61)
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.gravity_compiler_t, ptr %63, i32 0, i32 0
  store ptr %62, ptr %64, align 8, !tbaa !21
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gravity_compiler_t, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = icmp ne ptr %67, null
  br i1 %68, label %70, label %69

69:                                               ; preds = %43
  store ptr null, ptr %7, align 8
  br label %146

70:                                               ; preds = %43
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.gravity_compiler_t, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.gravity_compiler_t, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !22
  %77 = call ptr @gravity_parser_run(ptr noundef %73, ptr noundef %76)
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.gravity_compiler_t, ptr %78, i32 0, i32 4
  store ptr %77, ptr %79, align 8, !tbaa !15
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.gravity_compiler_t, ptr %80, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !15
  %83 = icmp ne ptr %82, null
  br i1 %83, label %85, label %84

84:                                               ; preds = %70
  br label %144

85:                                               ; preds = %70
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.gravity_compiler_t, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !21
  call void @gravity_parser_free(ptr noundef %88)
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.gravity_compiler_t, ptr %89, i32 0, i32 0
  store ptr null, ptr %90, align 8, !tbaa !21
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.gravity_compiler_t, ptr %91, i32 0, i32 4
  %93 = load ptr, ptr %92, align 8, !tbaa !15
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.gravity_compiler_t, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !22
  %97 = call zeroext i1 @gravity_semacheck1(ptr noundef %93, ptr noundef %96)
  %98 = zext i1 %97 to i8
  store i8 %98, ptr %14, align 1, !tbaa !13
  %99 = load i8, ptr %14, align 1, !tbaa !13, !range !19, !noundef !20
  %100 = trunc i8 %99 to i1
  br i1 %100, label %102, label %101

101:                                              ; preds = %85
  br label %144

102:                                              ; preds = %85
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.gravity_compiler_t, ptr %103, i32 0, i32 4
  %105 = load ptr, ptr %104, align 8, !tbaa !15
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.gravity_compiler_t, ptr %106, i32 0, i32 1
  %108 = load ptr, ptr %107, align 8, !tbaa !22
  %109 = call zeroext i1 @gravity_semacheck2(ptr noundef %105, ptr noundef %108)
  %110 = zext i1 %109 to i8
  store i8 %110, ptr %15, align 1, !tbaa !13
  %111 = load i8, ptr %15, align 1, !tbaa !13, !range !19, !noundef !20
  %112 = trunc i8 %111 to i1
  br i1 %112, label %114, label %113

113:                                              ; preds = %102
  br label %144

114:                                              ; preds = %102
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.gravity_compiler_t, ptr %115, i32 0, i32 4
  %117 = load ptr, ptr %116, align 8, !tbaa !15
  %118 = load ptr, ptr %8, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.gravity_compiler_t, ptr %118, i32 0, i32 1
  %120 = load ptr, ptr %119, align 8, !tbaa !22
  %121 = load ptr, ptr %8, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.gravity_compiler_t, ptr %121, i32 0, i32 3
  %123 = load ptr, ptr %122, align 8, !tbaa !18
  %124 = load i8, ptr %13, align 1, !tbaa !13, !range !19, !noundef !20
  %125 = trunc i8 %124 to i1
  %126 = call ptr @gravity_codegen(ptr noundef %117, ptr noundef %120, ptr noundef %123, i1 noundef zeroext %125)
  store ptr %126, ptr %16, align 8, !tbaa !5
  %127 = load ptr, ptr %16, align 8, !tbaa !5
  %128 = icmp ne ptr %127, null
  br i1 %128, label %130, label %129

129:                                              ; preds = %114
  br label %144

130:                                              ; preds = %114
  %131 = load ptr, ptr %16, align 8, !tbaa !5
  %132 = load i8, ptr %13, align 1, !tbaa !13, !range !19, !noundef !20
  %133 = trunc i8 %132 to i1
  %134 = call ptr @gravity_optimizer(ptr noundef %131, i1 noundef zeroext %133)
  store ptr %134, ptr %16, align 8, !tbaa !5
  %135 = load ptr, ptr %16, align 8, !tbaa !5
  %136 = icmp ne ptr %135, null
  br i1 %136, label %137, label %143

137:                                              ; preds = %130
  %138 = load ptr, ptr %8, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.gravity_compiler_t, ptr %138, i32 0, i32 3
  %140 = load ptr, ptr %139, align 8, !tbaa !18
  %141 = load ptr, ptr %16, align 8, !tbaa !5
  %142 = call ptr @gravity_closure_new(ptr noundef %140, ptr noundef %141)
  store ptr %142, ptr %7, align 8
  br label %146

143:                                              ; preds = %130
  br label %144

144:                                              ; preds = %143, %129, %113, %101, %84
  %145 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gravity_compiler_reset(ptr noundef %145, i1 noundef zeroext false)
  store ptr null, ptr %7, align 8
  br label %146

146:                                              ; preds = %144, %137, %69, %24
  %147 = load ptr, ptr %7, align 8
  ret ptr %147
}

declare void @gnode_free(ptr noundef) #0

declare ptr @gravity_vm_newmini() #0

declare void @gravity_vm_setdata(ptr noundef, ptr noundef) #0

declare void @gravity_vm_set_callbacks(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @internal_vm_transfer(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @internal_vm_cleanup(ptr noundef) #1

declare void @gravity_core_register(ptr noundef) #0

declare ptr @gravity_parser_create(ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext) #0

declare ptr @gravity_parser_run(ptr noundef, ptr noundef) #0

declare void @gravity_parser_free(ptr noundef) #0

declare zeroext i1 @gravity_semacheck1(ptr noundef, ptr noundef) #0

declare zeroext i1 @gravity_semacheck2(ptr noundef, ptr noundef) #0

declare ptr @gravity_codegen(ptr noundef, ptr noundef, ptr noundef, i1 noundef zeroext) #0

declare ptr @gravity_optimizer(ptr noundef, i1 noundef zeroext) #0

declare ptr @gravity_closure_new(ptr noundef, ptr noundef) #0

attributes #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 = { 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, !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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 32}
!16 = !{!"gravity_compiler_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!16, !6, i64 40}
!18 = !{!16, !6, i64 24}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !6, i64 0}
!22 = !{!16, !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"

declare ptr @void_array_create() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @gravity_compiler_reset(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_compiler_run(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i1 noundef zeroext %5) local_unnamed_addr #1 {
  %7 = icmp eq ptr %1, null
  %8 = icmp eq i64 %2, 0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %48, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %13, label %12

12:                                               ; preds = %9
  tail call void @gnode_free(ptr noundef nonnull %11) #2
  br label %13

13:                                               ; preds = %12, %9
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  %.not47 = icmp eq ptr %15, null
  br i1 %.not47, label %16, label %18

16:                                               ; preds = %13
  %17 = tail call ptr @void_array_create() #2
  store ptr %17, ptr %14, align 8, !tbaa !10
  br label %18

18:                                               ; preds = %16, %13
  %19 = tail call ptr @gravity_vm_newmini() #2
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %19, ptr %20, align 8, !tbaa !11
  tail call void @gravity_vm_setdata(ptr noundef %19, ptr noundef nonnull %0) #2
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  tail call void @gravity_vm_set_callbacks(ptr noundef %21, ptr noundef nonnull @internal_vm_transfer, ptr noundef nonnull @internal_vm_cleanup) #2
  %22 = load ptr, ptr %20, align 8, !tbaa !11
  tail call void @gravity_core_register(ptr noundef %22) #2
  %23 = tail call ptr @gravity_parser_create(ptr noundef nonnull %1, i64 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #2
  store ptr %23, ptr %0, align 8, !tbaa !12
  %.not48 = icmp eq ptr %23, null
  br i1 %.not48, label %48, label %24

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = tail call ptr @gravity_parser_run(ptr noundef nonnull %23, ptr noundef %26) #2
  store ptr %27, ptr %10, align 8, !tbaa !5
  %.not49 = icmp eq ptr %27, null
  br i1 %.not49, label %47, label %28

28:                                               ; preds = %24
  %29 = load ptr, ptr %0, align 8, !tbaa !12
  tail call void @gravity_parser_free(ptr noundef %29) #2
  store ptr null, ptr %0, align 8, !tbaa !12
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = load ptr, ptr %25, align 8, !tbaa !13
  %32 = tail call zeroext i1 @gravity_semacheck1(ptr noundef %30, ptr noundef %31) #2
  br i1 %32, label %33, label %47

33:                                               ; preds = %28
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %25, align 8, !tbaa !13
  %36 = tail call zeroext i1 @gravity_semacheck2(ptr noundef %34, ptr noundef %35) #2
  br i1 %36, label %37, label %47

37:                                               ; preds = %33
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %25, align 8, !tbaa !13
  %40 = load ptr, ptr %20, align 8, !tbaa !11
  %41 = tail call ptr @gravity_codegen(ptr noundef %38, ptr noundef %39, ptr noundef %40, i1 noundef zeroext %5) #2
  %.not50 = icmp eq ptr %41, null
  br i1 %.not50, label %47, label %42

42:                                               ; preds = %37
  %43 = tail call ptr @gravity_optimizer(ptr noundef nonnull %41, i1 noundef zeroext %5) #2
  %.not51 = icmp eq ptr %43, null
  br i1 %.not51, label %47, label %44

44:                                               ; preds = %42
  %45 = load ptr, ptr %20, align 8, !tbaa !11
  %46 = tail call ptr @gravity_closure_new(ptr noundef %45, ptr noundef nonnull %43) #2
  br label %48

47:                                               ; preds = %42, %37, %33, %28, %24
  tail call void @gravity_compiler_reset(ptr noundef nonnull %0, i1 noundef zeroext false)
  br label %48

48:                                               ; preds = %18, %6, %47, %44
  %.0 = phi ptr [ %46, %44 ], [ null, %47 ], [ null, %6 ], [ null, %18 ]
  ret ptr %.0
}

declare void @gnode_free(ptr noundef) local_unnamed_addr #0

declare ptr @gravity_vm_newmini() local_unnamed_addr #0

declare void @gravity_vm_setdata(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @gravity_vm_set_callbacks(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @internal_vm_transfer(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @internal_vm_cleanup(ptr noundef) #1

declare void @gravity_core_register(ptr noundef) local_unnamed_addr #0

declare ptr @gravity_parser_create(ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

declare ptr @gravity_parser_run(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @gravity_parser_free(ptr noundef) local_unnamed_addr #0

declare zeroext i1 @gravity_semacheck1(ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i1 @gravity_semacheck2(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @gravity_codegen(ptr noundef, ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare ptr @gravity_optimizer(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare ptr @gravity_closure_new(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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, !7, i64 32}
!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 = !{!6, !7, i64 40}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}


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