; 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_pop_context_protect(ptr noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %8 = zext i1 %1 to i8
  store i8 %8, ptr %5, align 1, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ircode_t, ptr %9, i32 0, i32 11
  %11 = getelementptr inbounds %struct.uint32_r, ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  br label %77

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load ptr, ptr %4, 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 2
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ircode_t, ptr %20, i32 0, i32 11
  %22 = getelementptr inbounds %struct.uint32_r, ptr %21, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = add i64 %23, -1
  store i64 %24, ptr %22, align 8, !tbaa !11
  %25 = getelementptr inbounds i32, ptr %19, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !18
  store i32 %26, ptr %6, align 4, !tbaa !18
  %27 = load i8, ptr %5, align 1, !tbaa !9, !range !19, !noundef !20
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %35

29:                                               ; preds = %15
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ircode_t, ptr %30, i32 0, i32 9
  %32 = load i32, ptr %6, align 4, !tbaa !18
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [256 x i8], ptr %31, i64 0, i64 %33
  store i8 1, ptr %34, align 1, !tbaa !9
  br label %49

35:                                               ; preds = %15
  %36 = load i32, ptr %6, align 4, !tbaa !18
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ircode_t, ptr %37, i32 0, i32 7
  %39 = load i16, ptr %38, align 4, !tbaa !21
  %40 = zext i16 %39 to i32
  %41 = icmp uge i32 %36, %40
  br i1 %41, label %42, label %48

42:                                               ; preds = %35
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ircode_t, ptr %43, i32 0, i32 9
  %45 = load i32, ptr %6, align 4, !tbaa !18
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [256 x i8], ptr %44, i64 0, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !9
  br label %48

48:                                               ; preds = %42, %35
  br label %49

49:                                               ; preds = %48, %29
  %50 = load i8, ptr %5, align 1, !tbaa !9, !range !19, !noundef !20
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %75

52:                                               ; preds = %49
  %53 = load i32, ptr %6, align 4, !tbaa !18
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ircode_t, ptr %54, i32 0, i32 7
  %56 = load i16, ptr %55, align 4, !tbaa !21
  %57 = zext i16 %56 to i32
  %58 = icmp uge i32 %53, %57
  br i1 %58, label %59, label %75

59:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ircode_t, ptr %60, i32 0, i32 12
  %62 = getelementptr inbounds %struct.context_r, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !22
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ircode_t, ptr %64, i32 0, i32 12
  %66 = getelementptr inbounds %struct.context_r, ptr %65, i32 0, i32 0
  %67 = load i64, ptr %66, align 8, !tbaa !23
  %68 = sub i64 %67, 1
  %69 = getelementptr inbounds ptr, ptr %63, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  store ptr %70, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !18
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  store i8 1, ptr %74, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %75

75:                                               ; preds = %59, %52, %49
  %76 = load i32, ptr %6, align 4, !tbaa !18
  store i32 %76, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %77

77:                                               ; preds = %75, %14
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

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 }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !14, i64 608}
!12 = !{!"ircode_t", !6, i64 0, !13, i64 8, !13, i64 32, !13, i64 56, !15, i64 80, !15, i64 84, !15, i64 88, !16, i64 92, !10, 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 = !{!"int", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!12, !6, i64 624}
!18 = !{!15, !15, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!12, !16, i64 92}
!22 = !{!12, !6, i64 648}
!23 = !{!12, !14, i64 632}


; 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 nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @ircode_register_pop_context_protect(ptr nocapture noundef %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 608
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %.thread, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 624
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = add i64 %4, -1
  store i64 %9, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i32, ptr %8, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !16
  br i1 %1, label %20, label %12

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 92
  %14 = load i16, ptr %13, align 4, !tbaa !17
  %15 = zext i16 %14 to i32
  %.not = icmp ult i32 %11, %15
  br i1 %.not, label %.thread, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 95
  %18 = zext i32 %11 to i64
  %19 = getelementptr inbounds [256 x i8], ptr %17, i64 0, i64 %18
  store i8 0, ptr %19, align 1, !tbaa !18
  br label %.thread

20:                                               ; preds = %6
  %21 = getelementptr inbounds i8, ptr %0, i64 95
  %22 = zext i32 %11 to i64
  %23 = getelementptr inbounds [256 x i8], ptr %21, i64 0, i64 %22
  store i8 1, ptr %23, align 1, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %0, i64 92
  %25 = load i16, ptr %24, align 4, !tbaa !17
  %26 = zext i16 %25 to i32
  %.not20 = icmp ult i32 %11, %26
  br i1 %.not20, label %.thread, label %27

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %0, i64 632
  %29 = getelementptr inbounds i8, ptr %0, i64 648
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = load i64, ptr %28, align 8, !tbaa !20
  %32 = getelementptr ptr, ptr %30, i64 %31
  %33 = getelementptr i8, ptr %32, i64 -8
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = getelementptr inbounds i8, ptr %34, i64 %22
  store i8 1, ptr %35, align 1, !tbaa !18
  br label %.thread

.thread:                                          ; preds = %16, %12, %20, %27, %2
  %.0 = phi i32 [ -1, %2 ], [ %11, %27 ], [ %11, %20 ], [ %11, %12 ], [ %11, %16 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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" }

!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, !7, i64 624}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !13, i64 92}
!18 = !{!14, !14, i64 0}
!19 = !{!6, !7, i64 648}
!20 = !{!6, !11, i64 632}
!21 = !{!7, !7, i64 0}


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