; LLVM IR from MaJerle/lwpkt :: lwpkt/src/lwpkt (lwpkt)

; 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.lwpkt = type { i32, [256 x i8], ptr, ptr, i32, ptr, i8, %struct.anon }
%struct.anon = type { i32, %struct.lwpkt_crc_t, i32, i32, i32, i32, i32, i64, i64 }
%struct.lwpkt_crc_t = type { i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @lwpkt_read(ptr noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

10:                                               ; preds = %2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %11, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %71

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @lwpkt_read(ptr noundef %13)
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 3
  br i1 %16, label %17, label %34

17:                                               ; preds = %12
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.lwpkt, ptr %19, i32 0, i32 4
  store i32 %18, ptr %20, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %17
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lwpkt, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lwpkt, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void %29(ptr noundef %30, i32 noundef 0)
  br label %31

31:                                               ; preds = %26, %21
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %69

34:                                               ; preds = %12
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %64

37:                                               ; preds = %34
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.lwpkt, ptr %39, i32 0, i32 4
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = sub i32 %38, %41
  %43 = icmp uge i32 %42, 100
  br i1 %43, label %44, label %63

44:                                               ; preds = %37
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call i32 @lwpkt_reset(ptr noundef %45)
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.lwpkt, ptr %48, i32 0, i32 4
  store i32 %47, ptr %49, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.lwpkt, ptr %51, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %60

55:                                               ; preds = %50
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lwpkt, ptr %56, i32 0, i32 5
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void %58(ptr noundef %59, i32 noundef 1)
  br label %60

60:                                               ; preds = %55, %50
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %37
  br label %68

64:                                               ; preds = %34
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.lwpkt, ptr %66, i32 0, i32 4
  store i32 %65, ptr %67, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %64, %63
  br label %69

69:                                               ; preds = %68, %33
  %70 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %70, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %71

71:                                               ; preds = %69, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %72 = load i32, ptr %3, align 4
  ret i32 %72
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @lwpkt_reset(ptr noundef) #0

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 = { 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, !10, i64 280}
!12 = !{!"lwpkt", !10, i64 0, !7, i64 4, !6, i64 264, !6, i64 272, !10, i64 280, !6, i64 288, !7, i64 296, !13, i64 304}
!13 = !{!"", !10, i64 0, !14, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !15, i64 32, !15, i64 40}
!14 = !{!"", !10, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 288}


; 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
declare dso_local i32 @lwpkt_read(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @lwpkt_process(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %21, label %4

4:                                                ; preds = %2
  %5 = tail call i32 @lwpkt_read(ptr noundef nonnull %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 280
  switch i32 %5, label %20 [
    i32 3, label %7
    i32 2, label %11
  ]

7:                                                ; preds = %4
  store i32 %1, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 288
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %.not25 = icmp eq ptr %9, null
  br i1 %.not25, label %21, label %10

10:                                               ; preds = %7
  tail call void %9(ptr noundef nonnull %0, i32 noundef 0) #1
  br label %21

11:                                               ; preds = %4
  %12 = load i32, ptr %6, align 8, !tbaa !5
  %13 = sub i32 %1, %12
  %14 = icmp ugt i32 %13, 99
  br i1 %14, label %15, label %21

15:                                               ; preds = %11
  %16 = tail call i32 @lwpkt_reset(ptr noundef nonnull %0)
  store i32 %1, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 288
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %21, label %19

19:                                               ; preds = %15
  tail call void %18(ptr noundef nonnull %0, i32 noundef 1) #1
  br label %21

20:                                               ; preds = %4
  store i32 %1, ptr %6, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %10, %7, %11, %19, %15, %20, %2
  %.0 = phi i32 [ 1, %2 ], [ %5, %20 ], [ 2, %15 ], [ 2, %19 ], [ 2, %11 ], [ 3, %7 ], [ 3, %10 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @lwpkt_reset(ptr noundef) local_unnamed_addr #0

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 = { 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 280}
!6 = !{!"lwpkt", !7, i64 0, !8, i64 4, !10, i64 264, !10, i64 272, !7, i64 280, !10, i64 288, !8, i64 296, !11, i64 304}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !7, i64 0, !12, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !13, i64 32, !13, i64 40}
!12 = !{!"", !7, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 288}


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