; LLVM IR from ox-vgg/vise :: src/search_engine/relja_retrival/external/KMCode_relja/ImageContent/ImageConten_6779f66d (ZN12ImageContent6toGRAYEv)

; 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.ImageContent = type { i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; 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: mustprogress uwtable
declare dso_local void @_ZN12ImageContent9initUCharEjj(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12ImageContent6toGRAYEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 3
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 5
  br i1 %7, label %8, label %103

8:                                                ; preds = %1
  %9 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !13
  call void @_ZN12ImageContent9initUCharEjj(ptr noundef nonnull align 8 dereferenceable(80) %4, i32 noundef %10, i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %13

13:                                               ; preds = %59, %8
  %14 = load i32, ptr %3, align 4, !tbaa !14
  %15 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !15
  %17 = icmp ult i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %62

19:                                               ; preds = %13
  %20 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 9
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds ptr, ptr %21, i64 0
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !14
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !17
  %28 = zext i8 %27 to i32
  %29 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 10
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = getelementptr inbounds ptr, ptr %30, i64 0
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !14
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !17
  %37 = zext i8 %36 to i32
  %38 = add nsw i32 %28, %37
  %39 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 11
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = getelementptr inbounds ptr, ptr %40, i64 0
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !14
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %42, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !17
  %47 = zext i8 %46 to i32
  %48 = add nsw i32 %38, %47
  %49 = sitofp i32 %48 to double
  %50 = fdiv double %49, 3.000000e+00
  %51 = fptoui double %50 to i8
  %52 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 8
  %53 = load ptr, ptr %52, align 8, !tbaa !20
  %54 = getelementptr inbounds ptr, ptr %53, i64 0
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !14
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  store i8 %51, ptr %58, align 1, !tbaa !17
  br label %59

59:                                               ; preds = %19
  %60 = load i32, ptr %3, align 4, !tbaa !14
  %61 = add i32 %60, 1
  store i32 %61, ptr %3, align 4, !tbaa !14
  br label %13, !llvm.loop !21

62:                                               ; preds = %18
  %63 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 9
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  %65 = getelementptr inbounds ptr, ptr %64, i64 0
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = icmp eq ptr %66, null
  br i1 %67, label %69, label %68

68:                                               ; preds = %62
  call void @_ZdaPv(ptr noundef %66) #4
  br label %69

69:                                               ; preds = %68, %62
  %70 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 9
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  %72 = icmp eq ptr %71, null
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  call void @_ZdaPv(ptr noundef %71) #4
  br label %74

74:                                               ; preds = %73, %69
  %75 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 9
  store ptr null, ptr %75, align 8, !tbaa !16
  %76 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 10
  %77 = load ptr, ptr %76, align 8, !tbaa !18
  %78 = getelementptr inbounds ptr, ptr %77, i64 0
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = icmp eq ptr %79, null
  br i1 %80, label %82, label %81

81:                                               ; preds = %74
  call void @_ZdaPv(ptr noundef %79) #4
  br label %82

82:                                               ; preds = %81, %74
  %83 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 10
  %84 = load ptr, ptr %83, align 8, !tbaa !18
  %85 = icmp eq ptr %84, null
  br i1 %85, label %87, label %86

86:                                               ; preds = %82
  call void @_ZdaPv(ptr noundef %84) #4
  br label %87

87:                                               ; preds = %86, %82
  %88 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 10
  store ptr null, ptr %88, align 8, !tbaa !18
  %89 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 11
  %90 = load ptr, ptr %89, align 8, !tbaa !19
  %91 = getelementptr inbounds ptr, ptr %90, i64 0
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  %93 = icmp eq ptr %92, null
  br i1 %93, label %95, label %94

94:                                               ; preds = %87
  call void @_ZdaPv(ptr noundef %92) #4
  br label %95

95:                                               ; preds = %94, %87
  %96 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 11
  %97 = load ptr, ptr %96, align 8, !tbaa !19
  %98 = icmp eq ptr %97, null
  br i1 %98, label %100, label %99

99:                                               ; preds = %95
  call void @_ZdaPv(ptr noundef %97) #4
  br label %100

100:                                              ; preds = %99, %95
  %101 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 11
  store ptr null, ptr %101, align 8, !tbaa !19
  %102 = getelementptr inbounds %class.ImageContent, ptr %4, i32 0, i32 3
  store i32 1, ptr %102, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %100, %1
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nobuiltin 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 #3 = { nounwind }
attributes #4 = { builtin 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 = !{!"_ZTS12ImageContent", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !6, i64 56}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !6, i64 64}
!19 = !{!10, !6, i64 72}
!20 = !{!10, !6, i64 48}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12ImageContent9initUCharEjj(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12ImageContent6toGRAYEv(ptr noundef nonnull align 8 dereferenceable(80) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 5
  br i1 %4, label %5, label %66

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = load i32, ptr %0, align 8, !tbaa !12
  tail call void @_ZN12ImageContent9initUCharEjj(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %7, i32 noundef %8)
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = getelementptr inbounds i8, ptr %0, i64 72
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  br label %19

._crit_edge:                                      ; preds = %19, %5
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.thread, label %46

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %20 = load ptr, ptr %11, align 8, !tbaa !14
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !16
  %24 = zext i8 %23 to i32
  %25 = load ptr, ptr %12, align 8, !tbaa !17
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %26, i64 %indvars.iv
  %28 = load i8, ptr %27, align 1, !tbaa !16
  %29 = zext i8 %28 to i32
  %30 = add nuw nsw i32 %29, %24
  %31 = load ptr, ptr %13, align 8, !tbaa !18
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %32, i64 %indvars.iv
  %34 = load i8, ptr %33, align 1, !tbaa !16
  %35 = zext i8 %34 to i32
  %36 = add nuw nsw i32 %30, %35
  %37 = uitofp nneg i32 %36 to double
  %38 = fdiv double %37, 3.000000e+00
  %39 = fptoui double %38 to i8
  %40 = load ptr, ptr %14, align 8, !tbaa !19
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds i8, ptr %41, i64 %indvars.iv
  store i8 %39, ptr %42, align 1, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load i32, ptr %9, align 8, !tbaa !13
  %44 = zext i32 %43 to i64
  %45 = icmp ult i64 %indvars.iv.next, %44
  br i1 %45, label %19, label %._crit_edge, !llvm.loop !20

46:                                               ; preds = %._crit_edge
  tail call void @_ZdaPv(ptr noundef nonnull %17) #2
  %.pr = load ptr, ptr %15, align 8, !tbaa !14
  %47 = icmp eq ptr %.pr, null
  br i1 %47, label %49, label %.thread

.thread:                                          ; preds = %._crit_edge, %46
  %48 = phi ptr [ %.pr, %46 ], [ %16, %._crit_edge ]
  tail call void @_ZdaPv(ptr noundef nonnull %48) #2
  br label %49

49:                                               ; preds = %.thread, %46
  store ptr null, ptr %15, align 8, !tbaa !14
  %50 = getelementptr inbounds i8, ptr %0, i64 64
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = icmp eq ptr %52, null
  br i1 %53, label %.thread16, label %54

54:                                               ; preds = %49
  tail call void @_ZdaPv(ptr noundef nonnull %52) #2
  %.pr12 = load ptr, ptr %50, align 8, !tbaa !17
  %55 = icmp eq ptr %.pr12, null
  br i1 %55, label %57, label %.thread16

.thread16:                                        ; preds = %49, %54
  %56 = phi ptr [ %.pr12, %54 ], [ %51, %49 ]
  tail call void @_ZdaPv(ptr noundef nonnull %56) #2
  br label %57

57:                                               ; preds = %.thread16, %54
  store ptr null, ptr %50, align 8, !tbaa !17
  %58 = getelementptr inbounds i8, ptr %0, i64 72
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = icmp eq ptr %60, null
  br i1 %61, label %.thread17, label %62

62:                                               ; preds = %57
  tail call void @_ZdaPv(ptr noundef nonnull %60) #2
  %.pr13 = load ptr, ptr %58, align 8, !tbaa !18
  %63 = icmp eq ptr %.pr13, null
  br i1 %63, label %65, label %.thread17

.thread17:                                        ; preds = %57, %62
  %64 = phi ptr [ %.pr13, %62 ], [ %59, %57 ]
  tail call void @_ZdaPv(ptr noundef nonnull %64) #2
  br label %65

65:                                               ; preds = %.thread17, %62
  store ptr null, ptr %58, align 8, !tbaa !18
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %65, %1
  ret void
}

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 = { nobuiltin 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 = { builtin 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 = !{!"_ZTS12ImageContent", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !10, i64 56}
!15 = !{!10, !10, i64 0}
!16 = !{!8, !8, i64 0}
!17 = !{!6, !10, i64 64}
!18 = !{!6, !10, i64 72}
!19 = !{!6, !10, i64 48}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass