; 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
@.str = external hidden unnamed_addr constant [29 x i8], align 1
@ylookup = external dso_local global [200 x ptr], align 16
@columnofs = external dso_local global [320 x i32], align 16
@dc_iscale = external dso_local global i32, align 4
@dc_texturemid = external dso_local global i32, align 4
@centery = external global i32, align 4
@dc_source = external dso_local global ptr, align 8
@dc_colormap = external dso_local global ptr, align 8
@dc_translation = external dso_local global ptr, align 8

; 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_DrawTranslatedColumn() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %7 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %8 = sub nsw i32 %6, %7
  store i32 %8, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  store i32 1, ptr %5, align 4
  br label %51

12:                                               ; preds = %0
  %13 = load i32, ptr @dc_x, align 4, !tbaa !5
  %14 = icmp uge i32 %13, 320
  br i1 %14, label %21, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %20 = icmp sge i32 %19, 200
  br i1 %20, label %21, label %25

21:                                               ; preds = %18, %15, %12
  %22 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %23 = load i32, ptr @dc_yh, align 4, !tbaa !5
  %24 = load i32, ptr @dc_x, align 4, !tbaa !5
  call void (ptr, ...) @I_Error(ptr noundef @.str, i32 noundef %22, i32 noundef %23, i32 noundef %24) #4
  unreachable

25:                                               ; preds = %18
  %26 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [200 x ptr], ptr @ylookup, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr @dc_x, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [320 x i32], ptr @columnofs, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %29, i64 %34
  store ptr %35, ptr %2, align 8, !tbaa !9
  %36 = load i32, ptr @dc_iscale, align 4, !tbaa !5
  store i32 %36, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr @dc_texturemid, align 4, !tbaa !5
  %38 = load i32, ptr @dc_yl, align 4, !tbaa !5
  %39 = load i32, ptr @centery, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = mul nsw i32 %40, %41
  %43 = add nsw i32 %37, %42
  store i32 %43, ptr %3, align 4, !tbaa !5
  %44 = load ptr, ptr %2, align 8, !tbaa !9
  %45 = load ptr, ptr @dc_source, align 8, !tbaa !9
  %46 = load ptr, ptr @dc_translation, align 8, !tbaa !9
  %47 = load ptr, ptr @dc_colormap, align 8, !tbaa !9
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = load i32, ptr %1, align 4, !tbaa !5
  call void @R_DrawTranslatedColumnKernel(ptr noundef %44, ptr noundef %45, ptr noundef %46, ptr noundef %47, i32 noundef %48, i32 noundef %49, i32 noundef %50)
  store i32 0, ptr %5, align 4
  br label %51

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

53:                                               ; preds = %51, %51
  ret void

54:                                               ; preds = %51
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @R_DrawTranslatedColumnKernel(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 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
@.str = external hidden unnamed_addr constant [29 x i8], align 1
@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
@dc_iscale = external dso_local local_unnamed_addr global i32, align 4
@dc_texturemid = external dso_local local_unnamed_addr global i32, align 4
@centery = external local_unnamed_addr global i32, align 4
@dc_source = external dso_local local_unnamed_addr global ptr, align 8
@dc_colormap = external dso_local local_unnamed_addr global ptr, align 8
@dc_translation = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @R_DrawTranslatedColumn() local_unnamed_addr #1 {
  %1 = load i32, ptr @dc_yh, align 4
  %2 = load i32, ptr @dc_yl, align 4
  %3 = sub nsw i32 %1, %2
  %4 = icmp slt i32 %3, 0
  br i1 %4, label %29, label %5

5:                                                ; preds = %0
  %6 = load i32, ptr @dc_x, align 4, !tbaa !5
  %7 = icmp ugt i32 %6, 319
  %8 = icmp slt i32 %2, 0
  %or.cond = or i1 %8, %7
  %9 = icmp sgt i32 %1, 199
  %or.cond3 = or i1 %9, %or.cond
  br i1 %or.cond3, label %10, label %11

10:                                               ; preds = %5
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str, i32 noundef %2, i32 noundef %1, i32 noundef %6) #2
  unreachable

11:                                               ; preds = %5
  %12 = zext nneg i32 %2 to i64
  %13 = getelementptr inbounds [200 x ptr], ptr @ylookup, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = zext nneg i32 %6 to i64
  %16 = getelementptr inbounds [320 x i32], ptr @columnofs, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %14, i64 %18
  %20 = load i32, ptr @dc_iscale, align 4, !tbaa !5
  %21 = load i32, ptr @dc_texturemid, align 4, !tbaa !5
  %22 = load i32, ptr @centery, align 4, !tbaa !5
  %23 = sub nsw i32 %2, %22
  %24 = mul nsw i32 %23, %20
  %25 = add nsw i32 %24, %21
  %26 = load ptr, ptr @dc_source, align 8, !tbaa !9
  %27 = load ptr, ptr @dc_translation, align 8, !tbaa !9
  %28 = load ptr, ptr @dc_colormap, align 8, !tbaa !9
  tail call void @R_DrawTranslatedColumnKernel(ptr noundef %19, ptr noundef %26, ptr noundef %27, ptr noundef %28, i32 noundef %25, i32 noundef %20, i32 noundef %3)
  br label %29

29:                                               ; preds = %0, %11
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @R_DrawTranslatedColumnKernel(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass