; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (sha1)

; 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.ByteArray_st = type { ptr, i64 }
%struct.Sha1Ctx_st = type { [64 x i8], [5 x i32], i64, i64, [64 x i8] }

@.str = external hidden unnamed_addr constant [14 x i8], align 1

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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @sha1_update(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  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
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %11
  store i32 2, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 240, i32 noundef %15, ptr noundef null)
  br label %128

16:                                               ; preds = %11
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %24, label %22

22:                                               ; preds = %19
  store i32 2, ptr %10, align 4, !tbaa !9
  %23 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 241, i32 noundef %23, ptr noundef null)
  br label %128

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ByteArray_st, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  store ptr %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ByteArray_st, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !14
  store i64 %32, ptr %7, align 8, !tbaa !15
  %33 = load i64, ptr %7, align 8, !tbaa !15
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %34, i32 0, i32 3
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = add i64 %36, %33
  store i64 %37, ptr %35, align 8, !tbaa !16
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !18
  %41 = load i64, ptr %7, align 8, !tbaa !15
  %42 = add i64 %40, %41
  store i64 %42, ptr %9, align 8, !tbaa !15
  %43 = load i64, ptr %9, align 8, !tbaa !15
  %44 = icmp ult i64 %43, 64
  br i1 %44, label %45, label %59

45:                                               ; preds = %26
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !18
  %51 = getelementptr inbounds [64 x i8], ptr %47, i64 0, i64 %50
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %51, ptr align 1 %52, i64 %53, i1 false)
  %54 = load i64, ptr %7, align 8, !tbaa !15
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %55, i32 0, i32 2
  %57 = load i64, ptr %56, align 8, !tbaa !18
  %58 = add i64 %57, %54
  store i64 %58, ptr %56, align 8, !tbaa !18
  br label %128

59:                                               ; preds = %26
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %62, i32 0, i32 2
  %64 = load i64, ptr %63, align 8, !tbaa !18
  %65 = getelementptr inbounds [64 x i8], ptr %61, i64 0, i64 %64
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %68, align 8, !tbaa !18
  %70 = sub i64 64, %69
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %65, ptr align 1 %66, i64 %70, i1 false)
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds [5 x i32], ptr %72, i64 0, i64 0
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds [64 x i8], ptr %75, i64 0, i64 0
  call void @sha1_compress(ptr noundef %73, ptr noundef %76)
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [64 x i8], ptr %78, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %79, i8 0, i64 64, i1 false)
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %81, i32 0, i32 2
  %83 = load i64, ptr %82, align 8, !tbaa !18
  %84 = sub i64 64, %83
  %85 = getelementptr inbounds i8, ptr %80, i64 %84
  store ptr %85, ptr %6, align 8, !tbaa !5
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %86, i32 0, i32 2
  %88 = load i64, ptr %87, align 8, !tbaa !18
  %89 = sub i64 64, %88
  %90 = load i64, ptr %7, align 8, !tbaa !15
  %91 = sub i64 %90, %89
  store i64 %91, ptr %7, align 8, !tbaa !15
  store i64 0, ptr %8, align 8, !tbaa !15
  br label %92

92:                                               ; preds = %104, %59
  %93 = load i64, ptr %8, align 8, !tbaa !15
  %94 = add i64 %93, 64
  %95 = load i64, ptr %7, align 8, !tbaa !15
  %96 = icmp ule i64 %94, %95
  br i1 %96, label %97, label %107

97:                                               ; preds = %92
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %98, i32 0, i32 1
  %100 = getelementptr inbounds [5 x i32], ptr %99, i64 0, i64 0
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = load i64, ptr %8, align 8, !tbaa !15
  %103 = getelementptr inbounds i8, ptr %101, i64 %102
  call void @sha1_compress(ptr noundef %100, ptr noundef %103)
  br label %104

104:                                              ; preds = %97
  %105 = load i64, ptr %8, align 8, !tbaa !15
  %106 = add i64 %105, 64
  store i64 %106, ptr %8, align 8, !tbaa !15
  br label %92, !llvm.loop !19

107:                                              ; preds = %92
  %108 = load i64, ptr %7, align 8, !tbaa !15
  %109 = load i64, ptr %8, align 8, !tbaa !15
  %110 = sub i64 %108, %109
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %111, i32 0, i32 2
  store i64 %110, ptr %112, align 8, !tbaa !18
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %113, i32 0, i32 2
  %115 = load i64, ptr %114, align 8, !tbaa !18
  %116 = icmp ne i64 %115, 0
  br i1 %116, label %117, label %127

117:                                              ; preds = %107
  %118 = load ptr, ptr %3, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %118, i32 0, i32 0
  %120 = getelementptr inbounds [64 x i8], ptr %119, i64 0, i64 0
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  %122 = load i64, ptr %8, align 8, !tbaa !15
  %123 = getelementptr inbounds i8, ptr %121, i64 %122
  %124 = load ptr, ptr %3, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.Sha1Ctx_st, ptr %124, i32 0, i32 2
  %126 = load i64, ptr %125, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %120, ptr align 1 %123, i64 %126, i1 false)
  br label %127

127:                                              ; preds = %117, %107
  br label %128

128:                                              ; preds = %127, %45, %22, %14
  %129 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret i32 %129
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sha1_compress(ptr noundef, 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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !13, i64 96}
!17 = !{!"Sha1Ctx_st", !7, i64 0, !7, i64 64, !13, i64 88, !13, i64 96, !7, i64 104}
!18 = !{!17, !13, i64 88}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str = external hidden unnamed_addr constant [14 x i8], align 1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @sha1_update(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %2
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 240, i32 noundef 2, ptr noundef null) #5
  br label %34

4:                                                ; preds = %2
  %.not48 = icmp eq ptr %1, null
  br i1 %.not48, label %5, label %6

5:                                                ; preds = %4
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 241, i32 noundef 2, ptr noundef null) #5
  br label %34

6:                                                ; preds = %4
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 96
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = add i64 %11, %9
  store i64 %12, ptr %10, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 88
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = add i64 %14, %9
  %16 = icmp ult i64 %15, 64
  %17 = getelementptr inbounds [64 x i8], ptr %0, i64 0, i64 %14
  br i1 %16, label %18, label %21

18:                                               ; preds = %6
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %17, ptr align 1 %7, i64 %9, i1 false)
  %19 = load i64, ptr %13, align 8, !tbaa !14
  %20 = add i64 %19, %9
  store i64 %20, ptr %13, align 8, !tbaa !14
  br label %34

21:                                               ; preds = %6
  %22 = sub i64 64, %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %17, ptr align 1 %7, i64 %22, i1 false)
  %23 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @sha1_compress(ptr noundef nonnull %23, ptr noundef nonnull %0)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %0, i8 0, i64 64, i1 false)
  %24 = load i64, ptr %13, align 8, !tbaa !14
  %25 = sub i64 64, %24
  %26 = getelementptr inbounds i8, ptr %7, i64 %25
  %27 = sub i64 %9, %25
  %.not4951 = icmp ult i64 %27, 64
  br i1 %.not4951, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %21, %.lr.ph
  %28 = phi i64 [ %30, %.lr.ph ], [ 64, %21 ]
  %.04252 = phi i64 [ %28, %.lr.ph ], [ 0, %21 ]
  %29 = getelementptr inbounds i8, ptr %26, i64 %.04252
  tail call void @sha1_compress(ptr noundef nonnull %23, ptr noundef %29)
  %30 = add i64 %28, 64
  %.not49 = icmp ugt i64 %30, %27
  br i1 %.not49, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %21
  %.042.lcssa = phi i64 [ 0, %21 ], [ %28, %.lr.ph ]
  %31 = sub i64 %27, %.042.lcssa
  store i64 %31, ptr %13, align 8, !tbaa !14
  %.not50 = icmp eq i64 %27, %.042.lcssa
  br i1 %.not50, label %34, label %32

32:                                               ; preds = %._crit_edge
  %33 = getelementptr inbounds i8, ptr %26, i64 %.042.lcssa
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %0, ptr align 1 %33, i64 %31, i1 false)
  br label %34

34:                                               ; preds = %._crit_edge, %32, %18, %5, %3
  %.0 = phi i32 [ 0, %18 ], [ 0, %32 ], [ 0, %._crit_edge ], [ 2, %5 ], [ 2, %3 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sha1_compress(ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"ByteArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !10, i64 96}
!13 = !{!"Sha1Ctx_st", !8, i64 0, !8, i64 64, !10, i64 88, !10, i64 96, !8, i64 104}
!14 = !{!13, !10, i64 88}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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