; 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.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_FileDumpHeap(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.memzone_t, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef @.str.4, i32 noundef %7, ptr noundef %8) #3
  %10 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.memzone_t, ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds %struct.memblock_s, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %76, %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Z_CheckBlockIntegrity(ptr noundef %15)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.memblock_s, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.memblock_s, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.memblock_s, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.6, ptr noundef %17, i32 noundef %20, ptr noundef %23, i32 noundef %26) #3
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.memblock_s, ptr %28, i32 0, i32 5
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.memzone_t, ptr %31, i32 0, i32 1
  %33 = icmp eq ptr %30, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %14
  br label %80

35:                                               ; preds = %14
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.memblock_s, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %36, i64 %40
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.memblock_s, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = icmp ne ptr %41, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %35
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.7) #3
  br label %49

49:                                               ; preds = %46, %35
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.memblock_s, ptr %50, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = getelementptr inbounds %struct.memblock_s, ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = icmp ne ptr %54, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %49
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.8) #3
  br label %60

60:                                               ; preds = %57, %49
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.memblock_s, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = icmp ne ptr %63, null
  br i1 %64, label %75, label %65

65:                                               ; preds = %60
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.memblock_s, ptr %66, i32 0, i32 5
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = getelementptr inbounds %struct.memblock_s, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = icmp ne ptr %70, null
  br i1 %71, label %75, label %72

72:                                               ; preds = %65
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str.9) #3
  br label %75

75:                                               ; preds = %72, %65, %60
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.memblock_s, ptr %77, i32 0, i32 5
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  store ptr %79, ptr %3, align 8, !tbaa !5
  br label %14

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, 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 = { 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 #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, !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 = !{!10, !6, i64 32}
!14 = !{!12, !11, i64 4}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !11, i64 16}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !6, 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.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_FileDumpHeap(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %3 = load i32, ptr %2, align 8, !tbaa !9
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.4, i32 noundef %3, ptr noundef nonnull %2) #2
  %5 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %.023 = load ptr, ptr %6, align 8, !tbaa !13
  tail call void @Z_CheckBlockIntegrity(ptr noundef %.023)
  %7 = getelementptr inbounds i8, ptr %.023, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %.023, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %.023, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !16
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.6, ptr noundef %.023, i32 noundef %8, ptr noundef %10, i32 noundef %12) #2
  %14 = getelementptr inbounds i8, ptr %.023, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = icmp eq ptr %15, %17
  br i1 %18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %41
  %19 = phi ptr [ %50, %41 ], [ %15, %1 ]
  %20 = phi ptr [ %49, %41 ], [ %14, %1 ]
  %21 = phi ptr [ %44, %41 ], [ %9, %1 ]
  %22 = phi ptr [ %42, %41 ], [ %7, %1 ]
  %.024 = phi ptr [ %.0, %41 ], [ %.023, %1 ]
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %.024, i64 %24
  %.not = icmp eq ptr %25, %19
  br i1 %.not, label %28, label %26

26:                                               ; preds = %.lr.ph
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.7) #2
  %.pre = load ptr, ptr %20, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %26, %.lr.ph
  %29 = phi ptr [ %.pre, %26 ], [ %19, %.lr.ph ]
  %30 = getelementptr inbounds i8, ptr %29, i64 32
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %.not20 = icmp eq ptr %31, %.024
  br i1 %.not20, label %34, label %32

32:                                               ; preds = %28
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.8) #2
  %.0.pre25.pre = load ptr, ptr %20, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %32, %28
  %.0.pre25 = phi ptr [ %.0.pre25.pre, %32 ], [ %29, %28 ]
  %35 = load ptr, ptr %21, align 8, !tbaa !15
  %.not21 = icmp eq ptr %35, null
  br i1 %.not21, label %36, label %41

36:                                               ; preds = %34
  %37 = getelementptr inbounds i8, ptr %.0.pre25, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %.not22 = icmp eq ptr %38, null
  br i1 %.not22, label %39, label %41

39:                                               ; preds = %36
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.9) #2
  %.0.pre = load ptr, ptr %20, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %34, %36, %39
  %.0 = phi ptr [ %.0.pre25, %34 ], [ %.0.pre25, %36 ], [ %.0.pre, %39 ]
  tail call void @Z_CheckBlockIntegrity(ptr noundef %.0)
  %42 = getelementptr inbounds i8, ptr %.0, i64 4
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = getelementptr inbounds i8, ptr %.0, i64 8
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds i8, ptr %.0, i64 16
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.6, ptr noundef %.0, i32 noundef %43, ptr noundef %45, i32 noundef %47) #2
  %49 = getelementptr inbounds i8, ptr %.0, i64 24
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load ptr, ptr @mainzone, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 8
  %53 = icmp eq ptr %50, %52
  br i1 %53, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %41, %1
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, 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" }
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, !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 4}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !11, i64 16}
!17 = !{!12, !6, i64 32}


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