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

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

@.str.2 = external hidden unnamed_addr constant [25 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

declare void @V_CopyRect(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

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

; 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 @STlib_updateMultIcon(ptr noundef %0, i32 noundef %1) #3 {
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.st_multicon_t, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %142

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.st_multicon_t, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.st_multicon_t, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp ne i32 %21, %25
  br i1 %26, label %30, label %27

27:                                               ; preds = %18
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %142

30:                                               ; preds = %27, %18
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.st_multicon_t, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = icmp ne i32 %34, -1
  br i1 %35, label %36, label %142

36:                                               ; preds = %30
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.st_multicon_t, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = icmp ne i32 %39, -1
  br i1 %40, label %41, label %116

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.st_multicon_t, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.st_multicon_t, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.st_multicon_t, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 8, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %47, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.patch_t, ptr %53, i32 0, i32 2
  %55 = load i16, ptr %54, align 4, !tbaa !17
  %56 = sext i16 %55 to i32
  %57 = sub nsw i32 %44, %56
  store i32 %57, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.st_multicon_t, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !20
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.st_multicon_t, ptr %61, i32 0, i32 5
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.st_multicon_t, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !13
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %63, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.patch_t, ptr %69, i32 0, i32 3
  %71 = load i16, ptr %70, align 2, !tbaa !21
  %72 = sext i16 %71 to i32
  %73 = sub nsw i32 %60, %72
  store i32 %73, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.st_multicon_t, ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.st_multicon_t, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds ptr, ptr %76, i64 %80
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.patch_t, ptr %82, i32 0, i32 0
  %84 = load i16, ptr %83, align 4, !tbaa !22
  %85 = sext i16 %84 to i32
  store i32 %85, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.st_multicon_t, ptr %86, i32 0, i32 5
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.st_multicon_t, ptr %89, i32 0, i32 2
  %91 = load i32, ptr %90, align 8, !tbaa !13
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds ptr, ptr %88, i64 %92
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.patch_t, ptr %94, i32 0, i32 1
  %96 = load i16, ptr %95, align 2, !tbaa !23
  %97 = sext i16 %96 to i32
  store i32 %97, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %98 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %98, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = sub nsw i32 %99, 168
  store i32 %100, ptr %10, align 4, !tbaa !9
  %101 = load i32, ptr %10, align 4, !tbaa !9
  %102 = icmp slt i32 %101, 0
  br i1 %102, label %103, label %104

103:                                              ; preds = %41
  call void (ptr, ...) @I_Error(ptr noundef @.str.2) #5
  unreachable

104:                                              ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %105 = load i32, ptr %5, align 4, !tbaa !9
  %106 = add nsw i32 %105, 0
  store i32 %106, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %107 = load i32, ptr %6, align 4, !tbaa !9
  %108 = sub nsw i32 %107, 200
  %109 = add nsw i32 %108, 200
  store i32 %109, ptr %12, align 4, !tbaa !9
  %110 = load i32, ptr %9, align 4, !tbaa !9
  %111 = load i32, ptr %10, align 4, !tbaa !9
  %112 = load i32, ptr %7, align 4, !tbaa !9
  %113 = load i32, ptr %8, align 4, !tbaa !9
  %114 = load i32, ptr %11, align 4, !tbaa !9
  %115 = load i32, ptr %12, align 4, !tbaa !9
  call void @V_CopyRect(i32 noundef %110, i32 noundef %111, i32 noundef 4, i32 noundef %112, i32 noundef %113, i32 noundef %114, i32 noundef %115, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %116

116:                                              ; preds = %104, %36
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.st_multicon_t, ptr %117, i32 0, i32 0
  %119 = load i32, ptr %118, align 8, !tbaa !15
  %120 = add nsw i32 %119, 0
  %121 = load ptr, ptr %3, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.st_multicon_t, ptr %121, i32 0, i32 1
  %123 = load i32, ptr %122, align 4, !tbaa !20
  %124 = sub nsw i32 %123, 200
  %125 = add nsw i32 %124, 200
  %126 = load ptr, ptr %3, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.st_multicon_t, ptr %126, i32 0, i32 5
  %128 = load ptr, ptr %127, align 8, !tbaa !16
  %129 = load ptr, ptr %3, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.st_multicon_t, ptr %129, i32 0, i32 3
  %131 = load ptr, ptr %130, align 8, !tbaa !14
  %132 = load i32, ptr %131, align 4, !tbaa !9
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds ptr, ptr %128, i64 %133
  %135 = load ptr, ptr %134, align 8, !tbaa !5
  call void @V_DrawPatch(i32 noundef %120, i32 noundef %125, i32 noundef 0, ptr noundef %135)
  %136 = load ptr, ptr %3, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.st_multicon_t, ptr %136, i32 0, i32 3
  %138 = load ptr, ptr %137, align 8, !tbaa !14
  %139 = load i32, ptr %138, align 4, !tbaa !9
  %140 = load ptr, ptr %3, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.st_multicon_t, ptr %140, i32 0, i32 2
  store i32 %139, ptr %141, align 8, !tbaa !13
  br label %142

142:                                              ; preds = %116, %30, %27, %2
  ret void
}

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 = { "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 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 = { 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 = !{!"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 = !{!12, !6, i64 24}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !6, i64 32}
!17 = !{!18, !19, i64 4}
!18 = !{!"", !19, i64 0, !19, i64 2, !19, i64 4, !19, i64 6, !7, i64 8}
!19 = !{!"short", !7, i64 0}
!20 = !{!12, !10, i64 4}
!21 = !{!18, !19, i64 6}
!22 = !{!18, !19, i64 0}
!23 = !{!18, !19, i64 2}


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

@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1

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

declare void @V_CopyRect(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @STlib_updateMultIcon(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %53, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = icmp eq i32 %8, %11
  %13 = icmp eq i32 %1, 0
  %or.cond.not39 = and i1 %13, %12
  %.not34 = icmp eq i32 %11, -1
  %or.cond36 = or i1 %.not34, %or.cond.not39
  br i1 %or.cond36, label %53, label %14

14:                                               ; preds = %6
  %.not35 = icmp eq i32 %8, -1
  br i1 %.not35, label %41, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = sext i32 %8 to i64
  %19 = getelementptr inbounds ptr, ptr %17, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %20, i64 6
  %24 = load i16, ptr %23, align 2, !tbaa !17
  %25 = sext i16 %24 to i32
  %26 = sub nsw i32 %22, %25
  %27 = icmp slt i32 %26, 168
  br i1 %27, label %28, label %29

28:                                               ; preds = %15
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.2) #3
  unreachable

29:                                               ; preds = %15
  %30 = add nsw i32 %26, -168
  %31 = getelementptr inbounds i8, ptr %20, i64 2
  %32 = load i16, ptr %31, align 2, !tbaa !20
  %33 = sext i16 %32 to i32
  %34 = load i16, ptr %20, align 4, !tbaa !21
  %35 = sext i16 %34 to i32
  %36 = load i32, ptr %0, align 8, !tbaa !22
  %37 = getelementptr inbounds i8, ptr %20, i64 4
  %38 = load i16, ptr %37, align 4, !tbaa !23
  %39 = sext i16 %38 to i32
  %40 = sub nsw i32 %36, %39
  tail call void @V_CopyRect(i32 noundef %40, i32 noundef %30, i32 noundef 4, i32 noundef %35, i32 noundef %33, i32 noundef %40, i32 noundef %26, i32 noundef 0) #4
  %.pre = load ptr, ptr %9, align 8, !tbaa !13
  %.pre40 = load i32, ptr %.pre, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %29, %14
  %42 = phi i32 [ %.pre40, %29 ], [ %11, %14 ]
  %43 = load i32, ptr %0, align 8, !tbaa !22
  %44 = getelementptr inbounds i8, ptr %0, i64 4
  %45 = load i32, ptr %44, align 4, !tbaa !16
  %46 = getelementptr inbounds i8, ptr %0, i64 32
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = sext i32 %42 to i64
  %49 = getelementptr inbounds ptr, ptr %47, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  tail call void @V_DrawPatch(i32 noundef %43, i32 noundef %45, i32 noundef 0, ptr noundef %50) #4
  %51 = load ptr, ptr %9, align 8, !tbaa !13
  %52 = load i32, ptr %51, align 4, !tbaa !11
  store i32 %52, ptr %7, align 8, !tbaa !12
  br label %53

53:                                               ; preds = %6, %41, %2
  ret void
}

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 = { "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 = { 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, !10, i64 24}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 32}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !7, i64 4}
!17 = !{!18, !19, i64 6}
!18 = !{!"", !19, i64 0, !19, i64 2, !19, i64 4, !19, i64 6, !8, i64 8}
!19 = !{!"short", !8, i64 0}
!20 = !{!18, !19, i64 2}
!21 = !{!18, !19, i64 0}
!22 = !{!6, !7, i64 0}
!23 = !{!18, !19, i64 4}


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