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

; 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.patch_t = type { i16, i16, i16, i16, [8 x i32] }

@hu_font = external global [63 x ptr], align 16

; 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: convergent nocallback nofree nosync nounwind willreturn memory(none)
declare i1 @llvm.is.constant.i32(i32) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_toupper_loc() #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @toupper(i32 noundef) #3

declare void @V_DrawPatch(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @F_CastPrint(ptr noundef %0) #5 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %14, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %62, %59, %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %73

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = load i8, ptr %19, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  store i32 %22, ptr %4, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %18
  br label %73

26:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = call i1 @llvm.is.constant.i32(i32 %27)
  br i1 %28, label %29, label %47

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %30 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %30, ptr %9, align 4, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp slt i32 %31, -128
  br i1 %32, label %36, label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp sgt i32 %34, 255
  br i1 %35, label %36, label %38

36:                                               ; preds = %33, %29
  %37 = load i32, ptr %9, align 4, !tbaa !9
  br label %45

38:                                               ; preds = %33
  %39 = call ptr @__ctype_toupper_loc() #7
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %38, %36
  %46 = phi i32 [ %37, %36 ], [ %44, %38 ]
  store i32 %46, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %50

47:                                               ; preds = %26
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = call i32 @toupper(i32 noundef %48) #8
  store i32 %49, ptr %8, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %47, %45
  %51 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %51, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = sub nsw i32 %52, 33
  store i32 %53, ptr %4, align 4, !tbaa !9
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %59, label %56

56:                                               ; preds = %50
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = icmp sgt i32 %57, 63
  br i1 %58, label %59, label %62

59:                                               ; preds = %56, %50
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add nsw i32 %60, 4
  store i32 %61, ptr %7, align 4, !tbaa !9
  br label %15, !llvm.loop !12

62:                                               ; preds = %56
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [63 x ptr], ptr @hu_font, i64 0, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.patch_t, ptr %66, i32 0, i32 0
  %68 = load i16, ptr %67, align 4, !tbaa !14
  %69 = sext i16 %68 to i32
  store i32 %69, ptr %6, align 4, !tbaa !9
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = add nsw i32 %71, %70
  store i32 %72, ptr %7, align 4, !tbaa !9
  br label %15, !llvm.loop !12

73:                                               ; preds = %25, %15
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = sdiv i32 %74, 2
  %76 = sub nsw i32 160, %75
  store i32 %76, ptr %5, align 4, !tbaa !9
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %77, ptr %3, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %125, %122, %73
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %141

81:                                               ; preds = %78
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %3, align 8, !tbaa !5
  %84 = load i8, ptr %82, align 1, !tbaa !11
  %85 = sext i8 %84 to i32
  store i32 %85, ptr %4, align 4, !tbaa !9
  %86 = load i32, ptr %4, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %89, label %88

88:                                               ; preds = %81
  br label %141

89:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %90 = load i32, ptr %4, align 4, !tbaa !9
  %91 = call i1 @llvm.is.constant.i32(i32 %90)
  br i1 %91, label %92, label %110

92:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %93 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %93, ptr %12, align 4, !tbaa !9
  %94 = load i32, ptr %12, align 4, !tbaa !9
  %95 = icmp slt i32 %94, -128
  br i1 %95, label %99, label %96

96:                                               ; preds = %92
  %97 = load i32, ptr %12, align 4, !tbaa !9
  %98 = icmp sgt i32 %97, 255
  br i1 %98, label %99, label %101

99:                                               ; preds = %96, %92
  %100 = load i32, ptr %12, align 4, !tbaa !9
  br label %108

101:                                              ; preds = %96
  %102 = call ptr @__ctype_toupper_loc() #7
  %103 = load ptr, ptr %102, align 8, !tbaa !5
  %104 = load i32, ptr %12, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds i32, ptr %103, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %101, %99
  %109 = phi i32 [ %100, %99 ], [ %107, %101 ]
  store i32 %109, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %113

110:                                              ; preds = %89
  %111 = load i32, ptr %4, align 4, !tbaa !9
  %112 = call i32 @toupper(i32 noundef %111) #8
  store i32 %112, ptr %11, align 4, !tbaa !9
  br label %113

113:                                              ; preds = %110, %108
  %114 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %114, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  %115 = load i32, ptr %13, align 4, !tbaa !9
  %116 = sub nsw i32 %115, 33
  store i32 %116, ptr %4, align 4, !tbaa !9
  %117 = load i32, ptr %4, align 4, !tbaa !9
  %118 = icmp slt i32 %117, 0
  br i1 %118, label %122, label %119

119:                                              ; preds = %113
  %120 = load i32, ptr %4, align 4, !tbaa !9
  %121 = icmp sgt i32 %120, 63
  br i1 %121, label %122, label %125

122:                                              ; preds = %119, %113
  %123 = load i32, ptr %5, align 4, !tbaa !9
  %124 = add nsw i32 %123, 4
  store i32 %124, ptr %5, align 4, !tbaa !9
  br label %78, !llvm.loop !17

125:                                              ; preds = %119
  %126 = load i32, ptr %4, align 4, !tbaa !9
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [63 x ptr], ptr @hu_font, i64 0, i64 %127
  %129 = load ptr, ptr %128, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.patch_t, ptr %129, i32 0, i32 0
  %131 = load i16, ptr %130, align 4, !tbaa !14
  %132 = sext i16 %131 to i32
  store i32 %132, ptr %6, align 4, !tbaa !9
  %133 = load i32, ptr %5, align 4, !tbaa !9
  %134 = load i32, ptr %4, align 4, !tbaa !9
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [63 x ptr], ptr @hu_font, i64 0, i64 %135
  %137 = load ptr, ptr %136, align 8, !tbaa !5
  call void @V_DrawPatch(i32 noundef %133, i32 noundef 180, i32 noundef 0, ptr noundef %137)
  %138 = load i32, ptr %6, align 4, !tbaa !9
  %139 = load i32, ptr %5, align 4, !tbaa !9
  %140 = add nsw i32 %139, %138
  store i32 %140, ptr %5, align 4, !tbaa !9
  br label %78, !llvm.loop !17

141:                                              ; preds = %88, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { nounwind willreturn memory(none) "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 = { inlinehint nounwind willreturn memory(read) 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 #4 = { "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6, !7, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !13}


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

@hu_font = external local_unnamed_addr global [63 x ptr], align 16

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @toupper(i32 noundef) local_unnamed_addr #0

declare void @V_DrawPatch(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @F_CastPrint(ptr noundef readonly %0) local_unnamed_addr #2 {
  %.not59 = icmp eq ptr %0, null
  br i1 %.not59, label %._crit_edge69, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not5573 = icmp eq i8 %2, 0
  br i1 %.not5573, label %._crit_edge, label %.lr.ph75

.lr.ph75:                                         ; preds = %.lr.ph.preheader, %.backedge58
  %.in = phi i8 [ %8, %.backedge58 ], [ %2, %.lr.ph.preheader ]
  %.pn = phi ptr [ %3, %.backedge58 ], [ %0, %.lr.ph.preheader ]
  %.0506074 = phi i32 [ %7, %.backedge58 ], [ 0, %.lr.ph.preheader ]
  %3 = getelementptr inbounds i8, ptr %.pn, i64 1
  %4 = sext i8 %.in to i32
  %5 = tail call i32 @toupper(i32 noundef %4) #3
  %6 = add i32 %5, -97
  %or.cond3 = icmp ult i32 %6, -64
  br i1 %or.cond3, label %.backedge58, label %9

.backedge58:                                      ; preds = %.lr.ph75, %9
  %.sink = phi i32 [ %15, %9 ], [ 4, %.lr.ph75 ]
  %7 = add nsw i32 %.0506074, %.sink
  %8 = load i8, ptr %3, align 1, !tbaa !5
  %.not55 = icmp eq i8 %8, 0
  br i1 %.not55, label %.lr.ph.._crit_edge_crit_edge, label %.lr.ph75

9:                                                ; preds = %.lr.ph75
  %10 = add nsw i32 %5, -33
  %11 = zext nneg i32 %10 to i64
  %12 = getelementptr inbounds [63 x ptr], ptr @hu_font, i64 0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !8
  %14 = load i16, ptr %13, align 4, !tbaa !10
  %15 = sext i16 %14 to i32
  br label %.backedge58

.lr.ph.._crit_edge_crit_edge:                     ; preds = %.backedge58
  %16 = sdiv i32 %7, -2
  %17 = add nsw i32 %16, 160
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.._crit_edge_crit_edge, %.lr.ph.preheader
  %.05060.lcssa = phi i32 [ %17, %.lr.ph.._crit_edge_crit_edge ], [ 160, %.lr.ph.preheader ]
  br i1 %.not59, label %._crit_edge69, label %.lr.ph68.preheader

.lr.ph68.preheader:                               ; preds = %._crit_edge
  %18 = load i8, ptr %0, align 1, !tbaa !5
  %.not5776 = icmp eq i8 %18, 0
  br i1 %.not5776, label %._crit_edge69, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph68.preheader, %.backedge
  %.in78 = phi i8 [ %24, %.backedge ], [ %18, %.lr.ph68.preheader ]
  %.pn79 = phi ptr [ %19, %.backedge ], [ %0, %.lr.ph68.preheader ]
  %.0486577 = phi i32 [ %23, %.backedge ], [ %.05060.lcssa, %.lr.ph68.preheader ]
  %19 = getelementptr inbounds i8, ptr %.pn79, i64 1
  %20 = sext i8 %.in78 to i32
  %21 = tail call i32 @toupper(i32 noundef %20) #3
  %22 = add i32 %21, -97
  %or.cond7 = icmp ult i32 %22, -64
  br i1 %or.cond7, label %.backedge, label %25

.backedge:                                        ; preds = %.lr.ph, %25
  %.sink72 = phi i32 [ %31, %25 ], [ 4, %.lr.ph ]
  %23 = add nsw i32 %.0486577, %.sink72
  %24 = load i8, ptr %19, align 1, !tbaa !5
  %.not57 = icmp eq i8 %24, 0
  br i1 %.not57, label %._crit_edge69, label %.lr.ph

25:                                               ; preds = %.lr.ph
  %26 = add nsw i32 %21, -33
  %27 = zext nneg i32 %26 to i64
  %28 = getelementptr inbounds [63 x ptr], ptr @hu_font, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !8
  %30 = load i16, ptr %29, align 4, !tbaa !10
  %31 = sext i16 %30 to i32
  tail call void @V_DrawPatch(i32 noundef %.0486577, i32 noundef 180, i32 noundef 0, ptr noundef nonnull %29) #4
  br label %.backedge

._crit_edge69:                                    ; preds = %.backedge, %.lr.ph68.preheader, %1, %._crit_edge
  ret void
}

attributes #0 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { "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 willreturn memory(read) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !6, i64 8}
!12 = !{!"short", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerConstantIntrinsicsPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass