; LLVM IR from aap/librw :: src/image.ll (ZN2rw5Image10removeMaskEv)

; 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.rw::Image" = type { i32, i32, i32, i32, i32, i32, ptr, ptr }

@.str.2 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw5Image10removeMaskEv = external hidden unnamed_addr constant [29 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw5Image10removeMaskEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  %11 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 3
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp sle i32 %12, 8
  br i1 %13, label %14, label %42

14:                                               ; preds = %1
  %15 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 7
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  br label %21

19:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.2, i32 noundef 820, ptr noundef @__PRETTY_FUNCTION__._ZN2rw5Image10removeMaskEv) #3
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %22 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = shl i32 1, %23
  %25 = mul nsw i32 4, %24
  store i32 %25, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %38, %21
  %27 = load i32, ptr %4, align 4, !tbaa !13
  %28 = load i32, ptr %3, align 4, !tbaa !13
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %41

31:                                               ; preds = %26
  %32 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 7
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  %34 = load i32, ptr %4, align 4, !tbaa !13
  %35 = add nsw i32 %34, 3
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  store i8 -1, ptr %37, align 1, !tbaa !14
  br label %38

38:                                               ; preds = %31
  %39 = load i32, ptr %4, align 4, !tbaa !13
  %40 = add nsw i32 %39, 4
  store i32 %40, ptr %4, align 4, !tbaa !13
  br label %26, !llvm.loop !15

41:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %102

42:                                               ; preds = %1
  %43 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 3
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 24
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  br label %102

47:                                               ; preds = %42
  %48 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  br label %54

52:                                               ; preds = %47
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.2, i32 noundef 828, ptr noundef @__PRETTY_FUNCTION__._ZN2rw5Image10removeMaskEv) #3
  unreachable

53:                                               ; No predecessors!
  br label %54

54:                                               ; preds = %53, %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %55 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 6
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  store ptr %56, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %57

57:                                               ; preds = %98, %54
  %58 = load i32, ptr %7, align 4, !tbaa !13
  %59 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 2
  %60 = load i32, ptr %59, align 8, !tbaa !18
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %57
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %101

63:                                               ; preds = %57
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %65

65:                                               ; preds = %89, %63
  %66 = load i32, ptr %9, align 4, !tbaa !13
  %67 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !19
  %69 = icmp slt i32 %66, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %65
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %92

71:                                               ; preds = %65
  %72 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 3
  %73 = load i32, ptr %72, align 4, !tbaa !9
  switch i32 %73, label %88 [
    i32 16, label %74
    i32 32, label %83
  ]

74:                                               ; preds = %71
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i64 1
  %77 = load i8, ptr %76, align 1, !tbaa !14
  %78 = zext i8 %77 to i32
  %79 = or i32 %78, 128
  %80 = trunc i32 %79 to i8
  store i8 %80, ptr %76, align 1, !tbaa !14
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 2
  store ptr %82, ptr %6, align 8, !tbaa !5
  br label %88

83:                                               ; preds = %71
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 3
  store i8 -1, ptr %85, align 1, !tbaa !14
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds i8, ptr %86, i64 4
  store ptr %87, ptr %6, align 8, !tbaa !5
  br label %88

88:                                               ; preds = %83, %74, %71
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %9, align 4, !tbaa !13
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %9, align 4, !tbaa !13
  br label %65, !llvm.loop !20

92:                                               ; preds = %70
  %93 = getelementptr inbounds %"struct.rw::Image", ptr %10, i32 0, i32 5
  %94 = load i32, ptr %93, align 4, !tbaa !21
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = sext i32 %94 to i64
  %97 = getelementptr inbounds i8, ptr %95, i64 %96
  store ptr %97, ptr %5, align 8, !tbaa !5
  br label %98

98:                                               ; preds = %92
  %99 = load i32, ptr %7, align 4, !tbaa !13
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %7, align 4, !tbaa !13
  br label %57, !llvm.loop !22

101:                                              ; preds = %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %102

102:                                              ; preds = %101, %46, %41
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 12}
!10 = !{!"_ZTSN2rw5ImageE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 32}
!13 = !{!11, !11, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 24}
!18 = !{!10, !11, i64 8}
!19 = !{!10, !11, i64 4}
!20 = distinct !{!20, !16}
!21 = !{!10, !11, i64 20}
!22 = distinct !{!22, !16}


; 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 [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw5Image10removeMaskEv = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw5Image10removeMaskEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 9
  br i1 %4, label %5, label %17

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %.not21 = icmp eq ptr %7, null
  br i1 %.not21, label %8, label %9

8:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.2, i32 noundef 820, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw5Image10removeMaskEv) #2
  unreachable

9:                                                ; preds = %5
  %10 = shl nuw nsw i32 4, %3
  %11 = zext nneg i32 %10 to i64
  br label %12

12:                                               ; preds = %9, %12
  %indvars.iv = phi i64 [ 0, %9 ], [ %indvars.iv.next, %12 ]
  %13 = load ptr, ptr %6, align 8, !tbaa !11
  %14 = or disjoint i64 %indvars.iv, 3
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  store i8 -1, ptr %15, align 1, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 4
  %16 = icmp ult i64 %indvars.iv.next, %11
  br i1 %16, label %12, label %.loopexit, !llvm.loop !13

17:                                               ; preds = %1
  %18 = icmp eq i32 %3, 24
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %29, label %.preheader22

.preheader22:                                     ; preds = %19
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %.preheader22
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  %26 = getelementptr inbounds i8, ptr %0, i64 20
  %27 = load i32, ptr %25, align 4, !tbaa !17
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.preheader, label %.loopexit

29:                                               ; preds = %19
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.2, i32 noundef 828, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw5Image10removeMaskEv) #2
  unreachable

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %30 = phi i32 [ %33, %._crit_edge ], [ %23, %.preheader.lr.ph ]
  %31 = phi i32 [ %34, %._crit_edge ], [ %27, %.preheader.lr.ph ]
  %.01427 = phi i32 [ %38, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.01626 = phi ptr [ %37, %._crit_edge ], [ %21, %.preheader.lr.ph ]
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %49
  %.pre = load i32, ptr %22, align 8, !tbaa !16
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %33 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %30, %.preheader ]
  %34 = phi i32 [ %51, %._crit_edge.loopexit ], [ %31, %.preheader ]
  %35 = load i32, ptr %26, align 4, !tbaa !18
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %.01626, i64 %36
  %38 = add nuw nsw i32 %.01427, 1
  %39 = icmp slt i32 %38, %33
  br i1 %39, label %.preheader, label %.loopexit, !llvm.loop !19

.lr.ph:                                           ; preds = %.preheader, %49
  %.025 = phi i32 [ %50, %49 ], [ 0, %.preheader ]
  %.01524 = phi ptr [ %.1, %49 ], [ %.01626, %.preheader ]
  %40 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %40, label %49 [
    i32 16, label %41
    i32 32, label %46
  ]

41:                                               ; preds = %.lr.ph
  %42 = getelementptr inbounds i8, ptr %.01524, i64 1
  %43 = load i8, ptr %42, align 1, !tbaa !12
  %44 = or i8 %43, -128
  store i8 %44, ptr %42, align 1, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %.01524, i64 2
  br label %49

46:                                               ; preds = %.lr.ph
  %47 = getelementptr inbounds i8, ptr %.01524, i64 3
  store i8 -1, ptr %47, align 1, !tbaa !12
  %48 = getelementptr inbounds i8, ptr %.01524, i64 4
  br label %49

49:                                               ; preds = %.lr.ph, %41, %46
  %.1 = phi ptr [ %.01524, %.lr.ph ], [ %48, %46 ], [ %45, %41 ]
  %50 = add nuw nsw i32 %.025, 1
  %51 = load i32, ptr %25, align 4, !tbaa !17
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %._crit_edge, %12, %.preheader.lr.ph, %.preheader22, %17
  ret void
}

attributes #0 = { noreturn nounwind "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 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 = { noreturn 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, !7, i64 12}
!6 = !{!"_ZTSN2rw5ImageE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 32}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !7, i64 4}
!18 = !{!6, !7, i64 20}
!19 = distinct !{!19, !14, !20}
!20 = !{!"llvm.loop.unswitch.partial.disable"}
!21 = distinct !{!21, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass