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

; 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.rl_data_type = type { ptr, ptr, ptr, ptr }
%struct.rl_list_type = type { ptr, ptr, i32, ptr }
%struct.SHA1_CTX = type { [5 x i32], [2 x i32], [64 x i8] }
%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 }

@rl_data_type_list_long = external global %struct.rl_data_type, align 8
@rl_list_type_long = external global %struct.rl_list_type, align 8

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

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @rl_string_get(ptr noundef, ptr noundef, i64 noundef) #1

declare i32 @rl_list_destroy(ptr noundef, 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
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_multi_string_sha1(ptr noundef %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.SHA1_CTX, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 92, ptr %9) #4
  call void @SHA1Init(ptr noundef %9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = call i32 @rl_read(ptr noundef %15, ptr noundef @rl_data_type_list_long, i64 noundef %16, ptr noundef @rl_list_type_long, ptr noundef %10, i32 noundef 0)
  store i32 %17, ptr %13, align 4, !tbaa !11
  %18 = load i32, ptr %13, align 4, !tbaa !11
  %19 = icmp ne i32 2, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  br label %83

21:                                               ; preds = %3
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %22, ptr %11, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = call i32 @rl_list_iterator_create(ptr noundef %23, ptr noundef %12, ptr noundef %24, i32 noundef 1)
  store i32 %25, ptr %13, align 4, !tbaa !11
  %26 = load i32, ptr %13, align 4, !tbaa !11
  %27 = icmp ne i32 0, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  br label %83

29:                                               ; preds = %21
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %61, %37, %29
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = call i32 @rl_list_iterator_next(ptr noundef %31, ptr noundef %10)
  store i32 %32, ptr %13, align 4, !tbaa !11
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %70

34:                                               ; preds = %30
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = icmp eq i64 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %34
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i64, ptr %38, align 8, !tbaa !9
  store i64 %39, ptr %14, align 8, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %40) #4
  br label %30, !llvm.loop !13

41:                                               ; preds = %34
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load i64, ptr %43, align 8, !tbaa !9
  %45 = call i32 @rl_string_get(ptr noundef %42, ptr noundef %7, i64 noundef %44)
  store i32 %45, ptr %13, align 4, !tbaa !11
  %46 = load i32, ptr %13, align 4, !tbaa !11
  %47 = icmp ne i32 0, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %41
  br label %83

49:                                               ; preds = %41
  %50 = load i64, ptr %14, align 8, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.rlite, ptr %51, i32 0, i32 6
  %53 = load i64, ptr %52, align 8, !tbaa !15
  %54 = icmp sgt i64 %50, %53
  br i1 %54, label %55, label %59

55:                                               ; preds = %49
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rlite, ptr %56, i32 0, i32 6
  %58 = load i64, ptr %57, align 8, !tbaa !15
  br label %61

59:                                               ; preds = %49
  %60 = load i64, ptr %14, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %59, %55
  %62 = phi i64 [ %58, %55 ], [ %60, %59 ]
  store i64 %62, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = trunc i64 %64 to i32
  call void @SHA1Update(ptr noundef %9, ptr noundef %63, i32 noundef %65)
  %66 = load i64, ptr %8, align 8, !tbaa !9
  %67 = load i64, ptr %14, align 8, !tbaa !9
  %68 = sub nsw i64 %67, %66
  store i64 %68, ptr %14, align 8, !tbaa !9
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %69) #4
  br label %30, !llvm.loop !13

70:                                               ; preds = %30
  store ptr null, ptr %12, align 8, !tbaa !5
  %71 = load i32, ptr %13, align 4, !tbaa !11
  %72 = icmp ne i32 %71, 9
  br i1 %72, label %73, label %74

73:                                               ; preds = %70
  br label %83

74:                                               ; preds = %70
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = call i32 @rl_list_destroy(ptr noundef %75, ptr noundef %76)
  store i32 %77, ptr %13, align 4, !tbaa !11
  %78 = load i32, ptr %13, align 4, !tbaa !11
  %79 = icmp ne i32 0, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %74
  br label %83

81:                                               ; preds = %74
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  call void @SHA1Final(ptr noundef %82, ptr noundef %9)
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %83

83:                                               ; preds = %81, %80, %73, %48, %28, %20
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %90

86:                                               ; preds = %83
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = call i32 @rl_list_iterator_destroy(ptr noundef %87, ptr noundef %88)
  br label %90

90:                                               ; preds = %86, %83
  %91 = load i32, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 92, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %91
}

declare void @SHA1Init(ptr noundef) #1

declare i32 @rl_list_iterator_create(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @rl_list_iterator_next(ptr noundef, ptr noundef) #1

declare void @SHA1Update(ptr noundef, ptr noundef, i32 noundef) #1

declare void @SHA1Final(ptr noundef, ptr noundef) #1

declare i32 @rl_list_iterator_destroy(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 48}
!16 = !{!"rlite", !10, i64 0, !10, i64 8, !12, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}


; 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.rl_data_type = type { ptr, ptr, ptr, ptr }
%struct.rl_list_type = type { ptr, ptr, i32, ptr }
%struct.SHA1_CTX = type { [5 x i32], [2 x i32], [64 x i8] }

@rl_data_type_list_long = external global %struct.rl_data_type, align 8
@rl_list_type_long = external global %struct.rl_list_type, align 8

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

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @rl_string_get(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @rl_list_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_multi_string_sha1(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = alloca %struct.SHA1_CTX, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 92, ptr nonnull %5) #5
  call void @SHA1Init(ptr noundef nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  store ptr null, ptr %7, align 8, !tbaa !5
  %8 = call i32 @rl_read(ptr noundef %0, ptr noundef nonnull @rl_data_type_list_long, i64 noundef %2, ptr noundef nonnull @rl_list_type_long, ptr noundef nonnull %6, i32 noundef 0) #5
  %.not = icmp eq i32 %8, 2
  br i1 %.not, label %9, label %.loopexit

9:                                                ; preds = %3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = call i32 @rl_list_iterator_create(ptr noundef %0, ptr noundef nonnull %7, ptr noundef %10, i32 noundef 1) #5
  %.not30 = icmp eq i32 %11, 0
  br i1 %.not30, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %9
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = call i32 @rl_list_iterator_next(ptr noundef %12, ptr noundef nonnull %6) #5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  br label %16

16:                                               ; preds = %.lr.ph, %.backedge
  %.040 = phi i64 [ 0, %.lr.ph ], [ %.0.be, %.backedge ]
  %17 = icmp eq i64 %.040, 0
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !9
  br i1 %17, label %.backedge, label %23

.backedge:                                        ; preds = %16, %25
  %.sink = phi ptr [ %30, %25 ], [ %18, %16 ]
  %.0.be = phi i64 [ %29, %25 ], [ %19, %16 ]
  call void @free(ptr noundef %.sink) #5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call i32 @rl_list_iterator_next(ptr noundef %20, ptr noundef nonnull %6) #5
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %16, label %._crit_edge, !llvm.loop !11

23:                                               ; preds = %16
  %24 = call i32 @rl_string_get(ptr noundef %0, ptr noundef nonnull %4, i64 noundef %19) #5
  %.not33 = icmp eq i32 %24, 0
  br i1 %.not33, label %25, label %.loopexit

25:                                               ; preds = %23
  %26 = load i64, ptr %15, align 8, !tbaa !13
  %..0 = call i64 @llvm.smin.i64(i64 %.040, i64 %26)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = trunc i64 %..0 to i32
  call void @SHA1Update(ptr noundef nonnull %5, ptr noundef %27, i32 noundef %28) #5
  %29 = sub nsw i64 %.040, %..0
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge, %.preheader
  %.lcssa = phi i32 [ %13, %.preheader ], [ %21, %.backedge ]
  store ptr null, ptr %7, align 8, !tbaa !5
  %.not31 = icmp eq i32 %.lcssa, 9
  br i1 %.not31, label %31, label %.thread

31:                                               ; preds = %._crit_edge
  %32 = call i32 @rl_list_destroy(ptr noundef %0, ptr noundef %10) #5
  %.not32 = icmp eq i32 %32, 0
  br i1 %.not32, label %33, label %.loopexit

33:                                               ; preds = %31
  call void @SHA1Final(ptr noundef %1, ptr noundef nonnull %5) #5
  br label %.loopexit

.loopexit:                                        ; preds = %23, %31, %9, %3, %33
  %.022.ph = phi i32 [ 0, %33 ], [ %32, %31 ], [ %11, %9 ], [ %8, %3 ], [ %24, %23 ]
  %.pr = load ptr, ptr %7, align 8, !tbaa !5
  %.not34 = icmp eq ptr %.pr, null
  br i1 %.not34, label %.thread, label %34

34:                                               ; preds = %.loopexit
  %35 = call i32 @rl_list_iterator_destroy(ptr noundef %0, ptr noundef nonnull %.pr) #5
  br label %.thread

.thread:                                          ; preds = %._crit_edge, %34, %.loopexit
  %.02237 = phi i32 [ %.022.ph, %34 ], [ %.022.ph, %.loopexit ], [ %.lcssa, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 92, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.02237
}

declare void @SHA1Init(ptr noundef) local_unnamed_addr #1

declare i32 @rl_list_iterator_create(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @rl_list_iterator_next(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @SHA1Update(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @SHA1Final(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @rl_list_iterator_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 48}
!14 = !{!"rlite", !10, i64 0, !10, i64 8, !15, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !15, i64 64, !15, i64 68, !15, i64 72, !15, i64 76, !6, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!15 = !{!"int", !7, i64 0}


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