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

6:                                                ; preds = %23, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp ult i32 %7, 256
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %5, align 4
  br label %26

10:                                               ; preds = %6
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ircode_t, ptr %11, i32 0, i32 9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds [256 x i8], ptr %12, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !11, !range !13, !noundef !14
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %10
  %21 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %21, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %26

22:                                               ; preds = %10
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = add i32 %24, 1
  store i32 %25, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !15

26:                                               ; preds = %20, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %27 = load i32, ptr %5, align 4
  switch i32 %27, label %33 [
    i32 2, label %28
    i32 1, label %31
  ]

28:                                               ; preds = %26
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ircode_t, ptr %29, i32 0, i32 8
  store i8 1, ptr %30, align 2, !tbaa !17
  store i32 0, ptr %2, align 4
  br label %31

31:                                               ; preds = %28, %26
  %32 = load i32, ptr %2, align 4
  ret i32 %32

33:                                               ; preds = %26
  unreachable
}

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


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local i32 @ircode_register_first_temp_available(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 95
  br label %3

3:                                                ; preds = %19, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.3, %19 ]
  %4 = getelementptr inbounds [256 x i8], ptr %2, i64 0, i64 %indvars.iv
  %5 = load i8, ptr %4, align 1, !tbaa !5, !range !9, !noundef !10
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %.loopexit.loopexit, label %7

7:                                                ; preds = %3
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %8 = getelementptr inbounds [256 x i8], ptr %2, i64 0, i64 %indvars.iv.next
  %9 = load i8, ptr %8, align 1, !tbaa !5, !range !9, !noundef !10
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %.loopexit.loopexit, label %11

11:                                               ; preds = %7
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %12 = getelementptr inbounds [256 x i8], ptr %2, i64 0, i64 %indvars.iv.next.1
  %13 = load i8, ptr %12, align 1, !tbaa !5, !range !9, !noundef !10
  %14 = icmp eq i8 %13, 0
  br i1 %14, label %.loopexit.loopexit, label %15

15:                                               ; preds = %11
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %16 = getelementptr inbounds [256 x i8], ptr %2, i64 0, i64 %indvars.iv.next.2
  %17 = load i8, ptr %16, align 1, !tbaa !5, !range !9, !noundef !10
  %18 = icmp eq i8 %17, 0
  br i1 %18, label %.loopexit.loopexit, label %19

19:                                               ; preds = %15
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 256
  br i1 %exitcond.not.3, label %20, label %3, !llvm.loop !11

20:                                               ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 94
  store i8 1, ptr %21, align 2, !tbaa !13
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %15, %11, %7, %3
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %3 ], [ %indvars.iv.next, %7 ], [ %indvars.iv.next.1, %11 ], [ %indvars.iv.next.2, %15 ]
  %22 = trunc nuw nsw i64 %indvars.iv.lcssa to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %20
  %.1 = phi i32 [ 0, %20 ], [ %22, %.loopexit.loopexit ]
  ret i32 %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 94}
!14 = !{!"ircode_t", !15, i64 0, !16, i64 8, !16, i64 32, !16, i64 56, !18, i64 80, !18, i64 84, !18, i64 88, !19, i64 92, !6, i64 94, !7, i64 95, !7, i64 351, !16, i64 608, !16, i64 632}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"", !17, i64 0, !17, i64 8, !15, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"short", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass