; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (dstu8845)

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

@.str = external hidden unnamed_addr constant [18 x i8], align 1

; 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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @next_gamma(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @dstu8845_crypt(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  br label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %14, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1020, i32 noundef %13, ptr noundef null)
  br label %61

14:                                               ; preds = %9
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %22, label %20

20:                                               ; preds = %17
  store i32 2, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1021, i32 noundef %21, ptr noundef null)
  br label %61

22:                                               ; preds = %17
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ByteArray_st, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ByteArray_st, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !14
  store i64 %30, ptr %8, align 8, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Dstu8845Ctx_st, ptr %31, i32 0, i32 3
  %33 = getelementptr inbounds [16 x i64], ptr %32, i64 0, i64 0
  store ptr %33, ptr %7, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %59, %24
  %35 = load i64, ptr %8, align 8, !tbaa !15
  %36 = add i64 %35, -1
  store i64 %36, ptr %8, align 8, !tbaa !15
  %37 = icmp ne i64 %35, 0
  br i1 %37, label %38, label %60

38:                                               ; preds = %34
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Dstu8845Ctx_st, ptr %40, i32 0, i32 5
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = add i64 %42, 1
  store i64 %43, ptr %41, align 8, !tbaa !16
  %44 = getelementptr inbounds i8, ptr %39, i64 %42
  %45 = load i8, ptr %44, align 1, !tbaa !18
  %46 = zext i8 %45 to i32
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load i8, ptr %47, align 1, !tbaa !18
  %50 = zext i8 %49 to i32
  %51 = xor i32 %50, %46
  %52 = trunc i32 %51 to i8
  store i8 %52, ptr %47, align 1, !tbaa !18
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Dstu8845Ctx_st, ptr %53, i32 0, i32 5
  %55 = load i64, ptr %54, align 8, !tbaa !16
  %56 = icmp eq i64 %55, 128
  br i1 %56, label %57, label %59

57:                                               ; preds = %38
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_gamma(ptr noundef %58)
  br label %59

59:                                               ; preds = %57, %38
  br label %34, !llvm.loop !19

60:                                               ; preds = %34
  br label %61

61:                                               ; preds = %60, %20, %12
  %62 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !6, i64 0}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !13, i64 344}
!17 = !{!"Dstu8845Ctx_st", !7, i64 0, !7, i64 64, !7, i64 192, !7, i64 208, !13, i64 336, !13, i64 344}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [18 x i8], align 1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @next_gamma(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @dstu8845_crypt(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit.sink.split, label %3

3:                                                ; preds = %2
  %.not17 = icmp eq ptr %1, null
  br i1 %.not17, label %.loopexit.sink.split, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 208
  %.not1819 = icmp eq i64 %6, 0
  br i1 %.not1819, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %8 = load ptr, ptr %1, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 344
  br label %10

10:                                               ; preds = %.lr.ph, %22
  %.in = phi i64 [ %6, %.lr.ph ], [ %11, %22 ]
  %.01420 = phi ptr [ %8, %.lr.ph ], [ %16, %22 ]
  %11 = add i64 %.in, -1
  %12 = load i64, ptr %9, align 8, !tbaa !12
  %13 = add i64 %12, 1
  store i64 %13, ptr %9, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %7, i64 %12
  %15 = load i8, ptr %14, align 1, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %.01420, i64 1
  %17 = load i8, ptr %.01420, align 1, !tbaa !14
  %18 = xor i8 %17, %15
  store i8 %18, ptr %.01420, align 1, !tbaa !14
  %19 = load i64, ptr %9, align 8, !tbaa !12
  %20 = icmp eq i64 %19, 128
  br i1 %20, label %21, label %22

21:                                               ; preds = %10
  tail call void @next_gamma(ptr noundef nonnull %0)
  br label %22

22:                                               ; preds = %21, %10
  %.not18 = icmp eq i64 %11, 0
  br i1 %.not18, label %.loopexit, label %10, !llvm.loop !15

.loopexit.sink.split:                             ; preds = %3, %2
  %.sink = phi i64 [ 1020, %2 ], [ 1021, %3 ]
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef %.sink, i32 noundef 2, ptr noundef null) #2
  br label %.loopexit

.loopexit:                                        ; preds = %22, %.loopexit.sink.split, %4
  %.013 = phi i32 [ 0, %4 ], [ 2, %.loopexit.sink.split ], [ 0, %22 ]
  ret i32 %.013
}

attributes #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 = { 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 = { 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 8}
!6 = !{!"ByteArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !10, i64 344}
!13 = !{!"Dstu8845Ctx_st", !8, i64 0, !8, i64 64, !8, i64 192, !8, i64 208, !10, i64 336, !10, i64 344}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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