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

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

@pbuffer = external dso_local global [4096 x i8], align 16
@fin = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@__PRETTY_FUNCTION__._Z7publishPN3ach7ChannelE = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7publishPN3ach7ChannelE(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %29, %1
  br label %7

7:                                                ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %8 = load ptr, ptr @fin, align 8, !tbaa !5
  %9 = call ptr @fgets(ptr noundef @pbuffer, i32 noundef 4096, ptr noundef %8)
  store ptr %9, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %7
  store i32 3, ptr %5, align 4
  br label %27

13:                                               ; preds = %7
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp eq ptr @pbuffer, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  br label %19

17:                                               ; preds = %13
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 81, ptr noundef @__PRETTY_FUNCTION__._Z7publishPN3ach7ChannelE) #6
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i64 @strlen(ptr noundef @pbuffer) #7
  %22 = call noundef i32 @_ZN3ach7Channel3putEPKvmii(ptr noundef nonnull align 8 dereferenceable(136) %20, ptr noundef @pbuffer, i64 noundef %21, i32 noundef 1, i32 noundef 0)
  store i32 %22, ptr %3, align 4, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  store i32 3, ptr %5, align 4
  br label %27

26:                                               ; preds = %19
  store i32 0, ptr %5, align 4
  br label %27

27:                                               ; preds = %26, %25, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %28 = load i32, ptr %5, align 4
  switch i32 %28, label %34 [
    i32 0, label %29
    i32 3, label %30
  ]

29:                                               ; preds = %27
  br label %6, !llvm.loop !11

30:                                               ; preds = %27
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = call noundef i32 @_ZN3ach7Channel5closeEii(ptr noundef nonnull align 8 dereferenceable(136) %31, i32 noundef 1, i32 noundef 0)
  %33 = load i32, ptr %3, align 4, !tbaa !9
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %33

34:                                               ; preds = %27
  unreachable
}

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

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { noreturn 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 #4 = { nounwind willreturn memory(read) "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 = { noreturn nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = distinct !{!11, !12}
!12 = !{!"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"

@pbuffer = external dso_local global [4096 x i8], align 16
@fin = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@__PRETTY_FUNCTION__._Z7publishPN3ach7ChannelE = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7publishPN3ach7ChannelE(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %8, %1
  %3 = load ptr, ptr @fin, align 8, !tbaa !5
  %4 = tail call ptr @fgets(ptr noundef nonnull @pbuffer, i32 noundef 4096, ptr noundef %3)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %11, label %5

5:                                                ; preds = %2
  %6 = icmp eq ptr %4, @pbuffer
  br i1 %6, label %8, label %7

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 81, ptr noundef nonnull @__PRETTY_FUNCTION__._Z7publishPN3ach7ChannelE) #4
  unreachable

8:                                                ; preds = %5
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @pbuffer) #5
  %10 = tail call noundef i32 @_ZN3ach7Channel3putEPKvmii(ptr noundef nonnull align 8 dereferenceable(136) %0, ptr noundef nonnull @pbuffer, i64 noundef %9, i32 noundef 1, i32 noundef 0)
  %.not10 = icmp eq i32 %10, 0
  br i1 %.not10, label %2, label %11

11:                                               ; preds = %2, %8
  %.1.ph = phi i32 [ %10, %8 ], [ 0, %2 ]
  %12 = tail call noundef i32 @_ZN3ach7Channel5closeEii(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef 1, i32 noundef 0)
  ret i32 %.1.ph
}

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { 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 #2 = { noreturn 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { noreturn nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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"}


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