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

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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@hex_symbols = external hidden global ptr, align 8

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

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

; 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 @ba_to_hex(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  br label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %11
  store i32 2, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 727, i32 noundef %15, ptr noundef null)
  br label %103

16:                                               ; preds = %11
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

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

22:                                               ; preds = %19
  store i32 2, ptr %7, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 728, i32 noundef %23, ptr noundef null)
  br label %103

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %32, label %30

30:                                               ; preds = %27
  store i32 2, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 729, i32 noundef %31, ptr noundef null)
  br label %103

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ByteArray_st, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ByteArray_st, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !14
  store i64 %40, ptr %10, align 8, !tbaa !15
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i64, ptr %41, align 8, !tbaa !15
  %43 = load i64, ptr %10, align 8, !tbaa !15
  %44 = mul i64 %43, 2
  %45 = add i64 %44, 1
  %46 = icmp ult i64 %42, %45
  br i1 %46, label %47, label %56

47:                                               ; preds = %34
  %48 = load i64, ptr %10, align 8, !tbaa !15
  %49 = mul i64 %48, 2
  %50 = add i64 %49, 1
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %50, ptr %51, align 8, !tbaa !15
  br label %52

52:                                               ; preds = %47
  store i32 16, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 735, i32 noundef %53, ptr noundef null)
  br label %103

54:                                               ; No predecessors!
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55, %34
  store i64 0, ptr %9, align 8, !tbaa !15
  br label %57

57:                                               ; preds = %91, %56
  %58 = load i64, ptr %9, align 8, !tbaa !15
  %59 = load i64, ptr %10, align 8, !tbaa !15
  %60 = icmp ult i64 %58, %59
  br i1 %60, label %61, label %94

61:                                               ; preds = %57
  %62 = load ptr, ptr @hex_symbols, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i64, ptr %9, align 8, !tbaa !15
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !16
  %67 = zext i8 %66 to i32
  %68 = ashr i32 %67, 4
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %62, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !16
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i64, ptr %9, align 8, !tbaa !15
  %74 = mul i64 %73, 2
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  store i8 %71, ptr %75, align 1, !tbaa !16
  %76 = load ptr, ptr @hex_symbols, align 8, !tbaa !5
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load i64, ptr %9, align 8, !tbaa !15
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !16
  %81 = zext i8 %80 to i32
  %82 = and i32 %81, 15
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %76, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !16
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = load i64, ptr %9, align 8, !tbaa !15
  %88 = mul i64 %87, 2
  %89 = add i64 %88, 1
  %90 = getelementptr inbounds i8, ptr %86, i64 %89
  store i8 %85, ptr %90, align 1, !tbaa !16
  br label %91

91:                                               ; preds = %61
  %92 = load i64, ptr %9, align 8, !tbaa !15
  %93 = add i64 %92, 1
  store i64 %93, ptr %9, align 8, !tbaa !15
  br label %57, !llvm.loop !17

94:                                               ; preds = %57
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = load i64, ptr %10, align 8, !tbaa !15
  %97 = mul i64 %96, 2
  %98 = getelementptr inbounds i8, ptr %95, i64 %97
  store i8 0, ptr %98, align 1, !tbaa !16
  %99 = load i64, ptr %10, align 8, !tbaa !15
  %100 = mul i64 %99, 2
  %101 = add i64 %100, 1
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %101, ptr %102, align 8, !tbaa !15
  br label %103

103:                                              ; preds = %94, %52, %30, %22, %14
  %104 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %104
}

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 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 [20 x i8], align 1
@hex_symbols = external hidden local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 17) i32 @ba_to_hex(ptr noundef readonly %0, ptr noundef writeonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 727, i32 noundef 2, ptr noundef null) #2
  br label %36

5:                                                ; preds = %3
  %.not33 = icmp eq ptr %1, null
  br i1 %.not33, label %6, label %7

6:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 728, i32 noundef 2, ptr noundef null) #2
  br label %36

7:                                                ; preds = %5
  %.not34 = icmp eq ptr %2, null
  br i1 %.not34, label %8, label %9

8:                                                ; preds = %7
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 729, i32 noundef 2, ptr noundef null) #2
  br label %36

9:                                                ; preds = %7
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = load i64, ptr %2, align 8, !tbaa !12
  %14 = shl i64 %12, 1
  %15 = or disjoint i64 %14, 1
  %.not35 = icmp ugt i64 %13, %14
  br i1 %.not35, label %.preheader, label %16

.preheader:                                       ; preds = %9
  %.not37 = icmp eq i64 %12, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

16:                                               ; preds = %9
  store i64 %15, ptr %2, align 8, !tbaa !12
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 735, i32 noundef 16, ptr noundef null) #2
  br label %36

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.02836 = phi i64 [ %34, %.lr.ph ], [ 0, %.preheader ]
  %17 = load ptr, ptr @hex_symbols, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %10, i64 %.02836
  %19 = load i8, ptr %18, align 1, !tbaa !14
  %20 = lshr i8 %19, 4
  %21 = zext nneg i8 %20 to i64
  %22 = getelementptr inbounds i8, ptr %17, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !14
  %24 = shl i64 %.02836, 1
  %25 = getelementptr inbounds i8, ptr %1, i64 %24
  store i8 %23, ptr %25, align 1, !tbaa !14
  %26 = load ptr, ptr @hex_symbols, align 8, !tbaa !13
  %27 = load i8, ptr %18, align 1, !tbaa !14
  %28 = and i8 %27, 15
  %29 = zext nneg i8 %28 to i64
  %30 = getelementptr inbounds i8, ptr %26, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !14
  %32 = or disjoint i64 %24, 1
  %33 = getelementptr inbounds i8, ptr %1, i64 %32
  store i8 %31, ptr %33, align 1, !tbaa !14
  %34 = add nuw i64 %.02836, 1
  %exitcond.not = icmp eq i64 %34, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %35 = getelementptr inbounds i8, ptr %1, i64 %14
  store i8 0, ptr %35, align 1, !tbaa !14
  store i64 %15, ptr %2, align 8, !tbaa !12
  br label %36

36:                                               ; preds = %._crit_edge, %16, %8, %6, %4
  %.0 = phi i32 [ 16, %16 ], [ 0, %._crit_edge ], [ 2, %8 ], [ 2, %6 ], [ 2, %4 ]
  ret i32 %.0
}

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, !7, i64 0}
!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, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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