; LLVM IR from achilles288/robot-monitor-graphics :: src/base/bitmap.ll (ZNK3rmg6Bitmap8getPixelEtt)

; 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.rmg::Pixel" = type { i8, i8, i8, i8, i8, i8 }
%"class.rmg::Bitmap" = type { i16, i16, i8, ptr }

@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local i48 @_ZNK3rmg6Bitmap8getPixelEtt(ptr noundef nonnull align 8 dereferenceable(16) %0, i16 noundef zeroext %1, i16 noundef zeroext %2) #2 align 2 {
  %4 = alloca %"struct.rmg::Pixel", align 1
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i48, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store i16 %2, ptr %7, align 2, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = load i16, ptr %6, align 2, !tbaa !9
  %13 = zext i16 %12 to i32
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %22

15:                                               ; preds = %3
  %16 = load i16, ptr %6, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 0
  %19 = load i16, ptr %18, align 8, !tbaa !11
  %20 = zext i16 %19 to i32
  %21 = icmp slt i32 %17, %20
  br label %22

22:                                               ; preds = %15, %3
  %23 = phi i1 [ false, %3 ], [ %21, %15 ]
  call void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext %23, ptr noundef @.str.6, ptr noundef @.str.7, i32 noundef 231)
  %24 = load i16, ptr %7, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %22
  %28 = load i16, ptr %7, align 2, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 1
  %31 = load i16, ptr %30, align 2, !tbaa !13
  %32 = zext i16 %31 to i32
  %33 = icmp slt i32 %29, %32
  br label %34

34:                                               ; preds = %27, %22
  %35 = phi i1 [ false, %22 ], [ %33, %27 ]
  call void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext %35, ptr noundef @.str.8, ptr noundef @.str.7, i32 noundef 232)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load i16, ptr %6, align 2, !tbaa !9
  %39 = zext i16 %38 to i32
  %40 = load i16, ptr %7, align 2, !tbaa !9
  %41 = zext i16 %40 to i32
  %42 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 0
  %43 = load i16, ptr %42, align 8, !tbaa !11
  %44 = zext i16 %43 to i32
  %45 = mul nsw i32 %41, %44
  %46 = add nsw i32 %39, %45
  %47 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 2
  %48 = load i8, ptr %47, align 4, !tbaa !15
  %49 = zext i8 %48 to i32
  %50 = mul nsw i32 %46, %49
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %37, i64 %51
  store ptr %52, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 2
  %54 = load i8, ptr %53, align 4, !tbaa !15
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %61

57:                                               ; preds = %34
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 0
  %60 = load i8, ptr %59, align 1, !tbaa !16
  call void @_ZN3rmg5PixelC2Eh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %60)
  store i32 1, ptr %9, align 4
  br label %101

61:                                               ; preds = %34
  %62 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 2
  %63 = load i8, ptr %62, align 4, !tbaa !15
  %64 = zext i8 %63 to i32
  %65 = icmp eq i32 %64, 2
  br i1 %65, label %66, label %73

66:                                               ; preds = %61
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 0
  %69 = load i8, ptr %68, align 1, !tbaa !16
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 1
  %72 = load i8, ptr %71, align 1, !tbaa !16
  call void @_ZN3rmg5PixelC2Ehh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %69, i8 noundef zeroext %72)
  store i32 1, ptr %9, align 4
  br label %101

73:                                               ; preds = %61
  %74 = getelementptr inbounds %"class.rmg::Bitmap", ptr %11, i32 0, i32 2
  %75 = load i8, ptr %74, align 4, !tbaa !15
  %76 = zext i8 %75 to i32
  %77 = icmp eq i32 %76, 3
  br i1 %77, label %78, label %88

78:                                               ; preds = %73
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 0
  %81 = load i8, ptr %80, align 1, !tbaa !16
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i64 1
  %84 = load i8, ptr %83, align 1, !tbaa !16
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i64 2
  %87 = load i8, ptr %86, align 1, !tbaa !16
  call void @_ZN3rmg5PixelC2Ehhh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %81, i8 noundef zeroext %84, i8 noundef zeroext %87)
  store i32 1, ptr %9, align 4
  br label %101

88:                                               ; preds = %73
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 0
  %91 = load i8, ptr %90, align 1, !tbaa !16
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i64 1
  %94 = load i8, ptr %93, align 1, !tbaa !16
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds i8, ptr %95, i64 2
  %97 = load i8, ptr %96, align 1, !tbaa !16
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i64 3
  %100 = load i8, ptr %99, align 1, !tbaa !16
  call void @_ZN3rmg5PixelC2Ehhhh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %91, i8 noundef zeroext %94, i8 noundef zeroext %97, i8 noundef zeroext %100)
  store i32 1, ptr %9, align 4
  br label %101

101:                                              ; preds = %88, %78, %66, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 1 %4, i64 6, i1 false)
  %102 = load i48, ptr %10, align 8
  ret i48 %102
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Eh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Ehh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Ehhh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Ehhhh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN3rmg6BitmapE", !10, i64 0, !10, i64 2, !7, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 2}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !7, i64 4}
!16 = !{!7, !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"

%"struct.rmg::Pixel" = type { i8, i8, i8, i8, i8, i8 }

@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local i48 @_ZNK3rmg6Bitmap8getPixelEtt(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, i16 noundef zeroext %1, i16 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = alloca %"struct.rmg::Pixel", align 8
  %5 = zext i16 %1 to i64
  %.not = icmp ne i16 %1, 0
  %6 = load i16, ptr %0, align 8
  %7 = icmp ugt i16 %6, %1
  %8 = select i1 %.not, i1 %7, i1 false
  tail call void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext %8, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.7, i32 noundef 231)
  %9 = zext i16 %2 to i64
  %.not19 = icmp ne i16 %2, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 2
  %11 = load i16, ptr %10, align 2
  %12 = icmp ugt i16 %11, %2
  %13 = select i1 %.not19, i1 %12, i1 false
  tail call void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext %13, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.7, i32 noundef 232)
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = load i16, ptr %0, align 8, !tbaa !11
  %17 = zext i16 %16 to i64
  %18 = mul nuw nsw i64 %17, %9
  %19 = add nuw nsw i64 %18, %5
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i8, ptr %20, align 4, !tbaa !12
  %22 = zext i8 %21 to i64
  %23 = mul nuw nsw i64 %19, %22
  %24 = and i64 %23, 4294967295
  %25 = getelementptr inbounds i8, ptr %15, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !13
  switch i8 %21, label %36 [
    i8 1, label %27
    i8 2, label %28
    i8 3, label %31
  ]

27:                                               ; preds = %3
  call void @_ZN3rmg5PixelC2Eh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %26)
  br label %43

28:                                               ; preds = %3
  %29 = getelementptr inbounds i8, ptr %25, i64 1
  %30 = load i8, ptr %29, align 1, !tbaa !13
  call void @_ZN3rmg5PixelC2Ehh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %26, i8 noundef zeroext %30)
  br label %43

31:                                               ; preds = %3
  %32 = getelementptr inbounds i8, ptr %25, i64 1
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %25, i64 2
  %35 = load i8, ptr %34, align 1, !tbaa !13
  call void @_ZN3rmg5PixelC2Ehhh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %26, i8 noundef zeroext %33, i8 noundef zeroext %35)
  br label %43

36:                                               ; preds = %3
  %37 = getelementptr inbounds i8, ptr %25, i64 1
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %25, i64 2
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = getelementptr inbounds i8, ptr %25, i64 3
  %42 = load i8, ptr %41, align 1, !tbaa !13
  call void @_ZN3rmg5PixelC2Ehhhh(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 noundef zeroext %26, i8 noundef zeroext %38, i8 noundef zeroext %40, i8 noundef zeroext %42)
  br label %43

43:                                               ; preds = %36, %31, %28, %27
  %.0.copyload = load i48, ptr %4, align 8
  ret i48 %.0.copyload
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Eh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Ehh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Ehhh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg5PixelC2Ehhhh(ptr noundef nonnull align 1 dereferenceable(6), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #2 align 2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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, !10, i64 8}
!6 = !{!"_ZTSN3rmg6BitmapE", !7, i64 0, !7, i64 2, !8, i64 4, !10, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !8, i64 4}
!13 = !{!8, !8, i64 0}


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