; 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: 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 @stub_example_message_unpack(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %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) #3
  %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 %61

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = call zeroext i8 @unpack_right_shift_u8(i8 noundef zeroext %16, i8 noundef zeroext 7, i8 noundef zeroext -128)
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.stub_example_message_t, ptr %18, i32 0, i32 0
  store i8 %17, ptr %19, align 2, !tbaa !12
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 0
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = call zeroext i8 @unpack_right_shift_u8(i8 noundef zeroext %22, i8 noundef zeroext 1, i8 noundef zeroext 126)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.stub_example_message_t, ptr %24, i32 0, i32 1
  store i8 %23, ptr %25, align 1, !tbaa !15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 0
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = call zeroext i16 @unpack_left_shift_u16(i8 noundef zeroext %28, i8 noundef zeroext 11, i8 noundef zeroext 1)
  store i16 %29, ptr %8, align 2, !tbaa !16
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 1
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = call zeroext i16 @unpack_left_shift_u16(i8 noundef zeroext %32, i8 noundef zeroext 3, i8 noundef zeroext -1)
  %34 = zext i16 %33 to i32
  %35 = load i16, ptr %8, align 2, !tbaa !16
  %36 = zext i16 %35 to i32
  %37 = or i32 %36, %34
  %38 = trunc i32 %37 to i16
  store i16 %38, ptr %8, align 2, !tbaa !16
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 2
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = call zeroext i16 @unpack_right_shift_u16(i8 noundef zeroext %41, i8 noundef zeroext 5, i8 noundef zeroext -32)
  %43 = zext i16 %42 to i32
  %44 = load i16, ptr %8, align 2, !tbaa !16
  %45 = zext i16 %44 to i32
  %46 = or i32 %45, %43
  %47 = trunc i32 %46 to i16
  store i16 %47, ptr %8, align 2, !tbaa !16
  %48 = load i16, ptr %8, align 2, !tbaa !16
  %49 = zext i16 %48 to i32
  %50 = and i32 %49, 2048
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %57

52:                                               ; preds = %13
  %53 = load i16, ptr %8, align 2, !tbaa !16
  %54 = zext i16 %53 to i32
  %55 = or i32 %54, 61440
  %56 = trunc i32 %55 to i16
  store i16 %56, ptr %8, align 2, !tbaa !16
  br label %57

57:                                               ; preds = %52, %13
  %58 = load i16, ptr %8, align 2, !tbaa !16
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.stub_example_message_t, ptr %59, i32 0, i32 2
  store i16 %58, ptr %60, align 2, !tbaa !17
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %61

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @unpack_right_shift_u16(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #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 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"stub_example_message_t", !7, i64 0, !7, i64 1, !14, i64 2}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !7, i64 1}
!16 = !{!14, !14, i64 0}
!17 = !{!13, !14, i64 2}


; 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, 1) i32 @stub_example_message_unpack(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ult i64 %2, 8
  br i1 %4, label %24, label %5

5:                                                ; preds = %3
  %6 = load i8, ptr %1, align 1, !tbaa !5
  %7 = tail call zeroext i8 @unpack_right_shift_u8(i8 noundef zeroext %6, i8 noundef zeroext 7, i8 noundef zeroext -128)
  store i8 %7, ptr %0, align 2, !tbaa !8
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %9 = tail call zeroext i8 @unpack_right_shift_u8(i8 noundef zeroext %8, i8 noundef zeroext 1, i8 noundef zeroext 126)
  %10 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %9, ptr %10, align 1, !tbaa !11
  %11 = load i8, ptr %1, align 1, !tbaa !5
  %12 = tail call zeroext i16 @unpack_left_shift_u16(i8 noundef zeroext %11, i8 noundef zeroext 11, i8 noundef zeroext 1)
  %13 = getelementptr inbounds i8, ptr %1, i64 1
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = tail call zeroext i16 @unpack_left_shift_u16(i8 noundef zeroext %14, i8 noundef zeroext 3, i8 noundef zeroext -1)
  %16 = or i16 %15, %12
  %17 = getelementptr inbounds i8, ptr %1, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = tail call zeroext i16 @unpack_right_shift_u16(i8 noundef zeroext %18, i8 noundef zeroext 5, i8 noundef zeroext -32)
  %20 = or i16 %16, %19
  %21 = and i16 %20, 2048
  %.not = icmp eq i16 %21, 0
  %22 = or i16 %20, -4096
  %spec.select = select i1 %.not, i16 %20, i16 %22
  %23 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %spec.select, ptr %23, align 2, !tbaa !12
  br label %24

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @unpack_right_shift_u16(i8 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 0}
!9 = !{!"stub_example_message_t", !6, i64 0, !6, i64 1, !10, i64 2}
!10 = !{!"short", !6, i64 0}
!11 = !{!9, !6, i64 1}
!12 = !{!9, !10, i64 2}


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