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

; 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.ircode_t = type { ptr, %struct.uint32_r, %struct.uint32_r, %struct.uint32_r, i32, i32, i32, i16, i8, [256 x i8], [256 x i8], %struct.uint32_r, %struct.context_r }
%struct.uint32_r = type { i64, i64, ptr }
%struct.context_r = type { i64, i64, ptr }
%struct.code_r = type { i64, i64, ptr }
%struct.inst_t = type { i32, i32, i32, i32, i32, %union.anon, i32 }
%union.anon = type { double }

; 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 hidden ptr @inst_new(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef, double noundef, i32 noundef) #1

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ircode_add_check(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.ircode_t, ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.code_r, ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ircode_t, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.code_r, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !17
  %15 = sub i64 %14, 1
  %16 = getelementptr inbounds ptr, ptr %9, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %17, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %95

20:                                               ; preds = %1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.inst_t, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = icmp eq i32 %23, 12
  br i1 %24, label %25, label %95

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.inst_t, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !20
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.inst_t, ptr %29, i32 0, i32 6
  %31 = load i32, ptr %30, align 8, !tbaa !21
  %32 = call ptr @inst_new(i32 noundef 51, i32 noundef %28, i32 noundef 0, i32 noundef 0, i32 noundef 0, i64 noundef 0, double noundef 0.000000e+00, i32 noundef %31)
  store ptr %32, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ircode_t, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.code_r, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ircode_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.code_r, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !22
  %43 = icmp eq i64 %37, %42
  br i1 %43, label %44, label %81

44:                                               ; preds = %25
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ircode_t, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.code_r, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !22
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %58

51:                                               ; preds = %44
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ircode_t, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.code_r, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !22
  %57 = shl i64 %56, 1
  br label %59

58:                                               ; preds = %44
  br label %59

59:                                               ; preds = %58, %51
  %60 = phi i64 [ %57, %51 ], [ 8, %58 ]
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ircode_t, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.code_r, ptr %63, i32 0, i32 1
  store i64 %60, ptr %64, align 8, !tbaa !22
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ircode_t, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.code_r, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !16
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ircode_t, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.code_r, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !22
  %75 = mul i64 8, %74
  %76 = call ptr @realloc(ptr noundef %69, i64 noundef %75) #4
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ircode_t, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.code_r, ptr %79, i32 0, i32 2
  store ptr %76, ptr %80, align 8, !tbaa !16
  br label %81

81:                                               ; preds = %59, %25
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.ircode_t, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.code_r, ptr %85, i32 0, i32 2
  %87 = load ptr, ptr %86, align 8, !tbaa !16
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ircode_t, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.code_r, ptr %90, i32 0, i32 0
  %92 = load i64, ptr %91, align 8, !tbaa !17
  %93 = add i64 %92, 1
  store i64 %93, ptr %91, align 8, !tbaa !17
  %94 = getelementptr inbounds ptr, ptr %87, i64 %92
  store ptr %82, ptr %94, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %95

95:                                               ; preds = %81, %20, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  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 allocsize(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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(1) }

!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 0}
!10 = !{!"ircode_t", !6, i64 0, !11, i64 8, !11, i64 32, !11, i64 56, !13, i64 80, !13, i64 84, !13, i64 88, !14, i64 92, !15, i64 94, !7, i64 95, !7, i64 351, !11, i64 608, !11, i64 632}
!11 = !{!"", !12, i64 0, !12, i64 8, !6, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!11, !6, i64 16}
!17 = !{!11, !12, i64 0}
!18 = !{!19, !13, i64 0}
!19 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !7, i64 24, !13, i64 32}
!20 = !{!19, !13, i64 8}
!21 = !{!19, !13, i64 32}
!22 = !{!11, !12, 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"

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ircode_add_check(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !15
  %5 = load i64, ptr %2, align 8, !tbaa !16
  %6 = getelementptr ptr, ptr %4, i64 %5
  %7 = getelementptr i8, ptr %6, i64 -8
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %37, label %9

9:                                                ; preds = %1
  %10 = load i32, ptr %8, align 8, !tbaa !18
  %11 = icmp eq i32 %10, 12
  br i1 %11, label %12, label %37

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %8, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %8, i64 32
  %16 = load i32, ptr %15, align 8, !tbaa !21
  %17 = tail call ptr @inst_new(i32 noundef 51, i32 noundef %14, i32 noundef 0, i32 noundef 0, i32 noundef 0, i64 noundef 0, double noundef 0.000000e+00, i32 noundef %16)
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !22
  %22 = icmp eq i64 %19, %21
  br i1 %22, label %23, label %._crit_edge

._crit_edge:                                      ; preds = %12
  %.phi.trans.insert = getelementptr inbounds i8, ptr %18, i64 16
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !15
  br label %31

23:                                               ; preds = %12
  %.not18 = icmp eq i64 %19, 0
  %24 = shl i64 %19, 1
  %spec.select = select i1 %.not18, i64 8, i64 %24
  store i64 %spec.select, ptr %20, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %18, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = shl i64 %spec.select, 3
  %28 = tail call ptr @realloc(ptr noundef %26, i64 noundef %27) #2
  %29 = load ptr, ptr %0, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  store ptr %28, ptr %30, align 8, !tbaa !15
  %.pre19 = load i64, ptr %29, align 8, !tbaa !16
  br label %31

31:                                               ; preds = %._crit_edge, %23
  %32 = phi i64 [ %.pre19, %23 ], [ %19, %._crit_edge ]
  %33 = phi ptr [ %28, %23 ], [ %.pre, %._crit_edge ]
  %34 = phi ptr [ %29, %23 ], [ %18, %._crit_edge ]
  %35 = add i64 %32, 1
  store i64 %35, ptr %34, align 8, !tbaa !16
  %36 = getelementptr inbounds ptr, ptr %33, i64 %32
  store ptr %17, ptr %36, align 8, !tbaa !17
  br label %37

37:                                               ; preds = %31, %9, %1
  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" }
attributes #1 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }

!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 = !{!"ircode_t", !7, i64 0, !10, i64 8, !10, i64 32, !10, i64 56, !12, i64 80, !12, i64 84, !12, i64 88, !13, i64 92, !14, i64 94, !8, i64 95, !8, i64 351, !10, i64 608, !10, i64 632}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!10, !7, i64 16}
!16 = !{!10, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !12, i64 0}
!19 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !8, i64 24, !12, i64 32}
!20 = !{!19, !12, i64 8}
!21 = !{!19, !12, i64 32}
!22 = !{!10, !11, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass