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

; 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_marklabel(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = call ptr @inst_new(i32 noundef 0, i32 noundef %8, i32 noundef 0, i32 noundef 0, i32 noundef 3, i64 noundef 0, double noundef 0.000000e+00, i32 noundef %9)
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ircode_t, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.code_r, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ircode_t, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.code_r, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !18
  %21 = icmp eq i64 %15, %20
  br i1 %21, label %22, label %59

22:                                               ; preds = %3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ircode_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.code_r, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %36

29:                                               ; preds = %22
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ircode_t, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.code_r, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !18
  %35 = shl i64 %34, 1
  br label %37

36:                                               ; preds = %22
  br label %37

37:                                               ; preds = %36, %29
  %38 = phi i64 [ %35, %29 ], [ 8, %36 ]
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ircode_t, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.code_r, ptr %41, i32 0, i32 1
  store i64 %38, ptr %42, align 8, !tbaa !18
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ircode_t, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.code_r, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !19
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ircode_t, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.code_r, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !18
  %53 = mul i64 8, %52
  %54 = call ptr @realloc(ptr noundef %47, i64 noundef %53) #4
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ircode_t, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.code_r, ptr %57, i32 0, i32 2
  store ptr %54, ptr %58, align 8, !tbaa !19
  br label %59

59:                                               ; preds = %37, %3
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ircode_t, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.code_r, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ircode_t, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = getelementptr inbounds %struct.code_r, ptr %68, i32 0, i32 0
  %70 = load i64, ptr %69, align 8, !tbaa !17
  %71 = add i64 %70, 1
  store i64 %71, ptr %69, align 8, !tbaa !17
  %72 = getelementptr inbounds ptr, ptr %65, i64 %70
  store ptr %60, ptr %72, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"ircode_t", !6, i64 0, !13, i64 8, !13, i64 32, !13, i64 56, !10, i64 80, !10, i64 84, !10, i64 88, !15, i64 92, !16, i64 94, !7, i64 95, !7, i64 351, !13, i64 608, !13, i64 632}
!13 = !{!"", !14, i64 0, !14, i64 8, !6, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!13, !14, i64 0}
!18 = !{!13, !14, i64 8}
!19 = !{!13, !6, i64 16}


; 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_marklabel(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @inst_new(i32 noundef 0, i32 noundef %1, i32 noundef 0, i32 noundef 0, i32 noundef 3, i64 noundef 0, double noundef 0.000000e+00, i32 noundef %2)
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = load i64, ptr %5, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !16
  %9 = icmp eq i64 %6, %8
  br i1 %9, label %10, label %._crit_edge

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

10:                                               ; preds = %3
  %.not = icmp eq i64 %6, 0
  %11 = shl i64 %6, 1
  %spec.select = select i1 %.not, i64 8, i64 %11
  store i64 %spec.select, ptr %7, align 8, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %5, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  %14 = shl i64 %spec.select, 3
  %15 = tail call ptr @realloc(ptr noundef %13, i64 noundef %14) #2
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %15, ptr %17, align 8, !tbaa !17
  %.pre12 = load i64, ptr %16, align 8, !tbaa !15
  br label %18

18:                                               ; preds = %._crit_edge, %10
  %19 = phi i64 [ %.pre12, %10 ], [ %6, %._crit_edge ]
  %20 = phi ptr [ %15, %10 ], [ %.pre, %._crit_edge ]
  %21 = phi ptr [ %16, %10 ], [ %5, %._crit_edge ]
  %22 = add i64 %19, 1
  store i64 %22, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds ptr, ptr %20, i64 %19
  store ptr %4, ptr %23, align 8, !tbaa !18
  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, !11, i64 0}
!16 = !{!10, !11, i64 8}
!17 = !{!10, !7, i64 16}
!18 = !{!7, !7, i64 0}


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