; LLVM IR from seppo0010/rlite :: src (hirlite)

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

; 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 void @rliteFreeReplyObject(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 1, ptr %5, align 4
  br label %62

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.rliteReply, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  switch i32 %13, label %60 [
    i32 3, label %60
    i32 2, label %14
    i32 6, label %50
    i32 5, label %50
    i32 1, label %50
  ]

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rliteReply, ptr %15, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %49

19:                                               ; preds = %14
  store i64 0, ptr %4, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %42, %19
  %21 = load i64, ptr %4, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rliteReply, ptr %22, i32 0, i32 4
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %25 = icmp ult i64 %21, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rliteReply, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load i64, ptr %4, align 8, !tbaa !15
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %41

34:                                               ; preds = %26
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rliteReply, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load i64, ptr %4, align 8, !tbaa !15
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  call void @rliteFreeReplyObject(ptr noundef %40)
  br label %41

41:                                               ; preds = %34, %26
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %4, align 8, !tbaa !15
  %44 = add i64 %43, 1
  store i64 %44, ptr %4, align 8, !tbaa !15
  br label %20, !llvm.loop !17

45:                                               ; preds = %20
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.rliteReply, ptr %46, i32 0, i32 5
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  call void @free(ptr noundef %48) #3
  br label %49

49:                                               ; preds = %45, %14
  br label %60

50:                                               ; preds = %10, %10, %10
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.rliteReply, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %59

55:                                               ; preds = %50
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rliteReply, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  call void @free(ptr noundef %58) #3
  br label %59

59:                                               ; preds = %55, %50
  br label %60

60:                                               ; preds = %59, %49, %10, %10
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %61) #3
  store i32 0, ptr %5, align 4
  br label %62

62:                                               ; preds = %60, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %63 = load i32, ptr %5, align 4
  switch i32 %63, label %65 [
    i32 0, label %64
    i32 1, label %64
  ]

64:                                               ; preds = %62, %62
  ret void

65:                                               ; preds = %62
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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, !11, i64 0}
!10 = !{!"rliteReply", !11, i64 0, !12, i64 8, !11, i64 16, !6, i64 24, !13, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !6, i64 40}
!15 = !{!13, !13, i64 0}
!16 = !{!10, !13, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !6, i64 24}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @rliteFreeReplyObject(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %25, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %4, label %24 [
    i32 1, label %20
    i32 2, label %5
    i32 6, label %20
    i32 5, label %20
  ]

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %24, label %.preheader

.preheader:                                       ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %.not20 = icmp eq i64 %9, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %15
  %10 = phi i64 [ %16, %15 ], [ %9, %.preheader ]
  %.019 = phi i64 [ %17, %15 ], [ 0, %.preheader ]
  %11 = load ptr, ptr %6, align 8, !tbaa !13
  %12 = getelementptr inbounds ptr, ptr %11, i64 %.019
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %.not17 = icmp eq ptr %13, null
  br i1 %.not17, label %15, label %14

14:                                               ; preds = %.lr.ph
  tail call void @rliteFreeReplyObject(ptr noundef nonnull %13)
  %.pre = load i64, ptr %8, align 8, !tbaa !14
  br label %15

15:                                               ; preds = %.lr.ph, %14
  %16 = phi i64 [ %10, %.lr.ph ], [ %.pre, %14 ]
  %17 = add nuw i64 %.019, 1
  %18 = icmp ult i64 %17, %16
  br i1 %18, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %15
  %.pre21 = load ptr, ptr %6, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %19 = phi ptr [ %.pre21, %._crit_edge.loopexit ], [ %7, %.preheader ]
  tail call void @free(ptr noundef %19) #2
  br label %24

20:                                               ; preds = %3, %3, %3
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %.not18 = icmp eq ptr %22, null
  br i1 %.not18, label %24, label %23

23:                                               ; preds = %20
  tail call void @free(ptr noundef nonnull %22) #2
  br label %24

24:                                               ; preds = %20, %23, %5, %._crit_edge, %3
  tail call void @free(ptr noundef nonnull %0) #2
  br label %25

25:                                               ; preds = %1, %24
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !7, i64 0}
!6 = !{!"rliteReply", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !12, i64 32, !11, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !11, i64 40}
!14 = !{!6, !12, i64 32}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !11, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass