; LLVM IR from boschglobal/dse.network :: dse/network/examples/stub (stub)

; 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.stub_example_message_t = type { i8, i8, i16 }

; Function Attrs: nounwind uwtable
define dso_local i32 @stub_example_message_pack(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 8
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 -22, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %68

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %15, i8 0, i64 8, i1 false)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.stub_example_message_t, ptr %16, i32 0, i32 0
  %18 = load i8, ptr %17, align 2, !tbaa !11
  %19 = call zeroext i8 @pack_left_shift_u8(i8 noundef zeroext %18, i8 noundef zeroext 7, i8 noundef zeroext -128)
  %20 = zext i8 %19 to i32
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 0
  %23 = load i8, ptr %22, align 1, !tbaa !14
  %24 = zext i8 %23 to i32
  %25 = or i32 %24, %20
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %22, align 1, !tbaa !14
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.stub_example_message_t, ptr %27, i32 0, i32 1
  %29 = load i8, ptr %28, align 1, !tbaa !15
  %30 = call zeroext i8 @pack_left_shift_u8(i8 noundef zeroext %29, i8 noundef zeroext 1, i8 noundef zeroext 126)
  %31 = zext i8 %30 to i32
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 0
  %34 = load i8, ptr %33, align 1, !tbaa !14
  %35 = zext i8 %34 to i32
  %36 = or i32 %35, %31
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr %33, align 1, !tbaa !14
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.stub_example_message_t, ptr %38, i32 0, i32 2
  %40 = load i16, ptr %39, align 2, !tbaa !16
  store i16 %40, ptr %8, align 2, !tbaa !17
  %41 = load i16, ptr %8, align 2, !tbaa !17
  %42 = call zeroext i8 @pack_right_shift_u16(i16 noundef zeroext %41, i8 noundef zeroext 11, i8 noundef zeroext 1)
  %43 = zext i8 %42 to i32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 0
  %46 = load i8, ptr %45, align 1, !tbaa !14
  %47 = zext i8 %46 to i32
  %48 = or i32 %47, %43
  %49 = trunc i32 %48 to i8
  store i8 %49, ptr %45, align 1, !tbaa !14
  %50 = load i16, ptr %8, align 2, !tbaa !17
  %51 = call zeroext i8 @pack_right_shift_u16(i16 noundef zeroext %50, i8 noundef zeroext 3, i8 noundef zeroext -1)
  %52 = zext i8 %51 to i32
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 1
  %55 = load i8, ptr %54, align 1, !tbaa !14
  %56 = zext i8 %55 to i32
  %57 = or i32 %56, %52
  %58 = trunc i32 %57 to i8
  store i8 %58, ptr %54, align 1, !tbaa !14
  %59 = load i16, ptr %8, align 2, !tbaa !17
  %60 = call zeroext i8 @pack_left_shift_u16(i16 noundef zeroext %59, i8 noundef zeroext 5, i8 noundef zeroext -32)
  %61 = zext i8 %60 to i32
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 2
  %64 = load i8, ptr %63, align 1, !tbaa !14
  %65 = zext i8 %64 to i32
  %66 = or i32 %65, %61
  %67 = trunc i32 %66 to i8
  store i8 %67, ptr %63, align 1, !tbaa !14
  store i32 8, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %68

68:                                               ; preds = %13, %12
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @pack_left_shift_u8(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @pack_right_shift_u16(i16 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @pack_left_shift_u16(i16 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #3

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint 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 = !{!"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, !7, i64 0}
!12 = !{!"stub_example_message_t", !7, i64 0, !7, i64 1, !13, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !7, i64 1}
!16 = !{!12, !13, i64 2}
!17 = !{!13, !13, 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
define dso_local range(i32 -22, 9) i32 @stub_example_message_pack(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ult i64 %2, 8
  br i1 %4, label %28, label %5

5:                                                ; preds = %3
  store i64 0, ptr %0, align 1
  %6 = load i8, ptr %1, align 2, !tbaa !5
  %7 = tail call zeroext i8 @pack_left_shift_u8(i8 noundef zeroext %6, i8 noundef zeroext 7, i8 noundef zeroext -128)
  %8 = load i8, ptr %0, align 1, !tbaa !10
  %9 = or i8 %8, %7
  store i8 %9, ptr %0, align 1, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %1, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = tail call zeroext i8 @pack_left_shift_u8(i8 noundef zeroext %11, i8 noundef zeroext 1, i8 noundef zeroext 126)
  %13 = load i8, ptr %0, align 1, !tbaa !10
  %14 = or i8 %13, %12
  store i8 %14, ptr %0, align 1, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %1, i64 2
  %16 = load i16, ptr %15, align 2, !tbaa !12
  %17 = tail call zeroext i8 @pack_right_shift_u16(i16 noundef zeroext %16, i8 noundef zeroext 11, i8 noundef zeroext 1)
  %18 = load i8, ptr %0, align 1, !tbaa !10
  %19 = or i8 %18, %17
  store i8 %19, ptr %0, align 1, !tbaa !10
  %20 = tail call zeroext i8 @pack_right_shift_u16(i16 noundef zeroext %16, i8 noundef zeroext 3, i8 noundef zeroext -1)
  %21 = getelementptr inbounds i8, ptr %0, i64 1
  %22 = load i8, ptr %21, align 1, !tbaa !10
  %23 = or i8 %22, %20
  store i8 %23, ptr %21, align 1, !tbaa !10
  %24 = tail call zeroext i8 @pack_left_shift_u16(i16 noundef zeroext %16, i8 noundef zeroext 5, i8 noundef zeroext -32)
  %25 = getelementptr inbounds i8, ptr %0, i64 2
  %26 = load i8, ptr %25, align 1, !tbaa !10
  %27 = or i8 %26, %24
  store i8 %27, ptr %25, align 1, !tbaa !10
  br label %28

28:                                               ; preds = %3, %5
  %.0 = phi i32 [ 8, %5 ], [ -22, %3 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @pack_left_shift_u8(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @pack_right_shift_u16(i16 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @pack_left_shift_u16(i16 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

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 = { inlinehint 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" }

!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 = !{!"stub_example_message_t", !7, i64 0, !7, i64 1, !9, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 1}
!12 = !{!6, !9, i64 2}


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