; LLVM IR from Aeternum-Veritas/Merry :: merry (merry_nreader)

; 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.MerryReader = type { i8, i8, i8, i8, %struct.MerryInstSection, %struct.MerryEAT, %struct.MerrySsT, %struct.MerryST, ptr, [2 x i64], i64, i64, ptr, i64, ptr, i64, ptr, ptr, ptr, ptr, i64, i64 }
%struct.MerryInstSection = type { i64, ptr, i64, i64 }
%struct.MerryEAT = type { ptr, i64, i64 }
%struct.MerrySsT = type { i64, i64, ptr, i8 }
%struct.MerryST = type { ptr, i64 }
%struct.MerrySymbol = type { i64, i64 }

; 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
define dso_local ptr @merry_reader_get_symbol(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.MerryReader, ptr %8, i32 0, i32 1
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %20, label %13

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MerryReader, ptr %14, i32 0, i32 6
  %16 = getelementptr inbounds %struct.MerrySsT, ptr %15, i32 0, i32 3
  %17 = load i8, ptr %16, align 8, !tbaa !17
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %13, %2
  store ptr null, ptr %3, align 8
  br label %59

21:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %53, %21
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MerryReader, ptr %24, i32 0, i32 15
  %26 = load i64, ptr %25, align 8, !tbaa !18
  %27 = icmp ult i64 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  br label %56

29:                                               ; preds = %22
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MerryReader, ptr %30, i32 0, i32 14
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.MerrySymbol, ptr %32, i64 %33
  %35 = getelementptr inbounds %struct.MerrySymbol, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %35, align 8, !tbaa !20
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = icmp eq i64 %36, %37
  br i1 %38, label %39, label %52

39:                                               ; preds = %29
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MerryReader, ptr %40, i32 0, i32 7
  %42 = getelementptr inbounds %struct.MerryST, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MerryReader, ptr %44, i32 0, i32 14
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.MerrySymbol, ptr %46, i64 %47
  %49 = getelementptr inbounds %struct.MerrySymbol, ptr %48, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !23
  %51 = getelementptr inbounds i8, ptr %43, i64 %50
  store ptr %51, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

52:                                               ; preds = %29
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %6, align 8, !tbaa !9
  br label %22, !llvm.loop !24

56:                                               ; preds = %39, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %61 [
    i32 2, label %58
    i32 1, label %59
  ]

58:                                               ; preds = %56
  store ptr null, ptr %3, align 8
  br label %59

59:                                               ; preds = %58, %56, %20
  %60 = load ptr, ptr %3, align 8
  ret ptr %60

61:                                               ; preds = %56
  unreachable
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 1}
!12 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !13, i64 8, !14, i64 40, !15, i64 64, !16, i64 96, !6, i64 112, !7, i64 120, !10, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !10, i64 224}
!13 = !{!"MerryInstSection", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!"MerryEAT", !6, i64 0, !10, i64 8, !10, i64 16}
!15 = !{!"MerrySsT", !10, i64 0, !10, i64 8, !6, i64 16, !7, i64 24}
!16 = !{!"MerryST", !6, i64 0, !10, i64 8}
!17 = !{!12, !7, i64 88}
!18 = !{!12, !10, i64 176}
!19 = !{!12, !6, i64 168}
!20 = !{!21, !10, i64 0}
!21 = !{!"MerrySymbol", !10, i64 0, !10, i64 8}
!22 = !{!12, !6, i64 96}
!23 = !{!21, !10, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"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"

%struct.MerrySymbol = type { i64, i64 }

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @merry_reader_get_symbol(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 1
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 88
  %8 = load i8, ptr %7, align 8, !tbaa !15
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 176
  %11 = load i64, ptr %10, align 8, !tbaa !16
  %.not14.not = icmp eq i64 %11, 0
  br i1 %.not14.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 168
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  br label %16

14:                                               ; preds = %16
  %15 = add nuw i64 %.01215, 1
  %exitcond.not = icmp eq i64 %15, %11
  br i1 %exitcond.not, label %.loopexit, label %16, !llvm.loop !18

16:                                               ; preds = %.lr.ph, %14
  %.01215 = phi i64 [ 0, %.lr.ph ], [ %15, %14 ]
  %17 = getelementptr inbounds %struct.MerrySymbol, ptr %13, i64 %.01215
  %18 = load i64, ptr %17, align 8, !tbaa !20
  %19 = icmp eq i64 %18, %1
  br i1 %19, label %20, label %14

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %17, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !23
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  br label %.loopexit

.loopexit:                                        ; preds = %14, %.preheader, %20, %2, %6
  %.1 = phi ptr [ null, %6 ], [ null, %2 ], [ %25, %20 ], [ null, %.preheader ], [ null, %14 ]
  ret ptr %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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, !7, i64 1}
!6 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 8, !12, i64 40, !13, i64 64, !14, i64 96, !11, i64 112, !7, i64 120, !10, i64 136, !10, i64 144, !11, i64 152, !10, i64 160, !11, i64 168, !10, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !10, i64 216, !10, i64 224}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"MerryInstSection", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24}
!10 = !{!"long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"MerryEAT", !11, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!"MerrySsT", !10, i64 0, !10, i64 8, !11, i64 16, !7, i64 24}
!14 = !{!"MerryST", !11, i64 0, !10, i64 8}
!15 = !{!6, !7, i64 88}
!16 = !{!6, !10, i64 176}
!17 = !{!6, !11, i64 168}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !10, i64 0}
!21 = !{!"MerrySymbol", !10, i64 0, !10, i64 8}
!22 = !{!6, !11, i64 96}
!23 = !{!21, !10, i64 8}


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