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

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

@dc_yh = external dso_local global i32, align 4
@dc_yl = external dso_local global i32, align 4
@dc_x = external dso_local global i32, align 4
@ylookup = external dso_local global [200 x ptr], align 16
@columnofs = external dso_local global [320 x i32], align 16
@R_DrawFuzzColumn.fuzzpos = external hidden global i32, align 4
@viewheight = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [33 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: noreturn
declare void @I_Error(ptr noundef, ...) #1

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

6:                                                ; preds = %0
  store i32 1, ptr @dc_yl, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %6, %0
  %8 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %9 = load i32, ptr @viewheight, align 4, !tbaa !5
  %10 = sub nsw i32 %9, 1
  %11 = icmp eq i32 %8, %10
  br i1 %11, label %12, label %15

12:                                               ; preds = %7
  %13 = load i32, ptr @viewheight, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 2
  store i32 %14, ptr @dc_yh, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %12, %7
  %16 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %17 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %18 = sub nsw i32 %16, %17
  store i32 %18, ptr %1, align 4, !tbaa !5
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  store i32 1, ptr %3, align 4
  br label %50

22:                                               ; preds = %15
  %23 = load i32, ptr @dc_x, align 4, !tbaa !5
  %24 = icmp uge i32 %23, 320
  br i1 %24, label %31, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %30 = icmp sge i32 %29, 200
  br i1 %30, label %31, label %35

31:                                               ; preds = %28, %25, %22
  %32 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %33 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %34 = load i32, ptr @dc_x, align 4, !tbaa !5
  call void (ptr, ...) @I_Error(ptr noundef @.str.1, i32 noundef %32, i32 noundef %33, i32 noundef %34) #4
  unreachable

35:                                               ; preds = %28
  %36 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [200 x ptr], ptr @ylookup, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr @dc_x, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [320 x i32], ptr @columnofs, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %39, i64 %44
  store ptr %45, ptr %2, align 8, !tbaa !9
  %46 = load ptr, ptr %2, align 8, !tbaa !9
  %47 = load i32, ptr @R_DrawFuzzColumn.fuzzpos, align 4, !tbaa !5
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = call i32 @R_DrawFuzzColumnKernel(ptr noundef %46, i32 noundef %47, i32 noundef %48)
  store i32 %49, ptr @R_DrawFuzzColumn.fuzzpos, align 4, !tbaa !5
  store i32 0, ptr %3, align 4
  br label %50

50:                                               ; preds = %35, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  %51 = load i32, ptr %3, align 4
  switch i32 %51, label %53 [
    i32 0, label %52
    i32 1, label %52
  ]

52:                                               ; preds = %50, %50
  ret void

53:                                               ; preds = %50
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @R_DrawFuzzColumnKernel(ptr noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nounwind }
attributes #4 = { 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}


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

@dc_yh = external dso_local local_unnamed_addr global i32, align 4
@dc_yl = external dso_local local_unnamed_addr global i32, align 4
@dc_x = external dso_local local_unnamed_addr global i32, align 4
@ylookup = external dso_local local_unnamed_addr global [200 x ptr], align 16
@columnofs = external dso_local local_unnamed_addr global [320 x i32], align 16
@R_DrawFuzzColumn.fuzzpos = external hidden local_unnamed_addr global i32, align 4
@viewheight = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @R_DrawFuzzColumn() local_unnamed_addr #1 {
  %1 = load i32, ptr @dc_yl, align 4
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %2, label %3

2:                                                ; preds = %0
  store i32 1, ptr @dc_yl, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %2, %0
  %4 = phi i32 [ 1, %2 ], [ %1, %0 ]
  %5 = load i32, ptr @dc_yh, align 4
  %6 = load i32, ptr @viewheight, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  %8 = icmp eq i32 %5, %7
  br i1 %8, label %9, label %11

9:                                                ; preds = %3
  %10 = add nsw i32 %6, -2
  store i32 %10, ptr @dc_yh, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %9, %3
  %12 = phi i32 [ %10, %9 ], [ %5, %3 ]
  %13 = sub nsw i32 %12, %4
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %32, label %15

15:                                               ; preds = %11
  %16 = load i32, ptr @dc_x, align 4, !tbaa !5
  %17 = icmp ugt i32 %16, 319
  %18 = icmp slt i32 %4, 0
  %or.cond = or i1 %18, %17
  %19 = icmp sgt i32 %12, 199
  %or.cond3 = or i1 %19, %or.cond
  br i1 %or.cond3, label %20, label %21

20:                                               ; preds = %15
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.1, i32 noundef %4, i32 noundef %12, i32 noundef %16) #2
  unreachable

21:                                               ; preds = %15
  %22 = zext nneg i32 %4 to i64
  %23 = getelementptr inbounds [200 x ptr], ptr @ylookup, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = zext nneg i32 %16 to i64
  %26 = getelementptr inbounds [320 x i32], ptr @columnofs, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %24, i64 %28
  %30 = load i32, ptr @R_DrawFuzzColumn.fuzzpos, align 4, !tbaa !5
  %31 = tail call i32 @R_DrawFuzzColumnKernel(ptr noundef %29, i32 noundef %30, i32 noundef %13)
  store i32 %31, ptr @R_DrawFuzzColumn.fuzzpos, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %11, %21
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @R_DrawFuzzColumnKernel(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass