; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/response.ll (ZN3qOS8response8receivedEPKcmm)

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

%"class.qOS::response" = type <{ ptr, ptr, %"class.qOS::timer", i64, i64, i64, i8, [7 x i8] }>
%"class.qOS::timer" = type { ptr, i64, i64 }

@_ZN3qOS5clock9IMMEDIATEE = external constant i64, align 8

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS8response5resetEv(ptr noundef nonnull align 8 dereferenceable(65)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qOS8response8receivedEPKcmm(ptr noundef nonnull align 8 dereferenceable(65) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %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
  store i64 %3, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  %11 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 6
  %12 = load volatile i8, ptr %11, align 8, !tbaa !13, !range !17, !noundef !18
  %13 = trunc i8 %12 to i1
  br i1 %13, label %47, label %14

14:                                               ; preds = %4
  %15 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 4
  %16 = load i64, ptr %15, align 8, !tbaa !19
  %17 = icmp eq i64 0, %16
  br i1 %17, label %18, label %47

18:                                               ; preds = %14
  %19 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !20
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 3
  %23 = load i64, ptr %22, align 8, !tbaa !21
  %24 = call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef %20, ptr noundef %21, i64 noundef %23) #3
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = icmp eq i64 0, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %18
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !21
  %31 = call noundef i64 @_ZN3qOS4util6strlenEPKcm(ptr noundef %28, i64 noundef %30) #3
  br label %34

32:                                               ; preds = %18
  %33 = load i64, ptr %7, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %32, %27
  %35 = phi i64 [ %31, %27 ], [ %33, %32 ]
  %36 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 4
  store i64 %35, ptr %36, align 8, !tbaa !19
  %37 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 5
  store volatile i64 0, ptr %37, align 8, !tbaa !22
  %38 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 6
  store volatile i8 0, ptr %38, align 8, !tbaa !13
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = load i64, ptr @_ZN3qOS5clock9IMMEDIATEE, align 8, !tbaa !9
  %41 = icmp ugt i64 %39, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %34
  %43 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 2
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = call noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24) %43, i64 noundef %44) #3
  br label %46

46:                                               ; preds = %42, %34
  br label %59

47:                                               ; preds = %14, %4
  %48 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 2
  %49 = call noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24) %48) #3
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  call void @_ZN3qOS8response5resetEv(ptr noundef nonnull align 8 dereferenceable(65) %10) #3
  store i32 2, ptr %9, align 4, !tbaa !11
  br label %58

51:                                               ; preds = %47
  %52 = getelementptr inbounds %"class.qOS::response", ptr %10, i32 0, i32 6
  %53 = load volatile i8, ptr %52, align 8, !tbaa !13, !range !17, !noundef !18
  %54 = trunc i8 %53 to i1
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  call void @_ZN3qOS8response5resetEv(ptr noundef nonnull align 8 dereferenceable(65) %10) #3
  store i32 1, ptr %9, align 4, !tbaa !11
  br label %57

56:                                               ; preds = %51
  br label %57

57:                                               ; preds = %56, %55
  br label %58

58:                                               ; preds = %57, %50
  br label %59

59:                                               ; preds = %58, %46
  %60 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %60
}

; Function Attrs: nounwind
declare noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare noundef i64 @_ZN3qOS4util6strlenEPKcm(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN3qOS14responseStatusE", !7, i64 0}
!13 = !{!14, !16, i64 64}
!14 = !{!"_ZTSN3qOS8responseE", !6, i64 8, !15, i64 16, !10, i64 40, !10, i64 48, !10, i64 56, !16, i64 64}
!15 = !{!"_ZTSN3qOS5timerE", !10, i64 8, !10, i64 16}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!14, !10, i64 48}
!20 = !{!14, !6, i64 8}
!21 = !{!14, !10, i64 40}
!22 = !{!14, !10, i64 56}


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

@_ZN3qOS5clock9IMMEDIATEE = external local_unnamed_addr constant i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS8response5resetEv(ptr noundef nonnull align 8 dereferenceable(65)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 3) i32 @_ZN3qOS8response8receivedEPKcmm(ptr noundef nonnull align 8 dereferenceable(65) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load volatile i8, ptr %5, align 8, !tbaa !5, !range !13, !noundef !14
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %30, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = load i64, ptr %9, align 8, !tbaa !15
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %30

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load i64, ptr %15, align 8, !tbaa !17
  %17 = tail call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef %14, ptr noundef %1, i64 noundef %16) #2
  %18 = icmp eq i64 %2, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %12
  %20 = load i64, ptr %15, align 8, !tbaa !17
  %21 = tail call noundef i64 @_ZN3qOS4util6strlenEPKcm(ptr noundef %1, i64 noundef %20) #2
  br label %22

22:                                               ; preds = %12, %19
  %23 = phi i64 [ %21, %19 ], [ %2, %12 ]
  store i64 %23, ptr %9, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  store volatile i64 0, ptr %24, align 8, !tbaa !18
  store volatile i8 0, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr @_ZN3qOS5clock9IMMEDIATEE, align 8, !tbaa !19
  %26 = icmp ult i64 %25, %3
  br i1 %26, label %27, label %38

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = tail call noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %3) #2
  br label %38

30:                                               ; preds = %8, %4
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = tail call noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24) %31) #2
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  tail call void @_ZN3qOS8response5resetEv(ptr noundef nonnull align 8 dereferenceable(65) %0) #2
  br label %38

34:                                               ; preds = %30
  %35 = load volatile i8, ptr %5, align 8, !tbaa !5, !range !13, !noundef !14
  %36 = trunc nuw i8 %35 to i1
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  tail call void @_ZN3qOS8response5resetEv(ptr noundef nonnull align 8 dereferenceable(65) %0) #2
  br label %38

38:                                               ; preds = %33, %34, %37, %22, %27
  %.0 = phi i32 [ 2, %33 ], [ 1, %37 ], [ 0, %34 ], [ 0, %27 ], [ 0, %22 ]
  ret i32 %.0
}

; Function Attrs: nounwind
declare noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef i64 @_ZN3qOS4util6strlenEPKcm(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

attributes #0 = { mustprogress 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 "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 }

!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, !12, i64 64}
!6 = !{!"_ZTSN3qOS8responseE", !7, i64 8, !10, i64 16, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3qOS5timerE", !11, i64 8, !11, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !11, i64 48}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !11, i64 40}
!18 = !{!6, !11, i64 56}
!19 = !{!11, !11, i64 0}


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