; 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_Context = type { ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32 }

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @argon2_verify(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.Argon2_Context, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 120, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp ugt i64 %16, 4294967295
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store i32 -5, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %93

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 -32, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %93

23:                                               ; preds = %19
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call i64 @strlen(ptr noundef %24) #7
  store i64 %25, ptr %13, align 8, !tbaa !9
  %26 = load i64, ptr %13, align 8, !tbaa !9
  %27 = icmp ugt i64 %26, 4294967295
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 -32, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %93

29:                                               ; preds = %23
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = trunc i64 %30 to i32
  store i32 %31, ptr %14, align 4, !tbaa !11
  %32 = load i32, ptr %14, align 4, !tbaa !11
  %33 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 5
  store i32 %32, ptr %33, align 8, !tbaa !13
  %34 = load i32, ptr %14, align 4, !tbaa !11
  %35 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 1
  store i32 %34, ptr %35, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 5
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = zext i32 %37 to i64
  %39 = call noalias ptr @malloc(i64 noundef %38) #8
  %40 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 4
  store ptr %39, ptr %40, align 8, !tbaa !16
  %41 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = zext i32 %42 to i64
  %44 = call noalias ptr @malloc(i64 noundef %43) #8
  %45 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 0
  store ptr %44, ptr %45, align 8, !tbaa !17
  %46 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %53

49:                                               ; preds = %29
  %50 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = icmp ne ptr %51, null
  br i1 %52, label %54, label %53

53:                                               ; preds = %49, %29
  store i32 -22, ptr %12, align 4, !tbaa !11
  br label %86

54:                                               ; preds = %49
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 2
  store ptr %55, ptr %56, align 8, !tbaa !18
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = trunc i64 %57 to i32
  %59 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 3
  store i32 %58, ptr %59, align 8, !tbaa !19
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !11
  %62 = call i32 @decode_string(ptr noundef %10, ptr noundef %60, i32 noundef %61)
  store i32 %62, ptr %12, align 4, !tbaa !11
  %63 = load i32, ptr %12, align 4, !tbaa !11
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %54
  br label %86

66:                                               ; preds = %54
  %67 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  store ptr %68, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 1
  %70 = load i32, ptr %69, align 8, !tbaa !15
  %71 = zext i32 %70 to i64
  %72 = call noalias ptr @malloc(i64 noundef %71) #8
  %73 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 0
  store ptr %72, ptr %73, align 8, !tbaa !17
  %74 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !17
  %76 = icmp ne ptr %75, null
  br i1 %76, label %78, label %77

77:                                               ; preds = %66
  store i32 -22, ptr %12, align 4, !tbaa !11
  br label %86

78:                                               ; preds = %66
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load i32, ptr %9, align 4, !tbaa !11
  %81 = call i32 @argon2_verify_ctx(ptr noundef %10, ptr noundef %79, i32 noundef %80)
  store i32 %81, ptr %12, align 4, !tbaa !11
  %82 = load i32, ptr %12, align 4, !tbaa !11
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %85

84:                                               ; preds = %78
  br label %86

85:                                               ; preds = %78
  br label %86

86:                                               ; preds = %85, %84, %77, %65, %53
  %87 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 4
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  call void @free(ptr noundef %88) #6
  %89 = getelementptr inbounds %struct.Argon2_Context, ptr %10, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  call void @free(ptr noundef %90) #6
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %91) #6
  %92 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %92, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %93

93:                                               ; preds = %86, %28, %22, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 120, ptr %10) #6
  %94 = load i32, ptr %5, align 4
  ret i32 %94
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

declare i32 @decode_string(ptr noundef, ptr noundef, i32 noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @argon2_verify_ctx(ptr noundef, ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = { nounwind willreturn 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 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 40}
!14 = !{!"Argon2_Context", !6, i64 0, !12, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !12, i64 56, !6, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !6, i64 96, !6, i64 104, !12, i64 112}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !6, i64 32}
!17 = !{!14, !6, i64 0}
!18 = !{!14, !6, i64 16}
!19 = !{!14, !12, i64 24}


; 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_Context = type { ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32 }

; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @argon2_verify(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.Argon2_Context, align 8
  call void @llvm.lifetime.start.p0(i64 120, ptr nonnull %5) #6
  %6 = icmp ugt i64 %2, 4294967295
  br i1 %6, label %36, label %7

7:                                                ; preds = %4
  %8 = icmp eq ptr %0, null
  br i1 %8, label %36, label %9

9:                                                ; preds = %7
  %10 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %11 = icmp ugt i64 %10, 4294967295
  br i1 %11, label %36, label %12

12:                                               ; preds = %9
  %13 = trunc nuw i64 %10 to i32
  %14 = getelementptr inbounds i8, ptr %5, i64 40
  store i32 %13, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %13, ptr %15, align 8, !tbaa !11
  %16 = tail call noalias ptr @malloc(i64 noundef %10) #8
  %17 = getelementptr inbounds i8, ptr %5, i64 32
  store ptr %16, ptr %17, align 8, !tbaa !12
  %18 = tail call noalias ptr @malloc(i64 noundef %10) #8
  store ptr %18, ptr %5, align 8, !tbaa !13
  %19 = icmp ne ptr %16, null
  %20 = icmp ne ptr %18, null
  %or.cond = and i1 %19, %20
  br i1 %or.cond, label %21, label %33

21:                                               ; preds = %12
  %22 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %1, ptr %22, align 8, !tbaa !14
  %23 = trunc nuw i64 %2 to i32
  %24 = getelementptr inbounds i8, ptr %5, i64 24
  store i32 %23, ptr %24, align 8, !tbaa !15
  %25 = call i32 @decode_string(ptr noundef nonnull %5, ptr noundef nonnull %0, i32 noundef %3) #6
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %26, label %33

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !13
  %28 = load i32, ptr %15, align 8, !tbaa !11
  %29 = zext i32 %28 to i64
  %30 = call noalias ptr @malloc(i64 noundef %29) #8
  store ptr %30, ptr %5, align 8, !tbaa !13
  %.not24 = icmp eq ptr %30, null
  br i1 %.not24, label %33, label %31

31:                                               ; preds = %26
  %32 = call i32 @argon2_verify_ctx(ptr noundef nonnull %5, ptr noundef %27, i32 noundef %3)
  br label %33

33:                                               ; preds = %26, %12, %31, %21
  %.019 = phi i32 [ %25, %21 ], [ %32, %31 ], [ -22, %12 ], [ -22, %26 ]
  %.018 = phi ptr [ null, %21 ], [ %27, %31 ], [ null, %12 ], [ %27, %26 ]
  %34 = load ptr, ptr %17, align 8, !tbaa !12
  call void @free(ptr noundef %34) #6
  %35 = load ptr, ptr %5, align 8, !tbaa !13
  call void @free(ptr noundef %35) #6
  call void @free(ptr noundef %.018) #6
  br label %36

36:                                               ; preds = %9, %7, %4, %33
  %.0 = phi i32 [ %.019, %33 ], [ -5, %4 ], [ -32, %7 ], [ -32, %9 ]
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %5) #6
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

declare i32 @decode_string(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @argon2_verify_ctx(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = { mustprogress nofree nounwind willreturn memory(argmem: 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 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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, !10, i64 40}
!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 8}
!12 = !{!6, !7, i64 32}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !10, i64 24}


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