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

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

@marknums = external hidden global [10 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [107 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
define dso_local void @AM_unloadPics() #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %20, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 10
  br i1 %4, label %5, label %23

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [10 x ptr], ptr @marknums, i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 -48
  %11 = getelementptr inbounds %struct.memblock_s, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp ne i32 %12, 1919505
  br i1 %13, label %14, label %15

14:                                               ; preds = %5
  call void (ptr, ...) @I_Error(ptr noundef @.str.1, i32 noundef 490) #5
  unreachable

15:                                               ; preds = %5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10 x ptr], ptr @marknums, i64 0, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  call void @Z_ChangeTag2(ptr noundef %19, i32 noundef 101)
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !13

23:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

; Function Attrs: noreturn
declare void @I_Error(ptr noundef, ...) #2

declare void @Z_ChangeTag2(ptr noundef, i32 noundef) #3

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 = { noreturn "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 = { "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 #4 = { nounwind }
attributes #5 = { noreturn }

!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 20}
!12 = !{!"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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@marknums = external hidden local_unnamed_addr global [10 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [107 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @AM_unloadPics() local_unnamed_addr #0 {
  %1 = load ptr, ptr @marknums, align 16, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 -28
  %3 = load i32, ptr %2, align 4, !tbaa !9
  %.not = icmp eq i32 %3, 1919505
  br i1 %.not, label %5, label %4

4:                                                ; preds = %37, %33, %29, %25, %21, %17, %13, %9, %5, %0
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.1, i32 noundef 490) #3
  unreachable

5:                                                ; preds = %0
  tail call void @Z_ChangeTag2(ptr noundef nonnull %1, i32 noundef 101) #4
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 8), align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 -28
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %.not.1 = icmp eq i32 %8, 1919505
  br i1 %.not.1, label %9, label %4

9:                                                ; preds = %5
  tail call void @Z_ChangeTag2(ptr noundef nonnull %6, i32 noundef 101) #4
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 16), align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 -28
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %.not.2 = icmp eq i32 %12, 1919505
  br i1 %.not.2, label %13, label %4

13:                                               ; preds = %9
  tail call void @Z_ChangeTag2(ptr noundef nonnull %10, i32 noundef 101) #4
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 24), align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 -28
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %.not.3 = icmp eq i32 %16, 1919505
  br i1 %.not.3, label %17, label %4

17:                                               ; preds = %13
  tail call void @Z_ChangeTag2(ptr noundef nonnull %14, i32 noundef 101) #4
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 32), align 16, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 -28
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %.not.4 = icmp eq i32 %20, 1919505
  br i1 %.not.4, label %21, label %4

21:                                               ; preds = %17
  tail call void @Z_ChangeTag2(ptr noundef nonnull %18, i32 noundef 101) #4
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 40), align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 -28
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %.not.5 = icmp eq i32 %24, 1919505
  br i1 %.not.5, label %25, label %4

25:                                               ; preds = %21
  tail call void @Z_ChangeTag2(ptr noundef nonnull %22, i32 noundef 101) #4
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 48), align 16, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 -28
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %.not.6 = icmp eq i32 %28, 1919505
  br i1 %.not.6, label %29, label %4

29:                                               ; preds = %25
  tail call void @Z_ChangeTag2(ptr noundef nonnull %26, i32 noundef 101) #4
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 56), align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 -28
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %.not.7 = icmp eq i32 %32, 1919505
  br i1 %.not.7, label %33, label %4

33:                                               ; preds = %29
  tail call void @Z_ChangeTag2(ptr noundef nonnull %30, i32 noundef 101) #4
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 64), align 16, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 -28
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %.not.8 = icmp eq i32 %36, 1919505
  br i1 %.not.8, label %37, label %4

37:                                               ; preds = %33
  tail call void @Z_ChangeTag2(ptr noundef nonnull %34, i32 noundef 101) #4
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @marknums, i64 72), align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 -28
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %.not.9 = icmp eq i32 %40, 1919505
  br i1 %.not.9, label %41, label %4

41:                                               ; preds = %37
  tail call void @Z_ChangeTag2(ptr noundef nonnull %38, i32 noundef 101) #4
  ret void
}

; Function Attrs: noreturn
declare void @I_Error(ptr noundef, ...) local_unnamed_addr #1

declare void @Z_ChangeTag2(ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { noreturn "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 = { noreturn nounwind }
attributes #4 = { 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 20}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass