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

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

%"class.rmg::Bitmap" = type { i16, i16, i8, ptr }
%"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: 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: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg6Bitmap8setPixelEttRKNS_5PixelE(ptr noundef nonnull align 8 dereferenceable(16) %0, i16 noundef zeroext %1, i16 noundef zeroext %2, ptr noundef nonnull align 1 dereferenceable(6) %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca ptr, 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = load i16, ptr %6, align 2, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %21

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

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

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

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

56:                                               ; preds = %33
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.rmg::Pixel", ptr %57, i32 0, i32 3
  %59 = load i8, ptr %58, align 1, !tbaa !16
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 0
  store i8 %59, ptr %61, align 1, !tbaa !18
  br label %122

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

67:                                               ; preds = %62
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.rmg::Pixel", ptr %68, i32 0, i32 3
  %70 = load i8, ptr %69, align 1, !tbaa !16
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 0
  store i8 %70, ptr %72, align 1, !tbaa !18
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.rmg::Pixel", ptr %73, i32 0, i32 4
  %75 = load i8, ptr %74, align 1, !tbaa !19
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 1
  store i8 %75, ptr %77, align 1, !tbaa !18
  br label %121

78:                                               ; preds = %62
  %79 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 2
  %80 = load i8, ptr %79, align 4, !tbaa !15
  %81 = zext i8 %80 to i32
  %82 = icmp eq i32 %81, 3
  br i1 %82, label %83, label %99

83:                                               ; preds = %78
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %"struct.rmg::Pixel", ptr %84, i32 0, i32 0
  %86 = load i8, ptr %85, align 1, !tbaa !20
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 0
  store i8 %86, ptr %88, align 1, !tbaa !18
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds %"struct.rmg::Pixel", ptr %89, i32 0, i32 1
  %91 = load i8, ptr %90, align 1, !tbaa !21
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i64 1
  store i8 %91, ptr %93, align 1, !tbaa !18
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds %"struct.rmg::Pixel", ptr %94, i32 0, i32 2
  %96 = load i8, ptr %95, align 1, !tbaa !22
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 2
  store i8 %96, ptr %98, align 1, !tbaa !18
  br label %120

99:                                               ; preds = %78
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = getelementptr inbounds %"struct.rmg::Pixel", ptr %100, i32 0, i32 0
  %102 = load i8, ptr %101, align 1, !tbaa !20
  %103 = load ptr, ptr %9, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 0
  store i8 %102, ptr %104, align 1, !tbaa !18
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds %"struct.rmg::Pixel", ptr %105, i32 0, i32 1
  %107 = load i8, ptr %106, align 1, !tbaa !21
  %108 = load ptr, ptr %9, align 8, !tbaa !5
  %109 = getelementptr inbounds i8, ptr %108, i64 1
  store i8 %107, ptr %109, align 1, !tbaa !18
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = getelementptr inbounds %"struct.rmg::Pixel", ptr %110, i32 0, i32 2
  %112 = load i8, ptr %111, align 1, !tbaa !22
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = getelementptr inbounds i8, ptr %113, i64 2
  store i8 %112, ptr %114, align 1, !tbaa !18
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = getelementptr inbounds %"struct.rmg::Pixel", ptr %115, i32 0, i32 4
  %117 = load i8, ptr %116, align 1, !tbaa !19
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  %119 = getelementptr inbounds i8, ptr %118, i64 3
  store i8 %117, ptr %119, align 1, !tbaa !18
  br label %120

120:                                              ; preds = %99, %83
  br label %121

121:                                              ; preds = %120, %67
  br label %122

122:                                              ; preds = %121, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!17, !7, i64 3}
!17 = !{!"_ZTSN3rmg5PixelE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5}
!18 = !{!7, !7, i64 0}
!19 = !{!17, !7, i64 4}
!20 = !{!17, !7, i64 0}
!21 = !{!17, !7, i64 1}
!22 = !{!17, !7, 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.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: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_assertbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg6Bitmap8setPixelEttRKNS_5PixelE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, i16 noundef zeroext %1, i16 noundef zeroext %2, ptr nocapture noundef nonnull readonly align 1 dereferenceable(6) %3) local_unnamed_addr #1 align 2 {
  %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 253)
  %9 = zext i16 %2 to i64
  %.not28 = 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 %.not28, 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 254)
  %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
  switch i8 %21, label %43 [
    i8 1, label %26
    i8 2, label %29
    i8 3, label %35
  ]

26:                                               ; preds = %4
  %27 = getelementptr inbounds i8, ptr %3, i64 3
  %28 = load i8, ptr %27, align 1, !tbaa !13
  store i8 %28, ptr %25, align 1, !tbaa !15
  br label %54

29:                                               ; preds = %4
  %30 = getelementptr inbounds i8, ptr %3, i64 3
  %31 = load i8, ptr %30, align 1, !tbaa !13
  store i8 %31, ptr %25, align 1, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %3, i64 4
  %33 = load i8, ptr %32, align 1, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %25, i64 1
  store i8 %33, ptr %34, align 1, !tbaa !15
  br label %54

35:                                               ; preds = %4
  %36 = load i8, ptr %3, align 1, !tbaa !17
  store i8 %36, ptr %25, align 1, !tbaa !15
  %37 = getelementptr inbounds i8, ptr %3, i64 1
  %38 = load i8, ptr %37, align 1, !tbaa !18
  %39 = getelementptr inbounds i8, ptr %25, i64 1
  store i8 %38, ptr %39, align 1, !tbaa !15
  %40 = getelementptr inbounds i8, ptr %3, i64 2
  %41 = load i8, ptr %40, align 1, !tbaa !19
  %42 = getelementptr inbounds i8, ptr %25, i64 2
  store i8 %41, ptr %42, align 1, !tbaa !15
  br label %54

43:                                               ; preds = %4
  %44 = load i8, ptr %3, align 1, !tbaa !17
  store i8 %44, ptr %25, align 1, !tbaa !15
  %45 = getelementptr inbounds i8, ptr %3, i64 1
  %46 = load i8, ptr %45, align 1, !tbaa !18
  %47 = getelementptr inbounds i8, ptr %25, i64 1
  store i8 %46, ptr %47, align 1, !tbaa !15
  %48 = getelementptr inbounds i8, ptr %3, i64 2
  %49 = load i8, ptr %48, align 1, !tbaa !19
  %50 = getelementptr inbounds i8, ptr %25, i64 2
  store i8 %49, ptr %50, align 1, !tbaa !15
  %51 = getelementptr inbounds i8, ptr %3, i64 4
  %52 = load i8, ptr %51, align 1, !tbaa !16
  %53 = getelementptr inbounds i8, ptr %25, i64 3
  store i8 %52, ptr %53, align 1, !tbaa !15
  br label %54

54:                                               ; preds = %29, %43, %35, %26
  ret void
}

attributes #0 = { 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 #1 = { 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" }

!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 = !{!14, !8, i64 3}
!14 = !{!"_ZTSN3rmg5PixelE", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5}
!15 = !{!8, !8, i64 0}
!16 = !{!14, !8, i64 4}
!17 = !{!14, !8, i64 0}
!18 = !{!14, !8, i64 1}
!19 = !{!14, !8, i64 2}


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