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

; 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
define dso_local i32 @ircode_register_push_temp(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = call i32 @ircode_register_new(ptr noundef %4)
  store i32 %5, ptr %3, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ircode_t, ptr %6, i32 0, i32 11
  %8 = getelementptr inbounds %struct.uint32_r, ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ircode_t, ptr %10, i32 0, i32 11
  %12 = getelementptr inbounds %struct.uint32_r, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !17
  %14 = icmp eq i64 %9, %13
  br i1 %14, label %15, label %46

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ircode_t, ptr %16, i32 0, i32 11
  %18 = getelementptr inbounds %struct.uint32_r, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %15
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ircode_t, ptr %22, i32 0, i32 11
  %24 = getelementptr inbounds %struct.uint32_r, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !17
  %26 = shl i64 %25, 1
  br label %28

27:                                               ; preds = %15
  br label %28

28:                                               ; preds = %27, %21
  %29 = phi i64 [ %26, %21 ], [ 8, %27 ]
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ircode_t, ptr %30, i32 0, i32 11
  %32 = getelementptr inbounds %struct.uint32_r, ptr %31, i32 0, i32 1
  store i64 %29, ptr %32, align 8, !tbaa !17
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ircode_t, ptr %33, i32 0, i32 11
  %35 = getelementptr inbounds %struct.uint32_r, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ircode_t, ptr %37, i32 0, i32 11
  %39 = getelementptr inbounds %struct.uint32_r, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = mul i64 4, %40
  %42 = call ptr @realloc(ptr noundef %36, i64 noundef %41) #4
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ircode_t, ptr %43, i32 0, i32 11
  %45 = getelementptr inbounds %struct.uint32_r, ptr %44, i32 0, i32 2
  store ptr %42, ptr %45, align 8, !tbaa !18
  br label %46

46:                                               ; preds = %28, %1
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ircode_t, ptr %48, i32 0, i32 11
  %50 = getelementptr inbounds %struct.uint32_r, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %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 0
  %55 = load i64, ptr %54, align 8, !tbaa !11
  %56 = add i64 %55, 1
  store i64 %56, ptr %54, align 8, !tbaa !11
  %57 = getelementptr inbounds i32, ptr %51, i64 %55
  store i32 %47, ptr %57, align 4, !tbaa !9
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ircode_t, ptr %59, i32 0, i32 5
  %61 = load i32, ptr %60, align 4, !tbaa !19
  %62 = icmp ugt i32 %58, %61
  br i1 %62, label %63, label %71

63:                                               ; preds = %46
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ircode_t, ptr %65, i32 0, i32 5
  store i32 %64, ptr %66, align 4, !tbaa !19
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ircode_t, ptr %67, i32 0, i32 6
  %69 = load i32, ptr %68, align 8, !tbaa !20
  %70 = add i32 %69, 1
  store i32 %70, ptr %68, align 8, !tbaa !20
  br label %71

71:                                               ; preds = %63, %46
  %72 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %72
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ircode_register_new(ptr noundef) #1

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, !14, i64 608}
!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 = !{!12, !14, i64 616}
!18 = !{!12, !6, i64 624}
!19 = !{!12, !10, i64 84}
!20 = !{!12, !10, i64 88}


; 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
define dso_local i32 @ircode_register_push_temp(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @ircode_register_new(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 608
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 616
  %6 = load i64, ptr %5, align 8, !tbaa !15
  %7 = icmp eq i64 %4, %6
  br i1 %7, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 624
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !16
  br label %14

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

14:                                               ; preds = %._crit_edge, %8
  %15 = phi i64 [ %4, %._crit_edge ], [ %.pre18, %8 ]
  %16 = phi ptr [ %.pre, %._crit_edge ], [ %13, %8 ]
  %17 = add i64 %15, 1
  store i64 %17, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %16, i64 %15
  store i32 %2, ptr %18, align 4, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 84
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %21 = icmp ugt i32 %2, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %14
  store i32 %2, ptr %19, align 4, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %0, i64 88
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = add i32 %24, 1
  store i32 %25, ptr %23, align 8, !tbaa !19
  br label %26

26:                                               ; preds = %22, %14
  ret i32 %2
}

; 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
declare hidden i32 @ircode_register_new(ptr noundef) local_unnamed_addr #0

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, !11, i64 608}
!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 = !{!6, !11, i64 616}
!16 = !{!6, !7, i64 624}
!17 = !{!12, !12, i64 0}
!18 = !{!6, !12, i64 84}
!19 = !{!6, !12, i64 88}


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