; LLVM IR from vul337/PrIntFuzz :: config/linux/firmware/carl9170fw/tools/lib (carlfw)

; 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.carlfw_list_entry = type { %struct.carlfw_list_entry_head, %union.anon }
%struct.carlfw_list_entry_head = type { %struct.list_head }
%struct.list_head = type { ptr, ptr }
%union.anon = type { [0 x i32], [8 x i8] }
%struct.carl9170fw_desc_head = type { [4 x i8], i16, i8, i8 }
%struct.carlfw = type { %struct.carlfw_file, %struct.carlfw_file, %struct.list_head, i32, i32 }
%struct.carlfw_file = type { ptr, i64, ptr }

; 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: inlinehint nounwind uwtable
declare hidden ptr @carlfw_entry_to_desc(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @carlfw_desc_to_entry(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @carlfw_desc_mod_len(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.carlfw_list_entry, align 8
  %10 = alloca i32, align 4
  %11 = 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 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.carl9170fw_desc_head, ptr %12, i32 0, i32 1
  %14 = load i16, ptr %13, align 1, !tbaa !11
  %15 = zext i16 %14 to i64
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = add i64 %15, %16
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %10, align 4, !tbaa !14
  %19 = load i32, ptr %10, align 4, !tbaa !14
  %20 = icmp slt i32 %19, 8
  br i1 %20, label %21, label %23

21:                                               ; preds = %3
  %22 = call ptr @ERR_PTR(i64 noundef -22)
  store ptr %22, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %61

23:                                               ; preds = %3
  %24 = load i32, ptr %10, align 4, !tbaa !14
  %25 = icmp sgt i32 %24, 8192
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = call ptr @ERR_PTR(i64 noundef -7)
  store ptr %27, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %61

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call ptr @carlfw_desc_to_entry(ptr noundef %29)
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %31, i64 24, i1 false)
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %10, align 4, !tbaa !14
  %34 = sext i32 %33 to i64
  %35 = add i64 %34, 16
  %36 = call ptr @realloc(ptr noundef %32, i64 noundef %35) #6
  store ptr %36, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %41

39:                                               ; preds = %28
  %40 = call ptr @ERR_PTR(i64 noundef -12)
  store ptr %40, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %61

41:                                               ; preds = %28
  %42 = getelementptr inbounds %struct.carlfw_list_entry, ptr %9, i32 0, i32 0
  %43 = getelementptr inbounds %struct.carlfw_list_entry_head, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.carlfw_list_entry, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.carlfw_list_entry_head, ptr %45, i32 0, i32 0
  call void @list_replace(ptr noundef %43, ptr noundef %46)
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = call ptr @carlfw_entry_to_desc(ptr noundef %47)
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !14
  %50 = trunc i32 %49 to i16
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.carl9170fw_desc_head, ptr %51, i32 0, i32 1
  store i16 %50, ptr %52, align 1, !tbaa !11
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.carlfw, ptr %54, i32 0, i32 4
  %56 = load i32, ptr %55, align 4, !tbaa !16
  %57 = zext i32 %56 to i64
  %58 = add i64 %57, %53
  %59 = trunc i64 %58 to i32
  store i32 %59, ptr %55, align 4, !tbaa !16
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %60, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %61

61:                                               ; preds = %41, %39, %26, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %62 = load ptr, ptr %4, align 8
  ret ptr %62
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ERR_PTR(i64 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) #3

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_replace(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!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, !13, i64 4}
!12 = !{!"carl9170fw_desc_head", !7, i64 0, !13, i64 4, !7, i64 6, !7, i64 7}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !15, i64 68}
!17 = !{!"carlfw", !18, i64 0, !18, i64 24, !19, i64 48, !15, i64 64, !15, i64 68}
!18 = !{!"carlfw_file", !6, i64 0, !10, i64 8, !6, i64 16}
!19 = !{!"list_head", !6, i64 0, !6, i64 8}


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

%struct.carlfw_list_entry = type { %struct.carlfw_list_entry_head, %union.anon }
%struct.carlfw_list_entry_head = type { %struct.list_head }
%struct.list_head = type { ptr, ptr }
%union.anon = type { [0 x i32], [8 x i8] }

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @carlfw_desc_mod_len(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.carlfw_list_entry, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i16, ptr %5, align 1, !tbaa !5
  %7 = zext i16 %6 to i64
  %8 = add i64 %7, %2
  %9 = trunc i64 %8 to i32
  %10 = icmp slt i32 %9, 8
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = tail call ptr @ERR_PTR(i64 noundef -22)
  br label %33

13:                                               ; preds = %3
  %14 = icmp ugt i32 %9, 8192
  br i1 %14, label %15, label %17

15:                                               ; preds = %13
  %16 = tail call ptr @ERR_PTR(i64 noundef -7)
  br label %33

17:                                               ; preds = %13
  %18 = tail call ptr @carlfw_desc_to_entry(ptr noundef nonnull %1)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %18, i64 24, i1 false)
  %19 = and i64 %8, 16383
  %20 = add nuw nsw i64 %19, 16
  %21 = tail call ptr @realloc(ptr noundef %18, i64 noundef %20) #6
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %17
  %24 = tail call ptr @ERR_PTR(i64 noundef -12)
  br label %33

25:                                               ; preds = %17
  call void @list_replace(ptr noundef nonnull %4, ptr noundef nonnull %21)
  %26 = call ptr @carlfw_entry_to_desc(ptr noundef nonnull %21)
  %27 = trunc i64 %8 to i16
  %28 = getelementptr inbounds i8, ptr %26, i64 4
  store i16 %27, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 68
  %30 = load i32, ptr %29, align 4, !tbaa !10
  %31 = trunc i64 %2 to i32
  %32 = add i32 %30, %31
  store i32 %32, ptr %29, align 4, !tbaa !10
  br label %33

33:                                               ; preds = %25, %23, %15, %11
  %.0 = phi ptr [ %12, %11 ], [ %16, %15 ], [ %24, %23 ], [ %26, %25 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  ret ptr %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ERR_PTR(i64 noundef) local_unnamed_addr #1

; 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) #3

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #4

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #6 = { nounwind allocsize(1) }

!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, !9, i64 4}
!6 = !{!"carl9170fw_desc_head", !7, i64 0, !9, i64 4, !7, i64 6, !7, i64 7}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!11, !16, i64 68}
!11 = !{!"carlfw", !12, i64 0, !12, i64 24, !15, i64 48, !16, i64 64, !16, i64 68}
!12 = !{!"carlfw_file", !13, i64 0, !14, i64 8, !13, i64 16}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"list_head", !13, i64 0, !13, i64 8}
!16 = !{!"int", !7, i64 0}


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