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

; 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.wbstartstruct_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x %struct.wbplayerstruct_t] }
%struct.wbplayerstruct_t = type { i32, i32, i32, i32, i32, [4 x i32], i32 }

@wbs = external hidden global ptr, align 8
@gamemode = external global i32, align 4
@snl_pointeron = external hidden global i32, align 4
@splat = external hidden global ptr, align 8
@yah = external hidden global [2 x ptr], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @WI_slamBackground() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @WI_drawEL() #0

; Function Attrs: nounwind uwtable
declare dso_local void @WI_drawOnLnode(i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @WI_drawAnimatedBack() #0

; Function Attrs: nounwind uwtable
define dso_local void @WI_drawShowNextLoc() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @WI_slamBackground()
  call void @WI_drawAnimatedBack()
  %4 = load i32, ptr @gamemode, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 2
  br i1 %5, label %6, label %51

6:                                                ; preds = %0
  %7 = load ptr, ptr @wbs, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.wbstartstruct_t, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = icmp sgt i32 %9, 2
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  call void @WI_drawEL()
  store i32 1, ptr %3, align 4
  br label %61

12:                                               ; preds = %6
  %13 = load ptr, ptr @wbs, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.wbstartstruct_t, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp eq i32 %15, 8
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = load ptr, ptr @wbs, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.wbstartstruct_t, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = sub nsw i32 %20, 1
  br label %26

22:                                               ; preds = %12
  %23 = load ptr, ptr @wbs, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.wbstartstruct_t, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %22, %17
  %27 = phi i32 [ %21, %17 ], [ %25, %22 ]
  store i32 %27, ptr %2, align 4, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %34, %26
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %32, label %37

32:                                               ; preds = %28
  %33 = load i32, ptr %1, align 4, !tbaa !5
  call void @WI_drawOnLnode(i32 noundef %33, ptr noundef @splat)
  br label %34

34:                                               ; preds = %32
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %1, align 4, !tbaa !5
  br label %28, !llvm.loop !15

37:                                               ; preds = %28
  %38 = load ptr, ptr @wbs, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.wbstartstruct_t, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  call void @WI_drawOnLnode(i32 noundef 8, ptr noundef @splat)
  br label %43

43:                                               ; preds = %42, %37
  %44 = load i32, ptr @snl_pointeron, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %43
  %47 = load ptr, ptr @wbs, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.wbstartstruct_t, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !14
  call void @WI_drawOnLnode(i32 noundef %49, ptr noundef @yah)
  br label %50

50:                                               ; preds = %46, %43
  br label %51

51:                                               ; preds = %50, %0
  %52 = load i32, ptr @gamemode, align 4, !tbaa !5
  %53 = icmp ne i32 %52, 2
  br i1 %53, label %59, label %54

54:                                               ; preds = %51
  %55 = load ptr, ptr @wbs, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.wbstartstruct_t, ptr %55, i32 0, i32 3
  %57 = load i32, ptr %56, align 4, !tbaa !14
  %58 = icmp ne i32 %57, 30
  br i1 %58, label %59, label %60

59:                                               ; preds = %54, %51
  call void @WI_drawEL()
  br label %60

60:                                               ; preds = %59, %54
  store i32 0, ptr %3, align 4
  br label %61

61:                                               ; preds = %60, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  %62 = load i32, ptr %3, align 4
  switch i32 %62, label %64 [
    i32 0, label %63
    i32 1, label %63
  ]

63:                                               ; preds = %61, %61
  ret void

64:                                               ; preds = %61
  unreachable
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !7, i64 40}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 12}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 4}


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

@wbs = external hidden local_unnamed_addr global ptr, align 8
@gamemode = external local_unnamed_addr global i32, align 4
@snl_pointeron = external hidden local_unnamed_addr global i32, align 4
@splat = external hidden global ptr, align 8
@yah = external hidden global [2 x ptr], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @WI_slamBackground() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @WI_drawEL() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @WI_drawOnLnode(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @WI_drawAnimatedBack() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @WI_drawShowNextLoc() local_unnamed_addr #0 {
  tail call void @WI_slamBackground()
  tail call void @WI_drawAnimatedBack()
  %1 = load i32, ptr @gamemode, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 2
  %.pre14 = load ptr, ptr @wbs, align 8, !tbaa !9
  br i1 %.not, label %.thread, label %2

2:                                                ; preds = %0
  %3 = load i32, ptr %.pre14, align 4, !tbaa !11
  %4 = icmp sgt i32 %3, 2
  br i1 %4, label %.sink.split, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %.pre14, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %8 = icmp eq i32 %7, 8
  br i1 %8, label %9, label %13

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %.pre14, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %12 = add nsw i32 %11, -1
  br label %13

13:                                               ; preds = %5, %9
  %14 = phi i32 [ %12, %9 ], [ %7, %5 ]
  %.not511 = icmp slt i32 %14, 0
  br i1 %.not511, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.012 = phi i32 [ %15, %.lr.ph ], [ 0, %13 ]
  tail call void @WI_drawOnLnode(i32 noundef %.012, ptr noundef nonnull @splat)
  %15 = add nuw i32 %.012, 1
  %exitcond.not = icmp eq i32 %.012, %14
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr @wbs, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %13
  %16 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %.pre14, %13 ]
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %.not6 = icmp eq i32 %18, 0
  br i1 %.not6, label %20, label %19

19:                                               ; preds = %._crit_edge
  tail call void @WI_drawOnLnode(i32 noundef 8, ptr noundef nonnull @splat)
  br label %20

20:                                               ; preds = %19, %._crit_edge
  %21 = load i32, ptr @snl_pointeron, align 4, !tbaa !5
  %.not7 = icmp eq i32 %21, 0
  br i1 %.not7, label %26, label %22

22:                                               ; preds = %20
  %23 = load ptr, ptr @wbs, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %23, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !14
  tail call void @WI_drawOnLnode(i32 noundef %25, ptr noundef nonnull @yah)
  br label %26

26:                                               ; preds = %20, %22
  %.pr = load i32, ptr @gamemode, align 4, !tbaa !5
  %.not8 = icmp eq i32 %.pr, 2
  br i1 %.not8, label %..thread_crit_edge, label %.sink.split

..thread_crit_edge:                               ; preds = %26
  %.pre13 = load ptr, ptr @wbs, align 8, !tbaa !9
  br label %.thread

.thread:                                          ; preds = %..thread_crit_edge, %0
  %27 = phi ptr [ %.pre13, %..thread_crit_edge ], [ %.pre14, %0 ]
  %28 = getelementptr inbounds i8, ptr %27, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %.not9 = icmp eq i32 %29, 30
  br i1 %.not9, label %30, label %.sink.split

.sink.split:                                      ; preds = %26, %.thread, %2
  tail call void @WI_drawEL()
  br label %30

30:                                               ; preds = %.sink.split, %.thread
  ret void
}

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

!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, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !7, i64 40}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 12}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 4}


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