; LLVM IR from marcobambini/gravity :: api (exec_c)

; 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_delegate_t = type { ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

@__const.main.delegate = external hidden unnamed_addr constant %struct.gravity_delegate_t, align 8
@source = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.gravity_delegate_t, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca %struct.gravity_value_t, align 8
  %12 = alloca double, align 8
  %13 = alloca [512 x i8], align 16
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 192, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 @__const.main.delegate, i64 192, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %14 = call ptr @gravity_compiler_create(ptr noundef %6)
  store ptr %14, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr @source, align 8, !tbaa !9
  %17 = load ptr, ptr @source, align 8, !tbaa !9
  %18 = call i64 @strlen(ptr noundef %17) #6
  %19 = call ptr @gravity_compiler_run(ptr noundef %15, ptr noundef %16, i64 noundef %18, i32 noundef 0, i1 noundef zeroext true, i1 noundef zeroext true)
  store ptr %19, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %56

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %24 = call ptr @gravity_vm_new(ptr noundef %6)
  store ptr %24, ptr %10, align 8, !tbaa !9
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = load ptr, ptr %10, align 8, !tbaa !9
  call void @gravity_compiler_transfer(ptr noundef %25, ptr noundef %26)
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  call void @gravity_compiler_free(ptr noundef %27)
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  call void @create_math_class(ptr noundef %28)
  %29 = load ptr, ptr %10, align 8, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = call zeroext i1 @gravity_vm_runmain(ptr noundef %29, ptr noundef %30)
  br i1 %31, label %32, label %50

32:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %33 = load ptr, ptr %10, align 8, !tbaa !9
  %34 = call { ptr, i64 } @gravity_vm_result(ptr noundef %33)
  %35 = getelementptr inbounds { ptr, i64 }, ptr %11, i32 0, i32 0
  %36 = extractvalue { ptr, i64 } %34, 0
  store ptr %36, ptr %35, align 8
  %37 = getelementptr inbounds { ptr, i64 }, ptr %11, i32 0, i32 1
  %38 = extractvalue { ptr, i64 } %34, 1
  store i64 %38, ptr %37, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = call double @gravity_vm_time(ptr noundef %39)
  store double %40, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 512, ptr %13) #5
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = getelementptr inbounds [512 x i8], ptr %13, i64 0, i64 0
  %43 = getelementptr inbounds { ptr, i64 }, ptr %11, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8
  %45 = getelementptr inbounds { ptr, i64 }, ptr %11, i32 0, i32 1
  %46 = load i64, ptr %45, align 8
  call void @gravity_value_dump(ptr noundef %41, ptr %44, i64 %46, ptr noundef %42, i16 noundef zeroext 512)
  %47 = getelementptr inbounds [512 x i8], ptr %13, i64 0, i64 0
  %48 = load double, ptr %12, align 8, !tbaa !11
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %47, double noundef %48)
  call void @llvm.lifetime.end.p0(i64 512, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  br label %50

50:                                               ; preds = %32, %23
  %51 = load ptr, ptr %10, align 8, !tbaa !9
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %55

53:                                               ; preds = %50
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  call void @gravity_vm_free(ptr noundef %54)
  br label %55

55:                                               ; preds = %53, %50
  call void @gravity_core_free()
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  store i32 0, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 192, ptr %6) #5
  %57 = load i32, ptr %9, align 4
  switch i32 %57, label %60 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  %59 = load i32, ptr %3, align 4
  ret i32 %59

60:                                               ; preds = %56
  unreachable
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare ptr @gravity_compiler_create(ptr noundef) #3

declare ptr @gravity_compiler_run(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

declare ptr @gravity_vm_new(ptr noundef) #3

declare void @gravity_compiler_transfer(ptr noundef, ptr noundef) #3

declare void @gravity_compiler_free(ptr noundef) #3

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

declare zeroext i1 @gravity_vm_runmain(ptr noundef, ptr noundef) #3

declare { ptr, i64 } @gravity_vm_result(ptr noundef) #3

declare double @gravity_vm_time(ptr noundef) #3

declare void @gravity_value_dump(ptr noundef, ptr, i64, ptr noundef, i16 noundef zeroext) #3

declare i32 @printf(ptr noundef, ...) #3

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

declare void @gravity_vm_free(ptr noundef) #3

declare void @gravity_core_free() #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


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

@__const.main.delegate = external hidden unnamed_addr constant %struct.gravity_delegate_t, align 8
@source = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.gravity_delegate_t, align 8
  %4 = alloca [512 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 192, ptr nonnull %3) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(192) %3, ptr noundef nonnull align 8 dereferenceable(192) @__const.main.delegate, i64 192, i1 false)
  %5 = call ptr @gravity_compiler_create(ptr noundef nonnull %3) #6
  %6 = load ptr, ptr @source, align 8, !tbaa !5
  %7 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #7
  %8 = call ptr @gravity_compiler_run(ptr noundef %5, ptr noundef %6, i64 noundef %7, i32 noundef 0, i1 noundef zeroext true, i1 noundef zeroext true) #6
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %21, label %9

9:                                                ; preds = %2
  %10 = call ptr @gravity_vm_new(ptr noundef nonnull %3) #6
  call void @gravity_compiler_transfer(ptr noundef %5, ptr noundef %10) #6
  call void @gravity_compiler_free(ptr noundef %5) #6
  call void @create_math_class(ptr noundef %10)
  %11 = call zeroext i1 @gravity_vm_runmain(ptr noundef %10, ptr noundef nonnull %8) #6
  br i1 %11, label %12, label %18

12:                                               ; preds = %9
  %13 = call { ptr, i64 } @gravity_vm_result(ptr noundef %10) #6
  %14 = extractvalue { ptr, i64 } %13, 0
  %15 = extractvalue { ptr, i64 } %13, 1
  %16 = call double @gravity_vm_time(ptr noundef %10) #6
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %4) #6
  call void @gravity_value_dump(ptr noundef %10, ptr %14, i64 %15, ptr noundef nonnull %4, i16 noundef zeroext 512) #6
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %4, double noundef %16)
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %4) #6
  br label %18

18:                                               ; preds = %12, %9
  %.not16 = icmp eq ptr %10, null
  br i1 %.not16, label %20, label %19

19:                                               ; preds = %18
  call void @gravity_vm_free(ptr noundef nonnull %10) #6
  br label %20

20:                                               ; preds = %19, %18
  call void @gravity_core_free() #6
  br label %21

21:                                               ; preds = %2, %20
  %.0 = phi i32 [ 0, %20 ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 192, ptr nonnull %3) #6
  ret i32 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare ptr @gravity_compiler_create(ptr noundef) local_unnamed_addr #3

declare ptr @gravity_compiler_run(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

declare ptr @gravity_vm_new(ptr noundef) local_unnamed_addr #3

declare void @gravity_compiler_transfer(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @gravity_compiler_free(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @create_math_class(ptr noundef) local_unnamed_addr #0

declare zeroext i1 @gravity_vm_runmain(ptr noundef, ptr noundef) local_unnamed_addr #3

declare { ptr, i64 } @gravity_vm_result(ptr noundef) local_unnamed_addr #3

declare double @gravity_vm_time(ptr noundef) local_unnamed_addr #3

declare void @gravity_value_dump(ptr noundef, ptr, i64, ptr noundef, i16 noundef zeroext) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #5

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

declare void @gravity_vm_free(ptr noundef) local_unnamed_addr #3

declare void @gravity_core_free() local_unnamed_addr #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { 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 #5 = { nofree nounwind "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 #6 = { nounwind }
attributes #7 = { 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"}


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