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

; 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.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, 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: nounwind uwtable
define dso_local i32 @rl_ensure_pages(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i32 @rl_has_flag(ptr noundef %5, i32 noundef 2)
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %38

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.rlite, ptr %9, i32 0, i32 17
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.rlite, ptr %12, i32 0, i32 16
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = icmp eq i64 %11, %14
  br i1 %15, label %16, label %37

16:                                               ; preds = %8
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rlite, ptr %17, i32 0, i32 18
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.rlite, ptr %20, i32 0, i32 16
  %22 = load i64, ptr %21, align 8, !tbaa !14
  %23 = mul i64 8, %22
  %24 = mul i64 %23, 2
  %25 = call ptr @realloc(ptr noundef %19, i64 noundef %24) #4
  store ptr %25, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %16
  store i32 4, ptr %3, align 4, !tbaa !9
  br label %68

29:                                               ; preds = %16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rlite, ptr %31, i32 0, i32 18
  store ptr %30, ptr %32, align 8, !tbaa !15
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rlite, ptr %33, i32 0, i32 16
  %35 = load i64, ptr %34, align 8, !tbaa !14
  %36 = mul nsw i64 %35, 2
  store i64 %36, ptr %34, align 8, !tbaa !14
  br label %37

37:                                               ; preds = %29, %8
  br label %38

38:                                               ; preds = %37, %1
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.rlite, ptr %39, i32 0, i32 14
  %41 = load i64, ptr %40, align 8, !tbaa !16
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rlite, ptr %42, i32 0, i32 13
  %44 = load i64, ptr %43, align 8, !tbaa !17
  %45 = icmp eq i64 %41, %44
  br i1 %45, label %46, label %67

46:                                               ; preds = %38
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rlite, ptr %47, i32 0, i32 15
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rlite, ptr %50, i32 0, i32 13
  %52 = load i64, ptr %51, align 8, !tbaa !17
  %53 = mul i64 8, %52
  %54 = mul i64 %53, 2
  %55 = call ptr @realloc(ptr noundef %49, i64 noundef %54) #4
  store ptr %55, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %59, label %58

58:                                               ; preds = %46
  store i32 4, ptr %3, align 4, !tbaa !9
  br label %68

59:                                               ; preds = %46
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.rlite, ptr %61, i32 0, i32 15
  store ptr %60, ptr %62, align 8, !tbaa !18
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.rlite, ptr %63, i32 0, i32 13
  %65 = load i64, ptr %64, align 8, !tbaa !17
  %66 = mul nsw i64 %65, 2
  store i64 %66, ptr %64, align 8, !tbaa !17
  br label %67

67:                                               ; preds = %59, %38
  br label %68

68:                                               ; preds = %67, %58, %28
  %69 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %69
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_has_flag(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

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 allocsize(1) "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 = { nounwind allocsize(1) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 120}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 112}
!15 = !{!12, !6, i64 128}
!16 = !{!12, !13, i64 96}
!17 = !{!12, !13, i64 88}
!18 = !{!12, !6, i64 104}


; 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: nounwind uwtable
define dso_local range(i32 0, 5) i32 @rl_ensure_pages(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @rl_has_flag(ptr noundef %0, i32 noundef 2)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %17, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 120
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 112
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = icmp eq i64 %5, %7
  br i1 %8, label %9, label %17

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = shl i64 %5, 4
  %13 = tail call ptr @realloc(ptr noundef %11, i64 noundef %12) #2
  %.not21 = icmp eq ptr %13, null
  br i1 %.not21, label %31, label %14

14:                                               ; preds = %9
  store ptr %13, ptr %10, align 8, !tbaa !13
  %15 = load i64, ptr %6, align 8, !tbaa !12
  %16 = shl nsw i64 %15, 1
  store i64 %16, ptr %6, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %3, %14, %1
  %18 = getelementptr inbounds i8, ptr %0, i64 96
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = icmp eq i64 %19, %21
  br i1 %22, label %23, label %31

23:                                               ; preds = %17
  %24 = getelementptr inbounds i8, ptr %0, i64 104
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = shl i64 %19, 4
  %27 = tail call ptr @realloc(ptr noundef %25, i64 noundef %26) #2
  %.not22 = icmp eq ptr %27, null
  br i1 %.not22, label %31, label %28

28:                                               ; preds = %23
  store ptr %27, ptr %24, align 8, !tbaa !16
  %29 = load i64, ptr %20, align 8, !tbaa !15
  %30 = shl nsw i64 %29, 1
  store i64 %30, ptr %20, align 8, !tbaa !15
  br label %31

31:                                               ; preds = %23, %9, %17, %28
  %.0 = phi i32 [ 0, %28 ], [ 0, %17 ], [ 4, %9 ], [ 4, %23 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_has_flag(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #2 = { nounwind allocsize(1) }

!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 120}
!6 = !{!"rlite", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 112}
!13 = !{!6, !11, i64 128}
!14 = !{!6, !7, i64 96}
!15 = !{!6, !7, i64 88}
!16 = !{!6, !11, i64 104}


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