; LLVM IR from dynexcoin/Dynex :: src/crypto (oaes_lib)

; 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._oaes_ctx = type { ptr, i16, [16 x i8] }
%struct._oaes_key = type { i64, ptr, i64, ptr, i64, i64 }

@oaes_header = external hidden global <{ i8, i8, i8, i8, i8, i8, [10 x i8] }>, align 16

; 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 uwtable
define dso_local i32 @oaes_key_export(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %3
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._oaes_ctx, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp eq ptr null, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 7, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

21:                                               ; preds = %15
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp eq ptr null, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 4, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

25:                                               ; preds = %21
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !12
  store i64 %27, ptr %8, align 8, !tbaa !12
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._oaes_ctx, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct._oaes_key, ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = add i64 %32, 16
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %33, ptr %34, align 8, !tbaa !12
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = icmp eq ptr null, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %25
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

38:                                               ; preds = %25
  %39 = load i64, ptr %8, align 8, !tbaa !12
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %40, align 8, !tbaa !12
  %42 = icmp ult i64 %39, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %38
  store i32 9, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

44:                                               ; preds = %38
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %45, ptr align 16 @oaes_header, i64 16, i1 false)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 5
  store i8 1, ptr %47, align 1, !tbaa !16
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._oaes_ctx, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct._oaes_key, ptr %50, i32 0, i32 0
  %52 = load i64, ptr %51, align 8, !tbaa !14
  %53 = trunc i64 %52 to i8
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 7
  store i8 %53, ptr %55, align 1, !tbaa !16
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 16
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._oaes_ctx, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct._oaes_key, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._oaes_ctx, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct._oaes_key, ptr %65, i32 0, i32 0
  %67 = load i64, ptr %66, align 8, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %57, ptr align 1 %62, i64 %67, i1 false)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

68:                                               ; preds = %44, %43, %37, %24, %20, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

; 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

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


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

@oaes_header = external hidden local_unnamed_addr global <{ i8, i8, i8, i8, i8, i8, [10 x i8] }>, align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 10) i32 @oaes_key_export(ptr noundef readonly %0, ptr noundef writeonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %28, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %28, label %8

8:                                                ; preds = %5
  %9 = icmp eq ptr %2, null
  br i1 %9, label %28, label %10

10:                                               ; preds = %8
  %11 = load i64, ptr %2, align 8, !tbaa !11
  %12 = load i64, ptr %6, align 8, !tbaa !13
  %13 = add i64 %12, 16
  store i64 %13, ptr %2, align 8, !tbaa !11
  %14 = icmp eq ptr %1, null
  br i1 %14, label %28, label %15

15:                                               ; preds = %10
  %16 = icmp ult i64 %11, %13
  br i1 %16, label %28, label %17

17:                                               ; preds = %15
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %1, ptr noundef nonnull align 16 dereferenceable(16) @oaes_header, i64 16, i1 false)
  %18 = getelementptr inbounds i8, ptr %1, i64 5
  store i8 1, ptr %18, align 1, !tbaa !15
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = trunc i64 %20 to i8
  %22 = getelementptr inbounds i8, ptr %1, i64 7
  store i8 %21, ptr %22, align 1, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %1, i64 16
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load i64, ptr %24, align 8, !tbaa !13
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %23, ptr align 1 %26, i64 %27, i1 false)
  br label %28

28:                                               ; preds = %15, %10, %8, %5, %3, %17
  %.0 = phi i32 [ 0, %17 ], [ 2, %3 ], [ 7, %5 ], [ 4, %8 ], [ 0, %10 ], [ 9, %15 ]
  ret i32 %.0
}

; Function Attrs: mustprogress 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) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: readwrite) }

!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, !7, i64 0}
!6 = !{!"_oaes_ctx", !7, i64 0, !10, i64 8, !8, i64 10}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_oaes_key", !12, i64 0, !7, i64 8, !12, i64 16, !7, i64 24, !12, i64 32, !12, i64 40}
!15 = !{!8, !8, i64 0}
!16 = !{!14, !7, i64 8}


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