; LLVM IR from NTHU-LSALAB/Gemini :: src/comm.ll (Z16prepare_responsePc14comm_request_tiz)

; 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.__va_list_tag = type { i32, i32, ptr, ptr }

; 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 noundef i64 @_Z15append_msg_dataImEmPcRmT_(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #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 uwtable
define dso_local noundef i64 @_Z16prepare_responsePc14comm_request_tiz(ptr noundef %0, i32 noundef %1, i32 noundef %2, ...) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca [1 x %struct.__va_list_tag], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !11
  %11 = call noundef i64 @_Z15append_msg_dataIiEmPcRmT_(ptr noundef %9, ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef %10)
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %35

14:                                               ; preds = %3
  %15 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %15)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  %18 = getelementptr inbounds %struct.__va_list_tag, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4
  %20 = icmp ule i32 %19, 160
  br i1 %20, label %21, label %26

21:                                               ; preds = %14
  %22 = getelementptr inbounds %struct.__va_list_tag, ptr %17, i32 0, i32 3
  %23 = load ptr, ptr %22, align 16
  %24 = getelementptr i8, ptr %23, i32 %19
  %25 = add i32 %19, 16
  store i32 %25, ptr %18, align 4
  br label %30

26:                                               ; preds = %14
  %27 = getelementptr inbounds %struct.__va_list_tag, ptr %17, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8
  %29 = getelementptr i8, ptr %28, i32 8
  store ptr %29, ptr %27, align 8
  br label %30

30:                                               ; preds = %26, %21
  %31 = phi ptr [ %24, %21 ], [ %28, %26 ]
  %32 = load double, ptr %31, align 8, !tbaa !15
  %33 = call noundef i64 @_Z15append_msg_dataIdEmPcRmT_(ptr noundef %16, ptr noundef nonnull align 8 dereferenceable(8) %7, double noundef %32)
  %34 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %34)
  br label %103

35:                                               ; preds = %3
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 2
  br i1 %37, label %38, label %59

38:                                               ; preds = %35
  %39 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %39)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  %42 = getelementptr inbounds %struct.__va_list_tag, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 16
  %44 = icmp ule i32 %43, 40
  br i1 %44, label %45, label %50

45:                                               ; preds = %38
  %46 = getelementptr inbounds %struct.__va_list_tag, ptr %41, i32 0, i32 3
  %47 = load ptr, ptr %46, align 16
  %48 = getelementptr i8, ptr %47, i32 %43
  %49 = add i32 %43, 8
  store i32 %49, ptr %42, align 16
  br label %54

50:                                               ; preds = %38
  %51 = getelementptr inbounds %struct.__va_list_tag, ptr %41, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8
  %53 = getelementptr i8, ptr %52, i32 8
  store ptr %53, ptr %51, align 8
  br label %54

54:                                               ; preds = %50, %45
  %55 = phi ptr [ %48, %45 ], [ %52, %50 ]
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = call noundef i64 @_Z15append_msg_dataIiEmPcRmT_(ptr noundef %40, ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef %56)
  %58 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %58)
  br label %102

59:                                               ; preds = %35
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 1
  br i1 %61, label %62, label %101

62:                                               ; preds = %59
  %63 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %63)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  %66 = getelementptr inbounds %struct.__va_list_tag, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 16
  %68 = icmp ule i32 %67, 40
  br i1 %68, label %69, label %74

69:                                               ; preds = %62
  %70 = getelementptr inbounds %struct.__va_list_tag, ptr %65, i32 0, i32 3
  %71 = load ptr, ptr %70, align 16
  %72 = getelementptr i8, ptr %71, i32 %67
  %73 = add i32 %67, 8
  store i32 %73, ptr %66, align 16
  br label %78

74:                                               ; preds = %62
  %75 = getelementptr inbounds %struct.__va_list_tag, ptr %65, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8
  %77 = getelementptr i8, ptr %76, i32 8
  store ptr %77, ptr %75, align 8
  br label %78

78:                                               ; preds = %74, %69
  %79 = phi ptr [ %72, %69 ], [ %76, %74 ]
  %80 = load i64, ptr %79, align 8, !tbaa !13
  %81 = call noundef i64 @_Z15append_msg_dataImEmPcRmT_(ptr noundef %64, ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef %80)
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  %84 = getelementptr inbounds %struct.__va_list_tag, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 16
  %86 = icmp ule i32 %85, 40
  br i1 %86, label %87, label %92

87:                                               ; preds = %78
  %88 = getelementptr inbounds %struct.__va_list_tag, ptr %83, i32 0, i32 3
  %89 = load ptr, ptr %88, align 16
  %90 = getelementptr i8, ptr %89, i32 %85
  %91 = add i32 %85, 8
  store i32 %91, ptr %84, align 16
  br label %96

92:                                               ; preds = %78
  %93 = getelementptr inbounds %struct.__va_list_tag, ptr %83, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8
  %95 = getelementptr i8, ptr %94, i32 8
  store ptr %95, ptr %93, align 8
  br label %96

96:                                               ; preds = %92, %87
  %97 = phi ptr [ %90, %87 ], [ %94, %92 ]
  %98 = load i64, ptr %97, align 8, !tbaa !13
  %99 = call noundef i64 @_Z15append_msg_dataImEmPcRmT_(ptr noundef %82, ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef %98)
  %100 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %100)
  br label %101

101:                                              ; preds = %96, %59
  br label %102

102:                                              ; preds = %101, %54
  br label %103

103:                                              ; preds = %102, %30
  %104 = load i64, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i64 %104
}

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { 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 = !{!"_ZTS14comm_request_t", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}


; 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.__va_list_tag = type { i32, i32, ptr, ptr }

; 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 nounwind uwtable
declare dso_local noundef i64 @_Z15append_msg_dataImEmPcRmT_(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

; 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
define dso_local noundef i64 @_Z16prepare_responsePc14comm_request_tiz(ptr noundef %0, i32 noundef %1, i32 noundef %2, ...) local_unnamed_addr #1 {
  %4 = alloca i64, align 8
  %5 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  %6 = call noundef i64 @_Z15append_msg_dataIiEmPcRmT_(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef %2)
  switch i32 %1, label %75 [
    i32 0, label %7
    i32 2, label %25
    i32 1, label %42
  ]

7:                                                ; preds = %3
  call void @llvm.va_start.p0(ptr nonnull %5)
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  %9 = load i32, ptr %8, align 4
  %10 = icmp ult i32 %9, 161
  br i1 %10, label %11, label %17

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %5, i64 16
  %13 = load ptr, ptr %12, align 16
  %14 = zext nneg i32 %9 to i64
  %15 = getelementptr i8, ptr %13, i64 %14
  %16 = add nuw nsw i32 %9, 16
  store i32 %16, ptr %8, align 4
  br label %21

17:                                               ; preds = %7
  %18 = getelementptr inbounds i8, ptr %5, i64 8
  %19 = load ptr, ptr %18, align 8
  %20 = getelementptr i8, ptr %19, i64 8
  store ptr %20, ptr %18, align 8
  br label %21

21:                                               ; preds = %17, %11
  %22 = phi ptr [ %15, %11 ], [ %19, %17 ]
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = call noundef i64 @_Z15append_msg_dataIdEmPcRmT_(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %4, double noundef %23)
  br label %.sink.split

25:                                               ; preds = %3
  call void @llvm.va_start.p0(ptr nonnull %5)
  %26 = load i32, ptr %5, align 16
  %27 = icmp ult i32 %26, 41
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %5, i64 16
  %30 = load ptr, ptr %29, align 16
  %31 = zext nneg i32 %26 to i64
  %32 = getelementptr i8, ptr %30, i64 %31
  %33 = add nuw nsw i32 %26, 8
  store i32 %33, ptr %5, align 16
  br label %38

34:                                               ; preds = %25
  %35 = getelementptr inbounds i8, ptr %5, i64 8
  %36 = load ptr, ptr %35, align 8
  %37 = getelementptr i8, ptr %36, i64 8
  store ptr %37, ptr %35, align 8
  br label %38

38:                                               ; preds = %34, %28
  %39 = phi ptr [ %32, %28 ], [ %36, %34 ]
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = call noundef i64 @_Z15append_msg_dataIiEmPcRmT_(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef %40)
  br label %.sink.split

42:                                               ; preds = %3
  call void @llvm.va_start.p0(ptr nonnull %5)
  %43 = load i32, ptr %5, align 16
  %44 = icmp ult i32 %43, 41
  br i1 %44, label %45, label %51

45:                                               ; preds = %42
  %46 = getelementptr inbounds i8, ptr %5, i64 16
  %47 = load ptr, ptr %46, align 16
  %48 = zext nneg i32 %43 to i64
  %49 = getelementptr i8, ptr %47, i64 %48
  %50 = add nuw nsw i32 %43, 8
  store i32 %50, ptr %5, align 16
  br label %55

51:                                               ; preds = %42
  %52 = getelementptr inbounds i8, ptr %5, i64 8
  %53 = load ptr, ptr %52, align 8
  %54 = getelementptr i8, ptr %53, i64 8
  store ptr %54, ptr %52, align 8
  br label %55

55:                                               ; preds = %51, %45
  %56 = phi ptr [ %49, %45 ], [ %53, %51 ]
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = call noundef i64 @_Z15append_msg_dataImEmPcRmT_(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %57)
  %59 = load i32, ptr %5, align 16
  %60 = icmp ult i32 %59, 41
  br i1 %60, label %61, label %67

61:                                               ; preds = %55
  %62 = getelementptr inbounds i8, ptr %5, i64 16
  %63 = load ptr, ptr %62, align 16
  %64 = zext nneg i32 %59 to i64
  %65 = getelementptr i8, ptr %63, i64 %64
  %66 = add nuw nsw i32 %59, 8
  store i32 %66, ptr %5, align 16
  br label %71

67:                                               ; preds = %55
  %68 = getelementptr inbounds i8, ptr %5, i64 8
  %69 = load ptr, ptr %68, align 8
  %70 = getelementptr i8, ptr %69, i64 8
  store ptr %70, ptr %68, align 8
  br label %71

71:                                               ; preds = %67, %61
  %72 = phi ptr [ %65, %61 ], [ %69, %67 ]
  %73 = load i64, ptr %72, align 8, !tbaa !5
  %74 = call noundef i64 @_Z15append_msg_dataImEmPcRmT_(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %73)
  br label %.sink.split

.sink.split:                                      ; preds = %21, %71, %38
  call void @llvm.va_end.p0(ptr nonnull %5)
  br label %75

75:                                               ; preds = %.sink.split, %3
  %76 = load i64, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i64 %76
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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