; LLVM IR from alekmaul/pvsneslib :: snes-examples/maps/DynamicMap (DynamicMap)

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

; 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

declare zeroext i16 @element2sprite32x32(i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @drawSpriteFrame32x32(i16 noundef zeroext %0) #2 {
  %2 = alloca i16, align 2
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  store i16 %0, ptr %2, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %5

5:                                                ; preds = %41, %1
  %6 = load i8, ptr %3, align 1, !tbaa !9
  %7 = zext i8 %6 to i32
  %8 = icmp slt i32 %7, 32
  br i1 %8, label %9, label %44

9:                                                ; preds = %5
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %10

10:                                               ; preds = %37, %9
  %11 = load i8, ptr %4, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp slt i32 %12, 32
  br i1 %13, label %14, label %40

14:                                               ; preds = %10
  %15 = load i8, ptr %3, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %30, label %18

18:                                               ; preds = %14
  %19 = load i8, ptr %4, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %30, label %22

22:                                               ; preds = %18
  %23 = load i8, ptr %3, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 31
  br i1 %25, label %30, label %26

26:                                               ; preds = %22
  %27 = load i8, ptr %4, align 1, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = icmp eq i32 %28, 31
  br i1 %29, label %30, label %36

30:                                               ; preds = %26, %22, %18, %14
  %31 = load i8, ptr %3, align 1, !tbaa !9
  %32 = load i8, ptr %4, align 1, !tbaa !9
  %33 = load i16, ptr %2, align 2, !tbaa !5
  %34 = trunc i16 %33 to i8
  %35 = call zeroext i16 @element2sprite32x32(i8 noundef zeroext %34)
  call void @drawSprite32x32(i8 noundef zeroext %31, i8 noundef zeroext %32, i16 noundef zeroext %35)
  br label %36

36:                                               ; preds = %30, %26
  br label %37

37:                                               ; preds = %36
  %38 = load i8, ptr %4, align 1, !tbaa !9
  %39 = add i8 %38, 1
  store i8 %39, ptr %4, align 1, !tbaa !9
  br label %10, !llvm.loop !10

40:                                               ; preds = %10
  br label %41

41:                                               ; preds = %40
  %42 = load i8, ptr %3, align 1, !tbaa !9
  %43 = add i8 %42, 1
  store i8 %43, ptr %3, align 1, !tbaa !9
  br label %5, !llvm.loop !12

44:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret void
}

declare void @drawSprite32x32(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) #1

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

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

declare zeroext i16 @element2sprite32x32(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @drawSpriteFrame32x32(i16 noundef zeroext %0) local_unnamed_addr #1 {
  %2 = trunc i16 %0 to i8
  br label %.preheader

.preheader:                                       ; preds = %1, %.split.us
  %.01924 = phi i8 [ 0, %1 ], [ %35, %.split.us ]
  switch i8 %.01924, label %.split.us [
    i8 31, label %.preheader.split.us.preheader
    i8 0, label %.preheader.split.us.preheader
  ]

.preheader.split.us.preheader:                    ; preds = %.preheader, %.preheader
  %3 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 0, i16 noundef zeroext %3) #2
  %4 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 1, i16 noundef zeroext %4) #2
  %5 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 2, i16 noundef zeroext %5) #2
  %6 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 3, i16 noundef zeroext %6) #2
  %7 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 4, i16 noundef zeroext %7) #2
  %8 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 5, i16 noundef zeroext %8) #2
  %9 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 6, i16 noundef zeroext %9) #2
  %10 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 7, i16 noundef zeroext %10) #2
  %11 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 8, i16 noundef zeroext %11) #2
  %12 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 9, i16 noundef zeroext %12) #2
  %13 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 10, i16 noundef zeroext %13) #2
  %14 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 11, i16 noundef zeroext %14) #2
  %15 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 12, i16 noundef zeroext %15) #2
  %16 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 13, i16 noundef zeroext %16) #2
  %17 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 14, i16 noundef zeroext %17) #2
  %18 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 15, i16 noundef zeroext %18) #2
  %19 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 16, i16 noundef zeroext %19) #2
  %20 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 17, i16 noundef zeroext %20) #2
  %21 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 18, i16 noundef zeroext %21) #2
  %22 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 19, i16 noundef zeroext %22) #2
  %23 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 20, i16 noundef zeroext %23) #2
  %24 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 21, i16 noundef zeroext %24) #2
  %25 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 22, i16 noundef zeroext %25) #2
  %26 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 23, i16 noundef zeroext %26) #2
  %27 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 24, i16 noundef zeroext %27) #2
  %28 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 25, i16 noundef zeroext %28) #2
  %29 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 26, i16 noundef zeroext %29) #2
  %30 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 27, i16 noundef zeroext %30) #2
  %31 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 28, i16 noundef zeroext %31) #2
  %32 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 29, i16 noundef zeroext %32) #2
  br label %.split.us

.split.us:                                        ; preds = %.preheader, %.preheader.split.us.preheader
  %.sink = phi i8 [ 30, %.preheader.split.us.preheader ], [ 0, %.preheader ]
  %33 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext %.sink, i16 noundef zeroext %33) #2
  %34 = tail call zeroext i16 @element2sprite32x32(i8 noundef zeroext %2) #2
  tail call void @drawSprite32x32(i8 noundef zeroext %.01924, i8 noundef zeroext 31, i16 noundef zeroext %34) #2
  %35 = add nuw nsw i8 %.01924, 1
  %exitcond.not = icmp eq i8 %35, 32
  br i1 %exitcond.not, label %36, label %.preheader, !llvm.loop !5

36:                                               ; preds = %.split.us
  ret void
}

declare void @drawSprite32x32(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

attributes #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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass