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

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

@big_endian_test = external dso_local constant i32, align 4
@.str = external hidden unnamed_addr constant [29 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

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

; 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

18:                                               ; preds = %15
  store i32 2, ptr %9, align 4, !tbaa !11
  %19 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 114, i32 noundef %19, ptr noundef null)
  br label %133

20:                                               ; preds = %15
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %23
  store i32 2, ptr %9, align 4, !tbaa !11
  %27 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 115, i32 noundef %27, ptr noundef null)
  br label %133

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %36, label %34

34:                                               ; preds = %31
  store i32 2, ptr %9, align 4, !tbaa !11
  %35 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 116, i32 noundef %35, ptr noundef null)
  br label %133

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = mul i64 %41, 4
  %43 = icmp uge i64 %40, %42
  br i1 %43, label %46, label %44

44:                                               ; preds = %39
  store i32 2, ptr %9, align 4, !tbaa !11
  %45 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 117, i32 noundef %45, ptr noundef null)
  br label %133

46:                                               ; preds = %39
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = mul i64 %51, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %49, ptr align 4 %50, i64 %52, i1 false)
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = mul i64 %54, 4
  %56 = icmp ugt i64 %53, %55
  br i1 %56, label %57, label %66

57:                                               ; preds = %48
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !9
  %60 = mul i64 %59, 4
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = load i64, ptr %6, align 8, !tbaa !9
  %64 = mul i64 %63, 4
  %65 = sub i64 %62, %64
  call void @llvm.memset.p0.i64(ptr align 1 %61, i8 0, i64 %65, i1 false)
  br label %66

66:                                               ; preds = %57, %48
  %67 = load i8, ptr @big_endian_test, align 4, !tbaa !13
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %132

70:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %71, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %72, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %73 = load i64, ptr %6, align 8, !tbaa !9
  %74 = mul i64 %73, 4
  store i64 %74, ptr %14, align 8, !tbaa !9
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %128, %70
  %76 = load i64, ptr %13, align 8, !tbaa !9
  %77 = load i64, ptr %14, align 8, !tbaa !9
  %78 = icmp ult i64 %76, %77
  br i1 %78, label %79, label %131

79:                                               ; preds = %75
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = load i64, ptr %13, align 8, !tbaa !9
  %82 = add i64 %81, 3
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !13
  %85 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 0
  store i8 %84, ptr %85, align 1, !tbaa !13
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = load i64, ptr %13, align 8, !tbaa !9
  %88 = add i64 %87, 2
  %89 = getelementptr inbounds i8, ptr %86, i64 %88
  %90 = load i8, ptr %89, align 1, !tbaa !13
  %91 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 1
  store i8 %90, ptr %91, align 1, !tbaa !13
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = load i64, ptr %13, align 8, !tbaa !9
  %94 = add i64 %93, 1
  %95 = getelementptr inbounds i8, ptr %92, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !13
  %97 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 2
  store i8 %96, ptr %97, align 1, !tbaa !13
  %98 = load ptr, ptr %10, align 8, !tbaa !5
  %99 = load i64, ptr %13, align 8, !tbaa !9
  %100 = add i64 %99, 0
  %101 = getelementptr inbounds i8, ptr %98, i64 %100
  %102 = load i8, ptr %101, align 1, !tbaa !13
  %103 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 3
  store i8 %102, ptr %103, align 1, !tbaa !13
  %104 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 0
  %105 = load i8, ptr %104, align 1, !tbaa !13
  %106 = load ptr, ptr %11, align 8, !tbaa !5
  %107 = load i64, ptr %13, align 8, !tbaa !9
  %108 = add i64 %107, 0
  %109 = getelementptr inbounds i8, ptr %106, i64 %108
  store i8 %105, ptr %109, align 1, !tbaa !13
  %110 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 1
  %111 = load i8, ptr %110, align 1, !tbaa !13
  %112 = load ptr, ptr %11, align 8, !tbaa !5
  %113 = load i64, ptr %13, align 8, !tbaa !9
  %114 = add i64 %113, 1
  %115 = getelementptr inbounds i8, ptr %112, i64 %114
  store i8 %111, ptr %115, align 1, !tbaa !13
  %116 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 2
  %117 = load i8, ptr %116, align 1, !tbaa !13
  %118 = load ptr, ptr %11, align 8, !tbaa !5
  %119 = load i64, ptr %13, align 8, !tbaa !9
  %120 = add i64 %119, 2
  %121 = getelementptr inbounds i8, ptr %118, i64 %120
  store i8 %117, ptr %121, align 1, !tbaa !13
  %122 = getelementptr inbounds [4 x i8], ptr %12, i64 0, i64 3
  %123 = load i8, ptr %122, align 1, !tbaa !13
  %124 = load ptr, ptr %11, align 8, !tbaa !5
  %125 = load i64, ptr %13, align 8, !tbaa !9
  %126 = add i64 %125, 3
  %127 = getelementptr inbounds i8, ptr %124, i64 %126
  store i8 %123, ptr %127, align 1, !tbaa !13
  br label %128

128:                                              ; preds = %79
  %129 = load i64, ptr %13, align 8, !tbaa !9
  %130 = add i64 %129, 4
  store i64 %130, ptr %13, align 8, !tbaa !9
  br label %75, !llvm.loop !14

131:                                              ; preds = %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %132

132:                                              ; preds = %131, %66
  br label %133

133:                                              ; preds = %132, %44, %34, %26, %18
  %134 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 %134
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@big_endian_test = external dso_local local_unnamed_addr constant i32, align 4
@.str = external hidden unnamed_addr constant [29 x i8], align 1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

5:                                                ; preds = %4
  %.not46 = icmp eq i64 %1, 0
  br i1 %.not46, label %.loopexit.sink.split, label %6

6:                                                ; preds = %5
  %.not47 = icmp eq ptr %2, null
  br i1 %.not47, label %.loopexit.sink.split, label %7

7:                                                ; preds = %6
  %8 = shl i64 %1, 2
  %.not48 = icmp ugt i64 %8, %3
  br i1 %.not48, label %.loopexit.sink.split, label %9

9:                                                ; preds = %7
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %2, ptr nonnull align 4 %0, i64 %8, i1 false)
  %10 = icmp ult i64 %8, %3
  br i1 %10, label %11, label %14

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %2, i64 %8
  %13 = sub i64 %3, %8
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %12, i8 0, i64 %13, i1 false)
  br label %14

14:                                               ; preds = %11, %9
  %15 = load i8, ptr @big_endian_test, align 4, !tbaa !5
  %16 = icmp eq i8 %15, 0
  %17 = icmp ne i64 %8, 0
  %or.cond = and i1 %16, %17
  br i1 %or.cond, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %14
  %18 = add i64 %8, -1
  %19 = icmp eq i64 %18, 3
  br i1 %19, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %20 = lshr i64 %18, 2
  %21 = add nuw nsw i64 %20, 1
  %unroll_iter = and i64 %21, 9223372036854775806
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.04049 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %29, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %22 = getelementptr inbounds i8, ptr %2, i64 %.04049
  %23 = load <4 x i8>, ptr %22, align 1, !tbaa !5
  %24 = shufflevector <4 x i8> %23, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i8> %24, ptr %22, align 1, !tbaa !5
  %25 = or disjoint i64 %.04049, 4
  %26 = getelementptr inbounds i8, ptr %2, i64 %25
  %27 = load <4 x i8>, ptr %26, align 1, !tbaa !5
  %28 = shufflevector <4 x i8> %27, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i8> %28, ptr %26, align 1, !tbaa !5
  %29 = add nuw i64 %.04049, 8
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !8

.loopexit.sink.split:                             ; preds = %7, %6, %5, %4
  %.sink = phi i64 [ 114, %4 ], [ 115, %5 ], [ 116, %6 ], [ 117, %7 ]
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef %.sink, i32 noundef 2, ptr noundef null) #4
  br label %.loopexit

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %.04049.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %29, %.lr.ph ]
  %30 = and i64 %18, 4
  %lcmp.mod.not.not = icmp eq i64 %30, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph.epil, label %.loopexit

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa
  %31 = getelementptr inbounds i8, ptr %2, i64 %.04049.unr
  %32 = load <4 x i8>, ptr %31, align 1, !tbaa !5
  %33 = shufflevector <4 x i8> %32, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i8> %33, ptr %31, align 1, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %.loopexit.loopexit.unr-lcssa, %.loopexit.sink.split, %14
  %.0 = phi i32 [ 0, %14 ], [ 2, %.loopexit.sink.split ], [ 0, %.loopexit.loopexit.unr-lcssa ], [ 0, %.lr.ph.epil ]
  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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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