; LLVM IR from imkcat/CatCrypto :: Sources/ModuleMaps/Argon2 (argon2)

; 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.Argon2_instance_t = type { ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.Argon2_Context = type { ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @argon2_ctx(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.Argon2_instance_t, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i32 @validate_inputs(ptr noundef %11)
  store i32 %12, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 56, ptr %9) #3
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp ne i32 0, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %16, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %105

17:                                               ; preds = %2
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp ne i32 0, %18
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp ne i32 1, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp ne i32 2, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i32 -26, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %105

27:                                               ; preds = %23, %20, %17
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Argon2_Context, ptr %28, i32 0, i32 11
  %30 = load i32, ptr %29, align 8, !tbaa !11
  store i32 %30, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Argon2_Context, ptr %32, i32 0, i32 12
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = mul i32 8, %34
  %36 = icmp ult i32 %31, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %27
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Argon2_Context, ptr %38, i32 0, i32 12
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = mul i32 8, %40
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %37, %27
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Argon2_Context, ptr %44, i32 0, i32 12
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = mul i32 %46, 4
  %48 = udiv i32 %43, %47
  store i32 %48, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Argon2_Context, ptr %50, i32 0, i32 12
  %52 = load i32, ptr %51, align 4, !tbaa !13
  %53 = mul i32 %52, 4
  %54 = mul i32 %49, %53
  store i32 %54, ptr %7, align 4, !tbaa !9
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Argon2_Context, ptr %55, i32 0, i32 14
  %57 = load i32, ptr %56, align 4, !tbaa !14
  %58 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 1
  store i32 %57, ptr %58, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 0
  store ptr null, ptr %59, align 8, !tbaa !17
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Argon2_Context, ptr %60, i32 0, i32 10
  %62 = load i32, ptr %61, align 4, !tbaa !18
  %63 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 2
  store i32 %62, ptr %63, align 4, !tbaa !19
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 3
  store i32 %64, ptr %65, align 8, !tbaa !20
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 4
  store i32 %66, ptr %67, align 4, !tbaa !21
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = mul i32 %68, 4
  %70 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 5
  store i32 %69, ptr %70, align 8, !tbaa !22
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Argon2_Context, ptr %71, i32 0, i32 12
  %73 = load i32, ptr %72, align 4, !tbaa !13
  %74 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 6
  store i32 %73, ptr %74, align 4, !tbaa !23
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Argon2_Context, ptr %75, i32 0, i32 13
  %77 = load i32, ptr %76, align 8, !tbaa !24
  %78 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 7
  store i32 %77, ptr %78, align 8, !tbaa !25
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 8
  store i32 %79, ptr %80, align 4, !tbaa !26
  %81 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 7
  %82 = load i32, ptr %81, align 8, !tbaa !25
  %83 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 6
  %84 = load i32, ptr %83, align 4, !tbaa !23
  %85 = icmp ugt i32 %82, %84
  br i1 %85, label %86, label %90

86:                                               ; preds = %42
  %87 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 6
  %88 = load i32, ptr %87, align 4, !tbaa !23
  %89 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 7
  store i32 %88, ptr %89, align 8, !tbaa !25
  br label %90

90:                                               ; preds = %86, %42
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = call i32 @initialize(ptr noundef %9, ptr noundef %91)
  store i32 %92, ptr %6, align 4, !tbaa !9
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = icmp ne i32 0, %93
  br i1 %94, label %95, label %97

95:                                               ; preds = %90
  %96 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %96, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %105

97:                                               ; preds = %90
  %98 = call i32 @fill_memory_blocks(ptr noundef %9)
  store i32 %98, ptr %6, align 4, !tbaa !9
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = icmp ne i32 0, %99
  br i1 %100, label %101, label %103

101:                                              ; preds = %97
  %102 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %102, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %105

103:                                              ; preds = %97
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  call void @finalize(ptr noundef %104, ptr noundef %9)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %105

105:                                              ; preds = %103, %101, %95, %26, %15
  call void @llvm.lifetime.end.p0(i64 56, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %106 = load i32, ptr %3, align 4
  ret i32 %106
}

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

declare i32 @validate_inputs(ptr noundef) #2

declare i32 @initialize(ptr noundef, ptr noundef) #2

declare i32 @fill_memory_blocks(ptr noundef) #2

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

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

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 }

!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, !10, i64 80}
!12 = !{!"Argon2_Context", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !6, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !6, i64 96, !6, i64 104, !10, i64 112}
!13 = !{!12, !10, i64 84}
!14 = !{!12, !10, i64 92}
!15 = !{!16, !10, i64 8}
!16 = !{!"Argon2_instance_t", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !6, i64 48}
!17 = !{!16, !6, i64 0}
!18 = !{!12, !10, i64 76}
!19 = !{!16, !10, i64 12}
!20 = !{!16, !10, i64 16}
!21 = !{!16, !10, i64 20}
!22 = !{!16, !10, i64 24}
!23 = !{!16, !10, i64 28}
!24 = !{!12, !10, i64 88}
!25 = !{!16, !10, i64 32}
!26 = !{!16, !10, 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"

%struct.Argon2_instance_t = type { ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @argon2_ctx(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.Argon2_instance_t, align 8
  %4 = tail call i32 @validate_inputs(ptr noundef %0) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #4
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %37

5:                                                ; preds = %2
  %or.cond3 = icmp ugt i32 %1, 2
  br i1 %or.cond3, label %37, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 84
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = shl i32 %10, 3
  %spec.select = tail call i32 @llvm.umax.i32(i32 %8, i32 %11)
  %12 = shl i32 %10, 2
  %13 = udiv i32 %spec.select, %12
  %14 = mul i32 %13, %12
  %15 = getelementptr inbounds i8, ptr %0, i64 92
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %16, ptr %17, align 8, !tbaa !13
  store ptr null, ptr %3, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %0, i64 76
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %19, ptr %20, align 4, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 %14, ptr %21, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 %13, ptr %22, align 4, !tbaa !19
  %23 = shl i32 %13, 2
  %24 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 %23, ptr %24, align 8, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %3, i64 28
  store i32 %10, ptr %25, align 4, !tbaa !21
  %26 = getelementptr inbounds i8, ptr %0, i64 88
  %27 = load i32, ptr %26, align 8, !tbaa !22
  %28 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 %27, ptr %28, align 8, !tbaa !23
  %29 = getelementptr inbounds i8, ptr %3, i64 36
  store i32 %1, ptr %29, align 4, !tbaa !24
  %30 = icmp ugt i32 %27, %10
  br i1 %30, label %31, label %32

31:                                               ; preds = %6
  store i32 %10, ptr %28, align 8, !tbaa !23
  br label %32

32:                                               ; preds = %31, %6
  %33 = call i32 @initialize(ptr noundef nonnull %3, ptr noundef nonnull %0) #4
  %.not38 = icmp eq i32 %33, 0
  br i1 %.not38, label %34, label %37

34:                                               ; preds = %32
  %35 = call i32 @fill_memory_blocks(ptr noundef nonnull %3) #4
  %.not39 = icmp eq i32 %35, 0
  br i1 %.not39, label %36, label %37

36:                                               ; preds = %34
  call void @finalize(ptr noundef nonnull %0, ptr noundef nonnull %3) #4
  br label %37

37:                                               ; preds = %34, %32, %5, %2, %36
  %.0 = phi i32 [ 0, %36 ], [ %4, %2 ], [ -26, %5 ], [ %33, %32 ], [ %35, %34 ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #4
  ret i32 %.0
}

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

declare i32 @validate_inputs(ptr noundef) local_unnamed_addr #2

declare i32 @initialize(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @fill_memory_blocks(ptr noundef) local_unnamed_addr #2

declare void @finalize(ptr noundef, ptr 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 80}
!6 = !{!"Argon2_Context", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !10, i64 56, !7, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !7, i64 96, !7, i64 104, !10, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 84}
!12 = !{!6, !10, i64 92}
!13 = !{!14, !10, i64 8}
!14 = !{!"Argon2_instance_t", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 48}
!15 = !{!14, !7, i64 0}
!16 = !{!6, !10, i64 76}
!17 = !{!14, !10, i64 12}
!18 = !{!14, !10, i64 16}
!19 = !{!14, !10, i64 20}
!20 = !{!14, !10, i64 24}
!21 = !{!14, !10, i64 28}
!22 = !{!6, !10, i64 88}
!23 = !{!14, !10, i64 32}
!24 = !{!14, !10, i64 36}


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