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

@c64_sprite = external global 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @isBitSet(i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @getPixel(i8 noundef zeroext %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext %3) #1 {
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  store i8 %0, ptr %5, align 1, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !5
  store i8 %3, ptr %8, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store volatile i64 ptrtoint (ptr @c64_sprite to i64), ptr %9, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %15 = load i8, ptr %7, align 1, !tbaa !5
  %16 = zext i8 %15 to i32
  %17 = and i32 %16, 254
  store i32 %17, ptr %10, align 4, !tbaa !10
  %18 = load i8, ptr %6, align 1, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = icmp sge i32 %19, 2
  br i1 %20, label %21, label %30

21:                                               ; preds = %4
  %22 = load i8, ptr %6, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = sub nsw i32 %23, 2
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr %6, align 1, !tbaa !5
  %26 = load i8, ptr %5, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = add nsw i32 %27, 16
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %5, align 1, !tbaa !5
  br label %30

30:                                               ; preds = %21, %4
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #2
  %31 = load volatile i64, ptr %9, align 8, !tbaa !8
  %32 = load i8, ptr %5, align 1, !tbaa !5
  %33 = zext i8 %32 to i32
  %34 = mul nsw i32 %33, 8
  %35 = sext i32 %34 to i64
  %36 = add i64 %31, %35
  %37 = load i8, ptr %6, align 1, !tbaa !5
  %38 = zext i8 %37 to i32
  %39 = mul nsw i32 8, %38
  %40 = sext i32 %39 to i64
  %41 = add i64 %36, %40
  %42 = load i8, ptr %8, align 1, !tbaa !5
  %43 = zext i8 %42 to i64
  %44 = add i64 %41, %43
  %45 = inttoptr i64 %44 to ptr
  %46 = load i8, ptr %45, align 1, !tbaa !5
  store i8 %46, ptr %11, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  %47 = load i8, ptr %11, align 1, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !10
  %49 = sub nsw i32 7, %48
  %50 = trunc i32 %49 to i8
  %51 = call zeroext i8 @isBitSet(i8 noundef zeroext %47, i8 noundef zeroext %50)
  store i8 %51, ptr %12, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  %52 = load i8, ptr %11, align 1, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !10
  %54 = sub nsw i32 7, %53
  %55 = sub nsw i32 %54, 1
  %56 = trunc i32 %55 to i8
  %57 = call zeroext i8 @isBitSet(i8 noundef zeroext %52, i8 noundef zeroext %56)
  store i8 %57, ptr %13, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  %58 = load i8, ptr %13, align 1, !tbaa !5
  %59 = zext i8 %58 to i32
  %60 = shl i32 %59, 1
  %61 = load i8, ptr %12, align 1, !tbaa !5
  %62 = zext i8 %61 to i32
  %63 = or i32 %60, %62
  %64 = trunc i32 %63 to i8
  store i8 %64, ptr %14, align 1, !tbaa !5
  %65 = load i8, ptr %14, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i8 %65
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, 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"

@c64_sprite = external global i8, align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @isBitSet(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @getPixel(i8 noundef zeroext %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5)
  store volatile i64 ptrtoint (ptr @c64_sprite to i64), ptr %5, align 8, !tbaa !5
  %6 = icmp ugt i8 %1, 1
  %7 = add i8 %1, -2
  %8 = add i8 %0, 16
  %.014 = select i1 %6, i8 %7, i8 %1
  %.0 = select i1 %6, i8 %8, i8 %0
  %9 = and i8 %2, -2
  %.0..0..0..0. = load volatile i64, ptr %5, align 8, !tbaa !5
  %10 = zext i8 %.0 to i64
  %11 = zext i8 %.014 to i64
  %12 = zext i8 %3 to i64
  %reass.add = add nuw nsw i64 %11, %10
  %reass.mul = shl nuw nsw i64 %reass.add, 3
  %13 = add nuw nsw i64 %reass.mul, %12
  %14 = add i64 %13, %.0..0..0..0.
  %15 = inttoptr i64 %14 to ptr
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sub i8 7, %9
  %18 = tail call zeroext i8 @isBitSet(i8 noundef zeroext %16, i8 noundef zeroext %17)
  %19 = sub i8 6, %9
  %20 = tail call zeroext i8 @isBitSet(i8 noundef zeroext %16, i8 noundef zeroext %19)
  %21 = shl i8 %20, 1
  %22 = or i8 %21, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5)
  ret i8 %22
}

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

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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