; LLVM IR from golems/ach :: cpp/cpptest.ll (Z9subscribePN3ach7ChannelE)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@fout = external dso_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [20 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9subscribePN3ach7ChannelE(ptr noundef %0) #1 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %"class.std::vector", align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  call void @_ZNSt6vectorIhSaIhEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  br label %11

11:                                               ; preds = %69, %1
  br label %12

12:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = invoke noundef i32 @_ZN3ach7Channel3getEPSt6vectorIhSaIhEEmPmPK8timespeciii(ptr noundef nonnull align 8 dereferenceable(136) %13, ptr noundef %5, i64 noundef 0, ptr noundef %6, ptr noundef null, i32 noundef 0, i32 noundef 33, i32 noundef 64)
          to label %15 unwind label %24

15:                                               ; preds = %12
  store i32 %14, ptr %3, align 4, !tbaa !13
  %16 = load i32, ptr %3, align 4, !tbaa !13
  %17 = icmp ne i32 0, %16
  br i1 %17, label %18, label %53

18:                                               ; preds = %15
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = icmp eq i32 5, %19
  br i1 %20, label %21, label %28

21:                                               ; preds = %18
  %22 = invoke i32 @usleep(i32 noundef 1000)
          to label %23 unwind label %24

23:                                               ; preds = %21
  br label %52

24:                                               ; preds = %63, %53, %37, %21, %12
  %25 = landingpad { ptr, i32 }
          cleanup
  %26 = extractvalue { ptr, i32 } %25, 0
  store ptr %26, ptr %8, align 8
  %27 = extractvalue { ptr, i32 } %25, 1
  store i32 %27, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %79

28:                                               ; preds = %18
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = load i32, ptr %3, align 4, !tbaa !13
  %33 = icmp eq i32 %32, 6
  br i1 %33, label %44, label %34

34:                                               ; preds = %31, %28
  %35 = load i32, ptr %3, align 4, !tbaa !13
  %36 = icmp ne i32 10, %35
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !13
  %40 = invoke ptr @ach_result_to_string(i32 noundef %39)
          to label %41 unwind label %24

41:                                               ; preds = %37
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str.2, ptr noundef %40) #5
  br label %43

43:                                               ; preds = %41, %34
  br label %44

44:                                               ; preds = %43, %31
  %45 = load i32, ptr %3, align 4, !tbaa !13
  %46 = icmp eq i32 6, %45
  br i1 %46, label %51, label %47

47:                                               ; preds = %44
  %48 = load i32, ptr %3, align 4, !tbaa !13
  %49 = icmp eq i32 5, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 3, ptr %10, align 4
  br label %67

51:                                               ; preds = %47, %44
  br label %52

52:                                               ; preds = %51, %23
  br label %53

53:                                               ; preds = %52, %15
  %54 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef 0) #5
  %55 = load i64, ptr %6, align 8, !tbaa !11
  %56 = load ptr, ptr @fout, align 8, !tbaa !5
  %57 = invoke i64 @fwrite(ptr noundef %54, i64 noundef 1, i64 noundef %55, ptr noundef %56)
          to label %58 unwind label %24

58:                                               ; preds = %53
  store i64 %57, ptr %7, align 8, !tbaa !11
  %59 = load i64, ptr %7, align 8, !tbaa !11
  %60 = load i64, ptr %6, align 8, !tbaa !11
  %61 = icmp ne i64 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %58
  store i32 0, ptr %3, align 4, !tbaa !13
  store i32 3, ptr %10, align 4
  br label %67

63:                                               ; preds = %58
  %64 = load ptr, ptr @fout, align 8, !tbaa !5
  %65 = invoke i32 @fflush(ptr noundef %64)
          to label %66 unwind label %24

66:                                               ; preds = %63
  store i32 0, ptr %10, align 4
  br label %67

67:                                               ; preds = %66, %62, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %68 = load i32, ptr %10, align 4
  switch i32 %68, label %85 [
    i32 0, label %69
    i32 3, label %70
  ]

69:                                               ; preds = %67
  br label %11, !llvm.loop !15

70:                                               ; preds = %67
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = invoke noundef i32 @_ZN3ach7Channel5closeEii(ptr noundef nonnull align 8 dereferenceable(136) %71, i32 noundef 1, i32 noundef 0)
          to label %73 unwind label %75

73:                                               ; preds = %70
  %74 = load i32, ptr %3, align 4, !tbaa !13
  store i32 1, ptr %10, align 4
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %74

75:                                               ; preds = %70
  %76 = landingpad { ptr, i32 }
          cleanup
  %77 = extractvalue { ptr, i32 } %76, 0
  store ptr %77, ptr %8, align 8
  %78 = extractvalue { ptr, i32 } %76, 1
  store i32 %78, ptr %9, align 4
  br label %79

79:                                               ; preds = %75, %24
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %8, align 8
  %82 = load i32, ptr %9, align 4
  %83 = insertvalue { ptr, i32 } poison, ptr %81, 0
  %84 = insertvalue { ptr, i32 } %83, i32 %82, 1
  resume { ptr, i32 } %84

85:                                               ; preds = %67
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

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

declare i32 @__gxx_personality_v0(...)

declare i32 @usleep(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

declare ptr @ach_result_to_string(i32 noundef) #3

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

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

declare i32 @fflush(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS10ach_status", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@fout = external dso_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [20 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9subscribePN3ach7ChannelE(ptr noundef %0) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.std::vector", align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @_ZNSt6vectorIhSaIhEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #5
  br label %4

4:                                                ; preds = %23, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  %5 = invoke noundef i32 @_ZN3ach7Channel3getEPSt6vectorIhSaIhEEmPmPK8timespeciii(ptr noundef nonnull align 8 dereferenceable(136) %0, ptr noundef nonnull %2, i64 noundef 0, ptr noundef nonnull %3, ptr noundef null, i32 noundef 0, i32 noundef 33, i32 noundef 64)
          to label %6 unwind label %9

6:                                                ; preds = %4
  switch i32 %5, label %11 [
    i32 0, label %17
    i32 5, label %7
  ]

7:                                                ; preds = %6
  %8 = invoke i32 @usleep(i32 noundef 1000)
          to label %17 unwind label %9

9:                                                ; preds = %12, %7, %4
  %10 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %31

11:                                               ; preds = %6
  %.not = icmp eq i32 %5, 6
  switch i32 %5, label %12 [
    i32 6, label %17
    i32 10, label %26
  ]

12:                                               ; preds = %11
  %13 = load ptr, ptr @stderr, align 8, !tbaa !9
  %14 = invoke ptr @ach_result_to_string(i32 noundef %5)
          to label %15 unwind label %9

15:                                               ; preds = %12
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.2, ptr noundef %14) #6
  br i1 %.not, label %17, label %26

17:                                               ; preds = %11, %6, %7, %15
  %18 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef 0) #5
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr @fout, align 8, !tbaa !9
  %21 = call i64 @fwrite(ptr noundef nonnull %18, i64 noundef 1, i64 noundef %19, ptr noundef %20)
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %.not23 = icmp eq i64 %21, %22
  br i1 %.not23, label %23, label %26

23:                                               ; preds = %17
  %24 = load ptr, ptr @fout, align 8, !tbaa !9
  %25 = call i32 @fflush(ptr noundef %24)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %4

26:                                               ; preds = %11, %15, %17
  %.021.ph = phi i32 [ 0, %17 ], [ %5, %15 ], [ %5, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %27 = invoke noundef i32 @_ZN3ach7Channel5closeEii(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef 1, i32 noundef 0)
          to label %28 unwind label %29

28:                                               ; preds = %26
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  ret i32 %.021.ph

29:                                               ; preds = %26
  %30 = landingpad { ptr, i32 }
          cleanup
  br label %31

31:                                               ; preds = %29, %9
  %.pn = phi { ptr, i32 } [ %30, %29 ], [ %10, %9 ]
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

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

declare i32 @__gxx_personality_v0(...)

declare i32 @usleep(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

declare ptr @ach_result_to_string(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nofree 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 = { nounwind }
attributes #6 = { cold 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 = !{!"any pointer", !7, i64 0}


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