; LLVM IR from NTHU-LSALAB/Gemini :: src/pod-manager.ll (Z16hook_thread_funcPv)

; 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.std::map.3" = type { %"class.std::_Rb_tree.4" }
%"class.std::_Rb_tree.4" = type { %"struct.std::_Rb_tree<int, std::pair<const int, unsigned long>, std::_Select1st<std::pair<const int, unsigned long>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, unsigned long>, std::_Select1st<std::pair<const int, unsigned long>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::map.8" = type { %"class.std::_Rb_tree.9" }
%"class.std::_Rb_tree.9" = type { %"struct.std::_Rb_tree<int, std::pair<const int, double>, std::_Select1st<std::pair<const int, double>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, double>, std::_Select1st<std::pair<const int, double>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }

@gpu_mem_limit = external dso_local global i64, align 8
@gpu_mem_used = external dso_local global i64, align 8
@allocation_map = external dso_local global %"class.std::map.3", align 8
@mem_info_mutex = external dso_local global %union.pthread_mutex_t, align 8
@client_burst_map = external dso_local global %"class.std::map.8", align 8
@client_stat_mutex = external dso_local global %union.pthread_mutex_t, align 8
@.str.16 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [46 x i8], align 1

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

; 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
declare dso_local noundef i64 @_Z12get_msg_dataImET_PcRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

declare void @_Z4INFOPKcz(ptr noundef, ...) #3

declare void @_Z5ERRORPKcz(ptr noundef, ...) #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #4

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z16hook_thread_funcPv(ptr noundef %0) #5 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [80 x i8], align 16
  %5 = alloca [40 x i8], align 16
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void (ptr, ...) @_Z5DEBUGPKcz(ptr noundef @.str.18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %19, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 80, ptr %4) #8
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #8
  br label %20

20:                                               ; preds = %81, %1
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = getelementptr inbounds [80 x i8], ptr %4, i64 0, i64 0
  %23 = call i64 @recv(i32 noundef %21, ptr noundef %22, i64 noundef 80, i32 noundef 0)
  store i64 %23, ptr %6, align 8, !tbaa !11
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %25, label %82

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  store i64 0, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  store i64 0, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  %26 = getelementptr inbounds [80 x i8], ptr %4, i64 0, i64 0
  %27 = call noundef ptr @_Z13parse_requestPcPS_PmPiP14comm_request_t(ptr noundef %26, ptr noundef null, ptr noundef null, ptr noundef %8, ptr noundef %7)
  store ptr %27, ptr %11, align 8, !tbaa !5
  %28 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %28, i8 0, i64 40, i1 false)
  %29 = load i32, ptr %7, align 4, !tbaa !13
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %37

31:                                               ; preds = %25
  %32 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load i64, ptr @gpu_mem_used, align 8, !tbaa !11
  %35 = load i64, ptr @gpu_mem_limit, align 8, !tbaa !11
  %36 = call noundef i64 (ptr, i32, i32, ...) @_Z16prepare_responsePc14comm_request_tiz(ptr noundef %32, i32 noundef 1, i32 noundef %33, i64 noundef %34, i64 noundef %35)
  store i64 %36, ptr %10, align 8, !tbaa !11
  br label %71

37:                                               ; preds = %25
  %38 = load i32, ptr %7, align 4, !tbaa !13
  %39 = icmp eq i32 %38, 2
  br i1 %39, label %40, label %53

40:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = call noundef i64 @_Z12get_msg_dataImET_PcRm(ptr noundef %41, ptr noundef nonnull align 8 dereferenceable(8) %9)
  store i64 %42, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = call noundef i32 @_Z12get_msg_dataIiET_PcRm(ptr noundef %43, ptr noundef nonnull align 8 dereferenceable(8) %9)
  store i32 %44, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  %45 = load i64, ptr %12, align 8, !tbaa !11
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = call noundef i32 @_Z24hook_update_memory_usagemii(i64 noundef %45, i32 noundef %46, i32 noundef %47)
  store i32 %48, ptr %14, align 4, !tbaa !9
  %49 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load i32, ptr %14, align 4, !tbaa !9
  %52 = call noundef i64 (ptr, i32, i32, ...) @_Z16prepare_responsePc14comm_request_tiz(ptr noundef %49, i32 noundef 2, i32 noundef %50, i32 noundef %51)
  store i64 %52, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  br label %70

53:                                               ; preds = %37
  %54 = load i32, ptr %7, align 4, !tbaa !13
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %69

56:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #8
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = call noundef double @_Z12get_msg_dataIdET_PcRm(ptr noundef %57, ptr noundef nonnull align 8 dereferenceable(8) %9)
  store double %58, ptr %15, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #8
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = call noundef double @_Z12get_msg_dataIdET_PcRm(ptr noundef %59, ptr noundef nonnull align 8 dereferenceable(8) %9)
  store double %60, ptr %16, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #8
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = load double, ptr %15, align 8, !tbaa !15
  %63 = load double, ptr %16, align 8, !tbaa !15
  %64 = call noundef double @_Z18hook_kernel_launchidd(i32 noundef %61, double noundef %62, double noundef %63)
  store double %64, ptr %17, align 8, !tbaa !15
  %65 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = load double, ptr %17, align 8, !tbaa !15
  %68 = call noundef i64 (ptr, i32, i32, ...) @_Z16prepare_responsePc14comm_request_tiz(ptr noundef %65, i32 noundef 0, i32 noundef %66, double noundef %67)
  store i64 %68, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #8
  br label %69

69:                                               ; preds = %56, %53
  br label %70

70:                                               ; preds = %69, %40
  br label %71

71:                                               ; preds = %70, %31
  %72 = load i64, ptr %10, align 8, !tbaa !11
  %73 = icmp ugt i64 %72, 0
  br i1 %73, label %74, label %81

74:                                               ; preds = %71
  %75 = load i32, ptr %3, align 4, !tbaa !9
  %76 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  %77 = call i64 @send(i32 noundef %75, ptr noundef %76, i64 noundef 40, i32 noundef 0)
  %78 = icmp eq i64 %77, -1
  br i1 %78, label %79, label %80

79:                                               ; preds = %74
  call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef @.str.19)
  br label %80

80:                                               ; preds = %79, %74
  br label %81

81:                                               ; preds = %80, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %20, !llvm.loop !17

82:                                               ; preds = %20
  %83 = load i64, ptr %6, align 8, !tbaa !11
  call void (ptr, ...) @_Z4INFOPKcz(ptr noundef @.str.20, i64 noundef %83)
  %84 = call i32 @pthread_mutex_lock(ptr noundef @mem_info_mutex) #8
  %85 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @allocation_map, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %86 = load i64, ptr %85, align 8, !tbaa !11
  %87 = load i64, ptr @gpu_mem_used, align 8, !tbaa !11
  %88 = sub i64 %87, %86
  store i64 %88, ptr @gpu_mem_used, align 8, !tbaa !11
  %89 = call noundef i64 @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48) @allocation_map, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %90 = load i64, ptr @gpu_mem_used, align 8, !tbaa !11
  call void (ptr, ...) @_Z5DEBUGPKcz(ptr noundef @.str.16, i64 noundef %90)
  %91 = call i32 @pthread_mutex_unlock(ptr noundef @mem_info_mutex) #8
  %92 = call i32 @pthread_mutex_lock(ptr noundef @client_stat_mutex) #8
  %93 = call noundef i64 @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48) @client_burst_map, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %94 = call i32 @pthread_mutex_unlock(ptr noundef @client_stat_mutex) #8
  %95 = load i32, ptr %3, align 4, !tbaa !9
  %96 = call i32 @close(i32 noundef %95)
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = icmp eq ptr %97, null
  br i1 %98, label %100, label %99

99:                                               ; preds = %82
  call void @_ZdlPvm(ptr noundef %97, i64 noundef 4) #9
  br label %100

100:                                              ; preds = %99, %82
  call void @pthread_exit(ptr noundef null) #10
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z24hook_update_memory_usagemii(i64 noundef, i32 noundef, i32 noundef) #5

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

declare void @_Z5DEBUGPKcz(ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z18hook_kernel_launchidd(i32 noundef, double noundef, double noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z12get_msg_dataIdET_PcRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #6

declare i64 @recv(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #3

declare noundef ptr @_Z13parse_requestPcPS_PmPiP14comm_request_t(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare noundef i64 @_Z16prepare_responsePc14comm_request_tiz(ptr noundef, i32 noundef, i32 noundef, ...) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z12get_msg_dataIiET_PcRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

declare i32 @close(i32 noundef) #3

; Function Attrs: noreturn
declare void @pthread_exit(ptr noundef) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { "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 "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 = { mustprogress 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 #6 = { nobuiltin 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 #7 = { noreturn "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 #8 = { nounwind }
attributes #9 = { builtin nounwind }
attributes #10 = { noreturn }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS14comm_request_t", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

%"class.std::map.3" = type { %"class.std::_Rb_tree.4" }
%"class.std::_Rb_tree.4" = type { %"struct.std::_Rb_tree<int, std::pair<const int, unsigned long>, std::_Select1st<std::pair<const int, unsigned long>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, unsigned long>, std::_Select1st<std::pair<const int, unsigned long>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::map.8" = type { %"class.std::_Rb_tree.9" }
%"class.std::_Rb_tree.9" = type { %"struct.std::_Rb_tree<int, std::pair<const int, double>, std::_Select1st<std::pair<const int, double>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, double>, std::_Select1st<std::pair<const int, double>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }

@gpu_mem_limit = external dso_local local_unnamed_addr global i64, align 8
@gpu_mem_used = external dso_local local_unnamed_addr global i64, align 8
@allocation_map = external dso_local global %"class.std::map.3", align 8
@mem_info_mutex = external dso_local global %union.pthread_mutex_t, align 8
@client_burst_map = external dso_local global %"class.std::map.8", align 8
@client_stat_mutex = external dso_local global %union.pthread_mutex_t, align 8
@.str.16 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [46 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z12get_msg_dataImET_PcRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

declare void @_Z4INFOPKcz(ptr noundef, ...) local_unnamed_addr #3

declare void @_Z5ERRORPKcz(ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress noreturn uwtable
define dso_local noalias noundef nonnull ptr @_Z16hook_thread_funcPv(ptr noundef %0) local_unnamed_addr #5 {
  %2 = alloca i32, align 4
  %3 = alloca [80 x i8], align 16
  %4 = alloca [40 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  tail call void (ptr, ...) @_Z5DEBUGPKcz(ptr noundef nonnull @.str.18)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #9
  %8 = load i32, ptr %0, align 4, !tbaa !5
  store i32 %8, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #9
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #9
  %9 = call i64 @recv(i32 noundef %8, ptr noundef nonnull %3, i64 noundef 80, i32 noundef 0)
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.thread
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #9
  store i64 0, ptr %7, align 8, !tbaa !9
  %11 = call noundef ptr @_Z13parse_requestPcPS_PmPiP14comm_request_t(ptr noundef nonnull %3, ptr noundef null, ptr noundef null, ptr noundef nonnull %6, ptr noundef nonnull %5)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %4, i8 0, i64 40, i1 false)
  %12 = load i32, ptr %5, align 4, !tbaa !11
  switch i32 %12, label %.thread [
    i32 1, label %13
    i32 2, label %18
    i32 0, label %24
  ]

13:                                               ; preds = %.lr.ph
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i64, ptr @gpu_mem_used, align 8, !tbaa !9
  %16 = load i64, ptr @gpu_mem_limit, align 8, !tbaa !9
  %17 = call noundef i64 (ptr, i32, i32, ...) @_Z16prepare_responsePc14comm_request_tiz(ptr noundef nonnull %4, i32 noundef 1, i32 noundef %14, i64 noundef %15, i64 noundef %16)
  br label %30

18:                                               ; preds = %.lr.ph
  %19 = call noundef i64 @_Z12get_msg_dataImET_PcRm(ptr noundef %11, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %20 = call noundef i32 @_Z12get_msg_dataIiET_PcRm(ptr noundef %11, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %21 = call noundef i32 @_Z24hook_update_memory_usagemii(i64 noundef %19, i32 noundef %20, i32 noundef %8)
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = call noundef i64 (ptr, i32, i32, ...) @_Z16prepare_responsePc14comm_request_tiz(ptr noundef nonnull %4, i32 noundef 2, i32 noundef %22, i32 noundef %21)
  br label %30

24:                                               ; preds = %.lr.ph
  %25 = call noundef double @_Z12get_msg_dataIdET_PcRm(ptr noundef %11, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %26 = call noundef double @_Z12get_msg_dataIdET_PcRm(ptr noundef %11, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %27 = call noundef double @_Z18hook_kernel_launchidd(i32 noundef %8, double noundef %25, double noundef %26)
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = call noundef i64 (ptr, i32, i32, ...) @_Z16prepare_responsePc14comm_request_tiz(ptr noundef nonnull %4, i32 noundef 0, i32 noundef %28, double noundef %27)
  br label %30

30:                                               ; preds = %18, %24, %13
  %.0 = phi i64 [ %17, %13 ], [ %23, %18 ], [ %29, %24 ]
  %.not = icmp eq i64 %.0, 0
  br i1 %.not, label %.thread, label %31

31:                                               ; preds = %30
  %32 = call i64 @send(i32 noundef %8, ptr noundef nonnull %4, i64 noundef 40, i32 noundef 0)
  %33 = icmp eq i64 %32, -1
  br i1 %33, label %34, label %.thread

34:                                               ; preds = %31
  call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef nonnull @.str.19)
  br label %.thread

.thread:                                          ; preds = %.lr.ph, %31, %34, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #9
  %35 = call i64 @recv(i32 noundef %8, ptr noundef nonnull %3, i64 noundef 80, i32 noundef 0)
  %36 = icmp sgt i64 %35, 0
  br i1 %36, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.thread, %1
  %.lcssa = phi i64 [ %9, %1 ], [ %35, %.thread ]
  call void (ptr, ...) @_Z4INFOPKcz(ptr noundef nonnull @.str.20, i64 noundef %.lcssa)
  %37 = call i32 @pthread_mutex_lock(ptr noundef nonnull @mem_info_mutex) #9
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @allocation_map, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = load i64, ptr @gpu_mem_used, align 8, !tbaa !9
  %41 = sub i64 %40, %39
  store i64 %41, ptr @gpu_mem_used, align 8, !tbaa !9
  %42 = call noundef i64 @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48) @allocation_map, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %43 = load i64, ptr @gpu_mem_used, align 8, !tbaa !9
  call void (ptr, ...) @_Z5DEBUGPKcz(ptr noundef nonnull @.str.16, i64 noundef %43)
  %44 = call i32 @pthread_mutex_unlock(ptr noundef nonnull @mem_info_mutex) #9
  %45 = call i32 @pthread_mutex_lock(ptr noundef nonnull @client_stat_mutex) #9
  %46 = call noundef i64 @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48) @client_burst_map, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %47 = call i32 @pthread_mutex_unlock(ptr noundef nonnull @client_stat_mutex) #9
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = call i32 @close(i32 noundef %48)
  call void @_ZdlPvm(ptr noundef %0, i64 noundef 4) #10
  call void @pthread_exit(ptr noundef null) #11
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z24hook_update_memory_usagemii(i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6 align 2

declare void @_Z5DEBUGPKcz(ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z18hook_kernel_launchidd(i32 noundef, double noundef, double noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z12get_msg_dataIdET_PcRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #7

declare i64 @recv(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

declare noundef ptr @_Z13parse_requestPcPS_PmPiP14comm_request_t(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare noundef i64 @_Z16prepare_responsePc14comm_request_tiz(ptr noundef, i32 noundef, i32 noundef, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z12get_msg_dataIiET_PcRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNSt3mapIimSt4lessIiESaISt4pairIKimEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEE5eraseERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6 align 2

declare i32 @close(i32 noundef) local_unnamed_addr #3

; Function Attrs: noreturn
declare void @pthread_exit(ptr noundef) local_unnamed_addr #8

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { "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 "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 = { mustprogress noreturn 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 #6 = { mustprogress 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 #7 = { nobuiltin 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 #8 = { noreturn "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 #9 = { nounwind }
attributes #10 = { builtin nounwind }
attributes #11 = { noreturn }

!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 = !{!"int", !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 = !{!"_ZTS14comm_request_t", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass