; LLVM IR from LoupVaillant/Monocypher-Utils :: src (hash)

; 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.crypto_blake2b_ctx = type { [8 x i64], [2 x i64], [16 x i64], i64, i64 }
%struct.crypto_sha512_ctx = type { [80 x i64], [8 x i64], [16 x i64], [2 x i64], i64 }

@.str = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @hash_input(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca [64 x i8], align 16
  %16 = alloca [4096 x i8], align 16
  %17 = alloca %struct.crypto_blake2b_ctx, align 8
  %18 = alloca i64, align 8
  %19 = alloca %struct.crypto_sha512_ctx, align 8
  %20 = alloca i64, align 8
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !9
  store i64 %6, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 64, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4096, ptr %16) #4
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %51

23:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 224, ptr %17) #4
  %24 = load i64, ptr %12, align 8, !tbaa !11
  %25 = load ptr, ptr %13, align 8, !tbaa !9
  %26 = load i64, ptr %14, align 8, !tbaa !11
  call void @crypto_blake2b_general_init(ptr noundef %17, i64 noundef %24, ptr noundef %25, i64 noundef %26)
  br label %27

27:                                               ; preds = %38, %23
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  %29 = call i32 @feof(ptr noundef %28) #4
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %36, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = call i32 @ferror(ptr noundef %32) #4
  %34 = icmp ne i32 %33, 0
  %35 = xor i1 %34, true
  br label %36

36:                                               ; preds = %31, %27
  %37 = phi i1 [ false, %27 ], [ %35, %31 ]
  br i1 %37, label %38, label %44

38:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %39 = getelementptr inbounds [4096 x i8], ptr %16, i64 0, i64 0
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  %41 = call i64 @fread(ptr noundef %39, i64 noundef 1, i64 noundef 4096, ptr noundef %40)
  store i64 %41, ptr %18, align 8, !tbaa !11
  %42 = getelementptr inbounds [4096 x i8], ptr %16, i64 0, i64 0
  %43 = load i64, ptr %18, align 8, !tbaa !11
  call void @crypto_blake2b_update(ptr noundef %17, ptr noundef %42, i64 noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %27, !llvm.loop !13

44:                                               ; preds = %36
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = call i32 @ferror(ptr noundef %45) #4
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %44
  call void @panic(ptr noundef @.str)
  br label %49

49:                                               ; preds = %48, %44
  %50 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  call void @crypto_blake2b_final(ptr noundef %17, ptr noundef %50)
  call void @llvm.lifetime.end.p0(i64 224, ptr %17) #4
  br label %51

51:                                               ; preds = %49, %7
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %79

54:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 856, ptr %19) #4
  call void @crypto_sha512_init(ptr noundef %19)
  br label %55

55:                                               ; preds = %66, %54
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = call i32 @feof(ptr noundef %56) #4
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %64, label %59

59:                                               ; preds = %55
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  %61 = call i32 @ferror(ptr noundef %60) #4
  %62 = icmp ne i32 %61, 0
  %63 = xor i1 %62, true
  br label %64

64:                                               ; preds = %59, %55
  %65 = phi i1 [ false, %55 ], [ %63, %59 ]
  br i1 %65, label %66, label %72

66:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %67 = getelementptr inbounds [4096 x i8], ptr %16, i64 0, i64 0
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  %69 = call i64 @fread(ptr noundef %67, i64 noundef 1, i64 noundef 4096, ptr noundef %68)
  store i64 %69, ptr %20, align 8, !tbaa !11
  %70 = getelementptr inbounds [4096 x i8], ptr %16, i64 0, i64 0
  %71 = load i64, ptr %20, align 8, !tbaa !11
  call void @crypto_sha512_update(ptr noundef %19, ptr noundef %70, i64 noundef %71)
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %55, !llvm.loop !15

72:                                               ; preds = %64
  %73 = load ptr, ptr %10, align 8, !tbaa !9
  %74 = call i32 @ferror(ptr noundef %73) #4
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %72
  call void @panic(ptr noundef @.str)
  br label %77

77:                                               ; preds = %76, %72
  %78 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  call void @crypto_sha512_final(ptr noundef %19, ptr noundef %78)
  call void @llvm.lifetime.end.p0(i64 856, ptr %19) #4
  br label %79

79:                                               ; preds = %77, %51
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %87, label %82

82:                                               ; preds = %79
  %83 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  %84 = load i64, ptr %12, align 8, !tbaa !11
  call void @print_buffer(ptr noundef %83, i64 noundef %84)
  %85 = load ptr, ptr %11, align 8, !tbaa !9
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %85)
  br label %111

87:                                               ; preds = %79
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = icmp eq i32 %88, 0
  br i1 %89, label %90, label %92

90:                                               ; preds = %87
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %92

92:                                               ; preds = %90, %87
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = icmp eq i32 %93, 1
  br i1 %94, label %95, label %97

95:                                               ; preds = %92
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %97

97:                                               ; preds = %95, %92
  %98 = load i64, ptr %12, align 8, !tbaa !11
  %99 = icmp ne i64 %98, 64
  br i1 %99, label %100, label %105

100:                                              ; preds = %97
  %101 = load i64, ptr %12, align 8, !tbaa !11
  %102 = trunc i64 %101 to i32
  %103 = mul i32 %102, 8
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %103)
  br label %105

105:                                              ; preds = %100, %97
  %106 = load ptr, ptr %11, align 8, !tbaa !9
  %107 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %106)
  %108 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  %109 = load i64, ptr %12, align 8, !tbaa !11
  call void @print_buffer(ptr noundef %108, i64 noundef %109)
  %110 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %111

111:                                              ; preds = %105, %82
  call void @llvm.lifetime.end.p0(i64 4096, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %15) #4
  ret void
}

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

declare void @crypto_blake2b_general_init(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #3

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare void @crypto_blake2b_update(ptr noundef, ptr noundef, i64 noundef) #2

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

declare void @panic(ptr noundef) #2

declare void @crypto_blake2b_final(ptr noundef, ptr noundef) #2

declare void @crypto_sha512_init(ptr noundef) #2

declare void @crypto_sha512_update(ptr noundef, ptr noundef, i64 noundef) #2

declare void @crypto_sha512_final(ptr noundef, ptr noundef) #2

declare void @print_buffer(ptr noundef, i64 noundef) #2

declare i32 @printf(ptr noundef, ...) #2

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 = { "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 "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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.crypto_blake2b_ctx = type { [8 x i64], [2 x i64], [16 x i64], i64, i64 }
%struct.crypto_sha512_ctx = type { [80 x i64], [8 x i64], [16 x i64], [2 x i64], i64 }

@.str = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @hash_input(i32 noundef %0, i32 noundef %1, ptr nocapture noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #0 {
  %8 = alloca [64 x i8], align 16
  %9 = alloca [4096 x i8], align 16
  %10 = alloca %struct.crypto_blake2b_ctx, align 8
  %11 = alloca %struct.crypto_sha512_ctx, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %8) #5
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %9) #5
  %12 = icmp eq i32 %0, 0
  br i1 %12, label %13, label %22

13:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 224, ptr nonnull %10) #5
  call void @crypto_blake2b_general_init(ptr noundef nonnull %10, i64 noundef %4, ptr noundef %5, i64 noundef %6) #5
  %14 = call i32 @feof(ptr noundef %2) #5
  %.not32 = icmp eq i32 %14, 0
  br i1 %.not32, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %13, %16
  %15 = call i32 @ferror(ptr noundef %2) #5
  %.not25 = icmp eq i32 %15, 0
  br i1 %.not25, label %16, label %.critedge

16:                                               ; preds = %.lr.ph
  %17 = call i64 @fread(ptr noundef nonnull %9, i64 noundef 1, i64 noundef 4096, ptr noundef %2)
  call void @crypto_blake2b_update(ptr noundef nonnull %10, ptr noundef nonnull %9, i64 noundef %17) #5
  %18 = call i32 @feof(ptr noundef %2) #5
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %16, %13
  %19 = call i32 @ferror(ptr noundef %2) #5
  %.not26 = icmp eq i32 %19, 0
  br i1 %.not26, label %21, label %20

20:                                               ; preds = %.critedge
  call void @panic(ptr noundef nonnull @.str) #5
  br label %21

21:                                               ; preds = %20, %.critedge
  call void @crypto_blake2b_final(ptr noundef nonnull %10, ptr noundef nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 224, ptr nonnull %10) #5
  br label %22

22:                                               ; preds = %21, %7
  %23 = icmp eq i32 %0, 1
  br i1 %23, label %24, label %33

24:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 856, ptr nonnull %11) #5
  call void @crypto_sha512_init(ptr noundef nonnull %11) #5
  %25 = call i32 @feof(ptr noundef %2) #5
  %.not2734 = icmp eq i32 %25, 0
  br i1 %.not2734, label %.lr.ph35, label %.critedge2

.lr.ph35:                                         ; preds = %24, %27
  %26 = call i32 @ferror(ptr noundef %2) #5
  %.not28 = icmp eq i32 %26, 0
  br i1 %.not28, label %27, label %.critedge2

27:                                               ; preds = %.lr.ph35
  %28 = call i64 @fread(ptr noundef nonnull %9, i64 noundef 1, i64 noundef 4096, ptr noundef %2)
  call void @crypto_sha512_update(ptr noundef nonnull %11, ptr noundef nonnull %9, i64 noundef %28) #5
  %29 = call i32 @feof(ptr noundef %2) #5
  %.not27 = icmp eq i32 %29, 0
  br i1 %.not27, label %.lr.ph35, label %.critedge2, !llvm.loop !7

.critedge2:                                       ; preds = %.lr.ph35, %27, %24
  %30 = call i32 @ferror(ptr noundef %2) #5
  %.not29 = icmp eq i32 %30, 0
  br i1 %.not29, label %32, label %31

31:                                               ; preds = %.critedge2
  call void @panic(ptr noundef nonnull @.str) #5
  br label %32

32:                                               ; preds = %31, %.critedge2
  call void @crypto_sha512_final(ptr noundef nonnull %11, ptr noundef nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 856, ptr nonnull %11) #5
  br label %33

33:                                               ; preds = %32, %22
  %.not30 = icmp eq i32 %1, 0
  br i1 %.not30, label %34, label %36

34:                                               ; preds = %33
  call void @print_buffer(ptr noundef nonnull %8, i64 noundef %4) #5
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %3)
  br label %46

36:                                               ; preds = %33
  %switch = icmp ult i32 %0, 2
  br i1 %switch, label %.sink.split, label %38

.sink.split:                                      ; preds = %36
  %.str.2.mux = select i1 %12, ptr @.str.2, ptr @.str.3
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.mux)
  br label %38

38:                                               ; preds = %36, %.sink.split
  %.not31 = icmp eq i64 %4, 64
  br i1 %.not31, label %43, label %39

39:                                               ; preds = %38
  %40 = trunc i64 %4 to i32
  %41 = shl i32 %40, 3
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %41)
  br label %43

43:                                               ; preds = %39, %38
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef %3)
  call void @print_buffer(ptr noundef nonnull %8, i64 noundef %4) #5
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %46

46:                                               ; preds = %43, %34
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %8) #5
  ret void
}

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

declare void @crypto_blake2b_general_init(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @feof(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

declare void @crypto_blake2b_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

declare void @panic(ptr noundef) local_unnamed_addr #2

declare void @crypto_blake2b_final(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @crypto_sha512_init(ptr noundef) local_unnamed_addr #2

declare void @crypto_sha512_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @crypto_sha512_final(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @print_buffer(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nofree 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 #4 = { nofree nounwind memory(read) "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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass