; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Doom/mc1-doom/src (z_zone)

; 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.memzone_t = type { i32, %struct.memblock_s, ptr }
%struct.memblock_s = type { i32, i32, ptr, i32, i32, ptr, ptr, i32 }

@mainzone = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [36 x i8], align 1

; 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 void @Z_CheckBlockIntegrity(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Z_DumpHeap(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load ptr, ptr @mainzone, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.memzone_t, ptr %6, i32 0, i32 0
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = load ptr, ptr @mainzone, align 8, !tbaa !9
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %8, ptr noundef %9)
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %11, i32 noundef %12)
  %14 = load ptr, ptr @mainzone, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.memzone_t, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds %struct.memblock_s, ptr %15, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  store ptr %17, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %89, %2
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  call void @Z_CheckBlockIntegrity(ptr noundef %19)
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.memblock_s, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp sge i32 %22, %23
  br i1 %24, label %25, label %43

25:                                               ; preds = %18
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.memblock_s, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %31, label %43

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.memblock_s, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.memblock_s, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.memblock_s, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %32, i32 noundef %35, ptr noundef %38, i32 noundef %41)
  br label %43

43:                                               ; preds = %31, %25, %18
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.memblock_s, ptr %44, i32 0, i32 5
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = load ptr, ptr @mainzone, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.memzone_t, ptr %47, i32 0, i32 1
  %49 = icmp eq ptr %46, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %43
  br label %93

51:                                               ; preds = %43
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.memblock_s, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %52, i64 %56
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.memblock_s, ptr %58, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = icmp ne ptr %57, %60
  br i1 %61, label %62, label %64

62:                                               ; preds = %51
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %64

64:                                               ; preds = %62, %51
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.memblock_s, ptr %65, i32 0, i32 5
  %67 = load ptr, ptr %66, align 8, !tbaa !18
  %68 = getelementptr inbounds %struct.memblock_s, ptr %67, i32 0, i32 6
  %69 = load ptr, ptr %68, align 8, !tbaa !19
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = icmp ne ptr %69, %70
  br i1 %71, label %72, label %74

72:                                               ; preds = %64
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %74

74:                                               ; preds = %72, %64
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.memblock_s, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = icmp ne ptr %77, null
  br i1 %78, label %88, label %79

79:                                               ; preds = %74
  %80 = load ptr, ptr %5, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.memblock_s, ptr %80, i32 0, i32 5
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  %83 = getelementptr inbounds %struct.memblock_s, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !17
  %85 = icmp ne ptr %84, null
  br i1 %85, label %88, label %86

86:                                               ; preds = %79
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  br label %88

88:                                               ; preds = %86, %79, %74
  br label %89

89:                                               ; preds = %88
  %90 = load ptr, ptr %5, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.memblock_s, ptr %90, i32 0, i32 5
  %92 = load ptr, ptr %91, align 8, !tbaa !18
  store ptr %92, ptr %5, align 8, !tbaa !9
  br label %18

93:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare i32 @printf(ptr noundef, ...) #2

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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 56}
!13 = !{!"memblock_s", !6, i64 0, !6, i64 4, !10, i64 8, !6, i64 16, !6, i64 20, !10, i64 24, !10, i64 32, !6, i64 40}
!14 = !{!12, !10, i64 32}
!15 = !{!13, !6, i64 16}
!16 = !{!13, !6, i64 4}
!17 = !{!13, !10, i64 8}
!18 = !{!13, !10, i64 24}
!19 = !{!13, !10, i64 32}


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

@mainzone = external dso_local local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @Z_CheckBlockIntegrity(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Z_DumpHeap(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %4 = load i32, ptr %3, align 8, !tbaa !9
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %4, ptr noundef nonnull %3)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %0, i32 noundef %1)
  %7 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 32
  br label %9

9:                                                ; preds = %.backedge, %2
  %.0.in = phi ptr [ %8, %2 ], [ %19, %.backedge ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !13
  tail call void @Z_CheckBlockIntegrity(ptr noundef %.0)
  %10 = getelementptr inbounds i8, ptr %.0, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %.not = icmp slt i32 %11, %0
  %.not21 = icmp sgt i32 %11, %1
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %18, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %.0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %.0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %.0, i32 noundef %14, ptr noundef %16, i32 noundef %11)
  br label %18

18:                                               ; preds = %12, %9
  %19 = getelementptr inbounds i8, ptr %.0, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = icmp eq ptr %20, %22
  br i1 %23, label %46, label %24

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %.0, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %.0, i64 %27
  %.not22 = icmp eq ptr %28, %20
  br i1 %.not22, label %31, label %29

29:                                               ; preds = %24
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %.pre = load ptr, ptr %19, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %29, %24
  %32 = phi ptr [ %.pre, %29 ], [ %20, %24 ]
  %33 = getelementptr inbounds i8, ptr %32, i64 32
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %.not23 = icmp eq ptr %34, %.0
  br i1 %.not23, label %37, label %35

35:                                               ; preds = %31
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %37

37:                                               ; preds = %35, %31
  %38 = getelementptr inbounds i8, ptr %.0, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %.not24 = icmp eq ptr %39, null
  br i1 %.not24, label %40, label %.backedge

.backedge:                                        ; preds = %37, %40, %44
  br label %9

40:                                               ; preds = %37
  %41 = load ptr, ptr %19, align 8, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %41, i64 8
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %.not25 = icmp eq ptr %43, null
  br i1 %.not25, label %44, label %.backedge

44:                                               ; preds = %40
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  br label %.backedge

46:                                               ; preds = %18
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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 = { nofree 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" }

!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, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!"memblock_s", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !11, i64 40}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !11, i64 16}
!15 = !{!12, !11, i64 4}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 32}


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