; 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.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 }
%struct.rl_page = type { i64, ptr, ptr }
%struct.rl_data_type = type { 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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_dirty_hash(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.SHA1_CTX, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 92, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store ptr null, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.rlite, ptr %10, i32 0, i32 17
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %15, align 8, !tbaa !5
  br label %78

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rlite, ptr %17, i32 0, i32 6
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = mul i64 %19, 1
  %21 = call noalias ptr @malloc(i64 noundef %20) #7
  store ptr %21, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  store i32 4, ptr %6, align 4, !tbaa !9
  br label %78

25:                                               ; preds = %16
  %26 = call noalias ptr @malloc(i64 noundef 20) #7
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %26, ptr %27, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  store i32 4, ptr %6, align 4, !tbaa !9
  br label %78

32:                                               ; preds = %25
  call void @SHA1Init(ptr noundef %8)
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %72, %32
  %34 = load i64, ptr %5, align 8, !tbaa !15
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rlite, ptr %35, i32 0, i32 17
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = icmp slt i64 %34, %37
  br i1 %38, label %39, label %75

39:                                               ; preds = %33
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rlite, ptr %40, i32 0, i32 18
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = load i64, ptr %5, align 8, !tbaa !15
  %44 = getelementptr inbounds ptr, ptr %42, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rlite, ptr %47, i32 0, i32 6
  %49 = load i64, ptr %48, align 8, !tbaa !14
  call void @llvm.memset.p0.i64(ptr align 1 %46, i8 0, i64 %49, i1 false)
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rl_page, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %66

54:                                               ; preds = %39
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.rl_page, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %struct.rl_data_type, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.rl_page, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !21
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = call i32 %59(ptr noundef %60, ptr noundef %63, ptr noundef %64)
  store i32 %65, ptr %6, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %54, %39
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rlite, ptr %68, i32 0, i32 6
  %70 = load i64, ptr %69, align 8, !tbaa !14
  %71 = trunc i64 %70 to i32
  call void @SHA1Update(ptr noundef %8, ptr noundef %67, i32 noundef %71)
  br label %72

72:                                               ; preds = %66
  %73 = load i64, ptr %5, align 8, !tbaa !15
  %74 = add nsw i64 %73, 1
  store i64 %74, ptr %5, align 8, !tbaa !15
  br label %33, !llvm.loop !22

75:                                               ; preds = %33
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  call void @SHA1Final(ptr noundef %77, ptr noundef %8)
  br label %78

78:                                               ; preds = %75, %31, %24, %14
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %79) #6
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %86

82:                                               ; preds = %78
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  call void @free(ptr noundef %84) #6
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %85, align 8, !tbaa !5
  br label %86

86:                                               ; preds = %82, %78
  %87 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 92, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret i32 %87
}

declare void @SHA1Init(ptr noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

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

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 allocsize(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 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 = { "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 48}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !6, i64 128}
!17 = !{!18, !6, i64 8}
!18 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!20, !6, i64 8}
!20 = !{!"rl_data_type", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!18, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"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.SHA1_CTX = type { [5 x i32], [2 x i32], [64 x i8] }

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

; 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 #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_dirty_hash(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.SHA1_CTX, align 4
  call void @llvm.lifetime.start.p0(i64 92, ptr nonnull %3) #6
  %4 = getelementptr inbounds i8, ptr %0, i64 120
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %.sink.split, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #7
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %.thread, label %11

11:                                               ; preds = %7
  %12 = tail call noalias dereferenceable_or_null(20) ptr @malloc(i64 noundef 20) #7
  store ptr %12, ptr %1, align 8, !tbaa !13
  %.not30 = icmp eq ptr %12, null
  br i1 %.not30, label %.thread, label %13

13:                                               ; preds = %11
  call void @SHA1Init(ptr noundef nonnull %3) #6
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp sgt i64 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 128
  br label %17

17:                                               ; preds = %.lr.ph, %30
  %.02543 = phi i64 [ 0, %.lr.ph ], [ %33, %30 ]
  %.02642 = phi i32 [ 0, %.lr.ph ], [ %.1, %30 ]
  %18 = load ptr, ptr %16, align 8, !tbaa !14
  %19 = getelementptr inbounds ptr, ptr %18, i64 %.02543
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i64, ptr %8, align 8, !tbaa !12
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %10, i8 0, i64 %21, i1 false)
  %22 = getelementptr inbounds i8, ptr %20, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %.not31 = icmp eq ptr %23, null
  br i1 %.not31, label %30, label %24

24:                                               ; preds = %17
  %25 = getelementptr inbounds i8, ptr %23, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %20, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  %29 = call i32 %26(ptr noundef nonnull %0, ptr noundef %28, ptr noundef nonnull %10) #6
  %.pre = load i64, ptr %8, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %24, %17
  %31 = phi i64 [ %.pre, %24 ], [ %21, %17 ]
  %.1 = phi i32 [ %29, %24 ], [ %.02642, %17 ]
  %32 = trunc i64 %31 to i32
  call void @SHA1Update(ptr noundef nonnull %3, ptr noundef nonnull %10, i32 noundef %32) #6
  %33 = add nuw nsw i64 %.02543, 1
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %17, label %._crit_edge, !llvm.loop !20

.thread:                                          ; preds = %7, %11
  tail call void @free(ptr noundef %10) #6
  br label %37

._crit_edge:                                      ; preds = %30, %13
  %.026.lcssa = phi i32 [ 0, %13 ], [ %.1, %30 ]
  %36 = load ptr, ptr %1, align 8, !tbaa !13
  call void @SHA1Final(ptr noundef %36, ptr noundef nonnull %3) #6
  call void @free(ptr noundef %10) #6
  %.not32 = icmp eq i32 %.026.lcssa, 0
  br i1 %.not32, label %39, label %37

37:                                               ; preds = %.thread, %._crit_edge
  %.236 = phi i32 [ 4, %.thread ], [ %.026.lcssa, %._crit_edge ]
  %38 = load ptr, ptr %1, align 8, !tbaa !13
  call void @free(ptr noundef %38) #6
  br label %.sink.split

.sink.split:                                      ; preds = %2, %37
  %.237.ph = phi i32 [ %.236, %37 ], [ 0, %2 ]
  store ptr null, ptr %1, align 8, !tbaa !13
  br label %39

39:                                               ; preds = %.sink.split, %._crit_edge
  %.237 = phi i32 [ 0, %._crit_edge ], [ %.237.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 92, ptr nonnull %3) #6
  ret i32 %.237
}

declare void @SHA1Init(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { "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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 48}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !11, i64 128}
!15 = !{!16, !11, i64 8}
!16 = !{!"", !7, i64 0, !11, i64 8, !11, i64 16}
!17 = !{!18, !11, i64 8}
!18 = !{!"rl_data_type", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!19 = !{!16, !11, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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