; 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: nounwind
declare void @free(ptr noundef) #1

; 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 @ircode_free(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call i32 @ircode_count(ptr noundef %6)
  store i32 %7, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %24, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %27

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ircode_t, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct.code_r, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %23) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %24

24:                                               ; preds = %13
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = add i32 %25, 1
  store i32 %26, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !18

27:                                               ; preds = %12
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ircode_t, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.code_r, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %40

34:                                               ; preds = %27
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ircode_t, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.code_r, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  call void @free(ptr noundef %39) #3
  br label %40

40:                                               ; preds = %34, %27
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ircode_t, ptr %41, i32 0, i32 12
  %43 = getelementptr inbounds %struct.context_r, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %51

46:                                               ; preds = %40
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ircode_t, ptr %47, i32 0, i32 12
  %49 = getelementptr inbounds %struct.context_r, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  call void @free(ptr noundef %50) #3
  br label %51

51:                                               ; preds = %46, %40
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ircode_t, ptr %52, i32 0, i32 11
  %54 = getelementptr inbounds %struct.uint32_r, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %62

57:                                               ; preds = %51
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ircode_t, ptr %58, i32 0, i32 11
  %60 = getelementptr inbounds %struct.uint32_r, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  call void @free(ptr noundef %61) #3
  br label %62

62:                                               ; preds = %57, %51
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ircode_t, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds %struct.uint32_r, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !22
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %73

68:                                               ; preds = %62
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ircode_t, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds %struct.uint32_r, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !22
  call void @free(ptr noundef %72) #3
  br label %73

73:                                               ; preds = %68, %62
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ircode_t, ptr %74, i32 0, i32 2
  %76 = getelementptr inbounds %struct.uint32_r, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !23
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %84

79:                                               ; preds = %73
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ircode_t, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds %struct.uint32_r, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !23
  call void @free(ptr noundef %83) #3
  br label %84

84:                                               ; preds = %79, %73
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ircode_t, ptr %85, i32 0, i32 3
  %87 = getelementptr inbounds %struct.uint32_r, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !24
  %89 = icmp ne ptr %88, null
  br i1 %89, label %90, label %95

90:                                               ; preds = %84
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.ircode_t, ptr %91, i32 0, i32 3
  %93 = getelementptr inbounds %struct.uint32_r, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !24
  call void @free(ptr noundef %94) #3
  br label %95

95:                                               ; preds = %90, %84
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.ircode_t, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !11
  call void @free(ptr noundef %98) #3
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %99) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @ircode_count(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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, !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, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !6, i64 648}
!21 = !{!12, !6, i64 624}
!22 = !{!12, !6, i64 24}
!23 = !{!12, !6, i64 48}
!24 = !{!12, !6, i64 72}


; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ircode_free(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @ircode_count(ptr noundef %0)
  %.not32 = icmp eq i32 %2, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext i32 %2 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !15
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %12, label %11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  tail call void @free(ptr noundef %10) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

11:                                               ; preds = %._crit_edge
  tail call void @free(ptr noundef nonnull %5) #2
  br label %12

12:                                               ; preds = %11, %._crit_edge
  %13 = getelementptr inbounds i8, ptr %0, i64 648
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %.not26 = icmp eq ptr %14, null
  br i1 %.not26, label %16, label %15

15:                                               ; preds = %12
  tail call void @free(ptr noundef nonnull %14) #2
  br label %16

16:                                               ; preds = %15, %12
  %17 = getelementptr inbounds i8, ptr %0, i64 624
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %.not27 = icmp eq ptr %18, null
  br i1 %.not27, label %20, label %19

19:                                               ; preds = %16
  tail call void @free(ptr noundef nonnull %18) #2
  br label %20

20:                                               ; preds = %19, %16
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %.not28 = icmp eq ptr %22, null
  br i1 %.not28, label %24, label %23

23:                                               ; preds = %20
  tail call void @free(ptr noundef nonnull %22) #2
  br label %24

24:                                               ; preds = %23, %20
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  %.not29 = icmp eq ptr %26, null
  br i1 %.not29, label %28, label %27

27:                                               ; preds = %24
  tail call void @free(ptr noundef nonnull %26) #2
  br label %28

28:                                               ; preds = %27, %24
  %29 = getelementptr inbounds i8, ptr %0, i64 72
  %30 = load ptr, ptr %29, align 8, !tbaa !23
  %.not30 = icmp eq ptr %30, null
  br i1 %.not30, label %32, label %31

31:                                               ; preds = %28
  tail call void @free(ptr noundef nonnull %30) #2
  br label %32

32:                                               ; preds = %31, %28
  %33 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @free(ptr noundef %33) #2
  tail call void @free(ptr noundef nonnull %0) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @ircode_count(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") 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 #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 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 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 648}
!20 = !{!6, !7, i64 624}
!21 = !{!6, !7, i64 24}
!22 = !{!6, !7, i64 48}
!23 = !{!6, !7, i64 72}


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