; LLVM IR from square/subzero :: core/external-crypto/modes/ltc (ltc_gcm)

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

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

; 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: nounwind uwtable
declare dso_local i32 @gcm_add_iv(ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_add_aad(ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_process(ptr noundef, i64 noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gcm_memory(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, ptr noundef %9, i64 noundef %10, i32 noundef %11, ptr noundef %12) #0 {
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca i64, align 8
  %25 = alloca i32, align 4
  %26 = alloca ptr, align 8
  %27 = alloca ptr, align 8
  %28 = alloca ptr, align 8
  %29 = alloca i32, align 4
  %30 = alloca i32, align 4
  %31 = alloca ptr, align 8
  store ptr %0, ptr %14, align 8, !tbaa !5
  store i64 %1, ptr %15, align 8, !tbaa !9
  store ptr %2, ptr %16, align 8, !tbaa !5
  store i64 %3, ptr %17, align 8, !tbaa !9
  store ptr %4, ptr %18, align 8, !tbaa !5
  store i64 %5, ptr %19, align 8, !tbaa !9
  store ptr %6, ptr %20, align 8, !tbaa !5
  store i64 %7, ptr %21, align 8, !tbaa !9
  store ptr %8, ptr %22, align 8, !tbaa !5
  store ptr %9, ptr %23, align 8, !tbaa !5
  store i64 %10, ptr %24, align 8, !tbaa !9
  store i32 %11, ptr %25, align 4, !tbaa !11
  store ptr %12, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %29) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #5
  %32 = load i64, ptr %24, align 8, !tbaa !9
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %30, align 4, !tbaa !11
  %34 = call noalias ptr @malloc(i64 noundef 65904) #6
  store ptr %34, ptr %28, align 8, !tbaa !5
  store ptr %34, ptr %27, align 8, !tbaa !5
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = load i64, ptr %15, align 8, !tbaa !9
  %37 = trunc i64 %36 to i32
  %38 = load ptr, ptr %28, align 8, !tbaa !5
  %39 = call i32 @gcm_init(ptr noundef %35, i32 noundef %37, ptr noundef %38)
  store i32 %39, ptr %29, align 4, !tbaa !11
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %13
  br label %93

42:                                               ; preds = %13
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = load i64, ptr %17, align 8, !tbaa !9
  %45 = load ptr, ptr %28, align 8, !tbaa !5
  %46 = call i32 @gcm_add_iv(ptr noundef %43, i64 noundef %44, ptr noundef %45)
  store i32 %46, ptr %29, align 4, !tbaa !11
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %42
  br label %93

49:                                               ; preds = %42
  %50 = load ptr, ptr %18, align 8, !tbaa !5
  %51 = load i64, ptr %19, align 8, !tbaa !9
  %52 = load ptr, ptr %28, align 8, !tbaa !5
  %53 = call i32 @gcm_add_aad(ptr noundef %50, i64 noundef %51, ptr noundef %52)
  store i32 %53, ptr %29, align 4, !tbaa !11
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %49
  br label %93

56:                                               ; preds = %49
  %57 = load ptr, ptr %20, align 8, !tbaa !5
  %58 = load i64, ptr %21, align 8, !tbaa !9
  %59 = load ptr, ptr %22, align 8, !tbaa !5
  %60 = load i32, ptr %25, align 4, !tbaa !11
  %61 = load ptr, ptr %28, align 8, !tbaa !5
  %62 = call i32 @gcm_process(ptr noundef %57, i64 noundef %58, ptr noundef %59, i32 noundef %60, ptr noundef %61)
  store i32 %62, ptr %29, align 4, !tbaa !11
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %56
  br label %93

65:                                               ; preds = %56
  %66 = load i32, ptr %25, align 4, !tbaa !11
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %72

68:                                               ; preds = %65
  %69 = load ptr, ptr %23, align 8, !tbaa !5
  %70 = load ptr, ptr %28, align 8, !tbaa !5
  %71 = call i32 @gcm_done(ptr noundef %69, ptr noundef %30, ptr noundef %70)
  store i32 %71, ptr %29, align 4, !tbaa !11
  br label %92

72:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %31) #5
  %73 = load i64, ptr %24, align 8, !tbaa !9
  %74 = call noalias ptr @malloc(i64 noundef %73) #6
  store ptr %74, ptr %31, align 8, !tbaa !5
  %75 = load ptr, ptr %31, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %90

77:                                               ; preds = %72
  %78 = load ptr, ptr %31, align 8, !tbaa !5
  %79 = load ptr, ptr %28, align 8, !tbaa !5
  %80 = call i32 @gcm_done(ptr noundef %78, ptr noundef %30, ptr noundef %79)
  store i32 %80, ptr %29, align 4, !tbaa !11
  %81 = load ptr, ptr %31, align 8, !tbaa !5
  %82 = load ptr, ptr %23, align 8, !tbaa !5
  %83 = load i64, ptr %24, align 8, !tbaa !9
  %84 = call i32 @memcmp(ptr noundef %81, ptr noundef %82, i64 noundef %83) #7
  %85 = icmp eq i32 %84, 0
  %86 = zext i1 %85 to i64
  %87 = select i1 %85, i32 0, i32 1
  %88 = load ptr, ptr %26, align 8, !tbaa !5
  store i32 %87, ptr %88, align 4, !tbaa !11
  %89 = load ptr, ptr %31, align 8, !tbaa !5
  call void @free(ptr noundef %89) #5
  br label %91

90:                                               ; preds = %72
  store i32 1, ptr %29, align 4, !tbaa !11
  br label %91

91:                                               ; preds = %90, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %31) #5
  br label %92

92:                                               ; preds = %91, %68
  br label %93

93:                                               ; preds = %92, %64, %55, %48, %41
  %94 = load ptr, ptr %27, align 8, !tbaa !5
  call void @free(ptr noundef %94) #5
  %95 = load i32, ptr %29, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #5
  ret i32 %95
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

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

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 = { 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind willreturn memory(read) }

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


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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_add_iv(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_add_aad(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_process(ptr noundef, i64 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gcm_memory(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, ptr noundef %9, i64 noundef %10, i32 noundef %11, ptr nocapture noundef writeonly %12) local_unnamed_addr #0 {
  %14 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #5
  %15 = trunc i64 %10 to i32
  store i32 %15, ptr %14, align 4, !tbaa !5
  %16 = tail call noalias dereferenceable_or_null(65904) ptr @malloc(i64 noundef 65904) #6
  %17 = trunc i64 %1 to i32
  %18 = tail call i32 @gcm_init(ptr noundef %0, i32 noundef %17, ptr noundef %16)
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %35

19:                                               ; preds = %13
  %20 = tail call i32 @gcm_add_iv(ptr noundef %2, i64 noundef %3, ptr noundef %16)
  %.not33 = icmp eq i32 %20, 0
  br i1 %.not33, label %21, label %35

21:                                               ; preds = %19
  %22 = tail call i32 @gcm_add_aad(ptr noundef %4, i64 noundef %5, ptr noundef %16)
  %.not34 = icmp eq i32 %22, 0
  br i1 %.not34, label %23, label %35

23:                                               ; preds = %21
  %24 = tail call i32 @gcm_process(ptr noundef %6, i64 noundef %7, ptr noundef %8, i32 noundef %11, ptr noundef %16)
  %.not35 = icmp eq i32 %24, 0
  br i1 %.not35, label %25, label %35

25:                                               ; preds = %23
  %26 = icmp eq i32 %11, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %25
  %28 = call i32 @gcm_done(ptr noundef %9, ptr noundef nonnull %14, ptr noundef %16)
  br label %35

29:                                               ; preds = %25
  %30 = tail call noalias ptr @malloc(i64 noundef %10) #6
  %.not36 = icmp eq ptr %30, null
  br i1 %.not36, label %35, label %31

31:                                               ; preds = %29
  %32 = call i32 @gcm_done(ptr noundef nonnull %30, ptr noundef nonnull %14, ptr noundef %16)
  %bcmp = call i32 @bcmp(ptr nonnull %30, ptr %9, i64 %10)
  %33 = icmp ne i32 %bcmp, 0
  %34 = zext i1 %33 to i32
  store i32 %34, ptr %12, align 4, !tbaa !5
  call void @free(ptr noundef nonnull %30) #5
  br label %35

35:                                               ; preds = %31, %29, %27, %23, %21, %19, %13
  %.1 = phi i32 [ %18, %13 ], [ %20, %19 ], [ %22, %21 ], [ %24, %23 ], [ %28, %27 ], [ %32, %31 ], [ 1, %29 ]
  call void @free(ptr noundef %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #5
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

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 = { 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 #3 = { 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 #4 = { nofree nounwind willreturn memory(argmem: read) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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