; LLVM IR from DANTE2076/SmartLoopAIproject :: src/dashbls/depends/relic/src/md (sha224-256)

; 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.SHA256Context = type { [8 x i32], i32, i32, i16, [64 x i8], i32, i32 }

@__const.SHA256FinalBits.masks = external hidden unnamed_addr constant [8 x i8], align 1
@__const.SHA256FinalBits.markbit = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @SHA256FinalBits(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca [8 x i8], align 1
  %9 = alloca [8 x i8], align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 @__const.SHA256FinalBits.masks, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 @__const.SHA256FinalBits.markbit, i64 8, i1 false)
  %12 = load i32, ptr %7, align 4, !tbaa !10
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SHA256Context, ptr %20, i32 0, i32 5
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %30, label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %7, align 4, !tbaa !10
  %26 = icmp uge i32 %25, 8
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %7, align 4, !tbaa !10
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %27, %24, %19
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SHA256Context, ptr %31, i32 0, i32 6
  store i32 3, ptr %32, align 4, !tbaa !15
  store i32 3, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SHA256Context, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SHA256Context, ptr %39, i32 0, i32 6
  %41 = load i32, ptr %40, align 4, !tbaa !15
  store i32 %41, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

42:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SHA256Context, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !16
  store i32 %45, ptr %11, align 4, !tbaa !10
  %46 = load i32, ptr %7, align 4, !tbaa !10
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SHA256Context, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = add i32 %49, %46
  store i32 %50, ptr %48, align 4, !tbaa !16
  %51 = load i32, ptr %11, align 4, !tbaa !10
  %52 = icmp ult i32 %50, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %42
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SHA256Context, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !17
  %57 = add i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !17
  %58 = icmp eq i32 %57, 0
  br label %59

59:                                               ; preds = %53, %42
  %60 = phi i1 [ false, %42 ], [ %58, %53 ]
  %61 = zext i1 %60 to i64
  %62 = select i1 %60, i32 1, i32 0
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.SHA256Context, ptr %63, i32 0, i32 6
  store i32 %62, ptr %64, align 4, !tbaa !15
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load i8, ptr %6, align 1, !tbaa !9
  %67 = zext i8 %66 to i32
  %68 = load i32, ptr %7, align 4, !tbaa !10
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds [8 x i8], ptr %8, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !9
  %72 = zext i8 %71 to i32
  %73 = and i32 %67, %72
  %74 = load i32, ptr %7, align 4, !tbaa !10
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [8 x i8], ptr %9, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !9
  %78 = zext i8 %77 to i32
  %79 = or i32 %73, %78
  %80 = trunc i32 %79 to i8
  call void @SHA224_256Finalize(ptr noundef %65, i8 noundef zeroext %80)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %81

81:                                               ; preds = %59, %38, %30, %18, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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

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

; 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
declare hidden void @SHA224_256Finalize(ptr noundef, i8 noundef zeroext) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 108}
!13 = !{!"SHA256Context", !7, i64 0, !11, i64 32, !11, i64 36, !14, i64 40, !7, i64 42, !11, i64 108, !11, i64 112}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !11, i64 112}
!16 = !{!13, !11, i64 32}
!17 = !{!13, !11, i64 36}


; 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"

@__const.SHA256FinalBits.masks = external hidden unnamed_addr constant [8 x i8], align 1
@__const.SHA256FinalBits.markbit = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @SHA256FinalBits(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %34, label %4

4:                                                ; preds = %3
  %.not24 = icmp eq ptr %0, null
  br i1 %.not24, label %34, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 108
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  %9 = icmp ugt i32 %2, 7
  %or.cond = or i1 %9, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 112
  br i1 %or.cond, label %11, label %12

11:                                               ; preds = %5
  store i32 3, ptr %10, align 4, !tbaa !11
  br label %34

12:                                               ; preds = %5
  %13 = load i32, ptr %10, align 4, !tbaa !11
  %.not25 = icmp eq i32 %13, 0
  br i1 %.not25, label %14, label %34

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = add i32 %16, %2
  store i32 %17, ptr %15, align 4, !tbaa !12
  %18 = icmp ult i32 %17, %16
  br i1 %18, label %19, label %25

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %0, i64 36
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = add i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !13
  %23 = icmp eq i32 %22, 0
  %24 = zext i1 %23 to i32
  br label %25

25:                                               ; preds = %19, %14
  %26 = phi i32 [ 0, %14 ], [ %24, %19 ]
  store i32 %26, ptr %10, align 4, !tbaa !11
  %27 = zext nneg i32 %2 to i64
  %28 = getelementptr inbounds [8 x i8], ptr @__const.SHA256FinalBits.masks, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !14
  %30 = and i8 %29, %1
  %31 = getelementptr inbounds [8 x i8], ptr @__const.SHA256FinalBits.markbit, i64 0, i64 %27
  %32 = load i8, ptr %31, align 1, !tbaa !14
  %33 = or i8 %30, %32
  tail call void @SHA224_256Finalize(ptr noundef nonnull %0, i8 noundef zeroext %33)
  br label %34

34:                                               ; preds = %12, %4, %3, %25, %11
  %.0 = phi i32 [ 3, %11 ], [ 0, %25 ], [ 0, %3 ], [ 1, %4 ], [ %13, %12 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @SHA224_256Finalize(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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" }

!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, !9, i64 108}
!6 = !{!"SHA256Context", !7, i64 0, !9, i64 32, !9, i64 36, !10, i64 40, !7, i64 42, !9, i64 108, !9, i64 112}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!6, !9, i64 112}
!12 = !{!6, !9, i64 32}
!13 = !{!6, !9, i64 36}
!14 = !{!7, !7, i64 0}


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