; LLVM IR from CerebusOSS/CereLink :: cbhwlib/CCFUtils.ll (ZN8CCFUtils16WriteCCFNoPromptEPKc)

; 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.CCFUtils = type <{ ptr, ptr, i8, [7 x i8], ptr, i8, [7 x i8], ptr, i32, i32, i32, [4 x i8], ptr, i8, i8, [6 x i8] }>

; 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
define dso_local noundef i32 @_ZN8CCFUtils16WriteCCFNoPromptEPKc(ptr noundef nonnull align 8 dereferenceable(74) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 12
  store ptr %9, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !13
  %11 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 5
  %12 = load i8, ptr %11, align 8, !tbaa !15, !range !16, !noundef !17
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %22

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 7
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 10
  %21 = load i32, ptr %20, align 8, !tbaa !20
  call void @_ZN3ccf11ConWriteCCFEPKcP5cbCCFPFvjNS_10_ccfResultES1_11_cbStateCCFjEj(ptr noundef %15, ptr noundef %17, ptr noundef %19, i32 noundef %21)
  br label %71

22:                                               ; preds = %2
  %23 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %25 = icmp ne ptr %24, null
  br i1 %25, label %36, label %26

26:                                               ; preds = %22
  %27 = load ptr, ptr %8, align 8, !tbaa !22
  %28 = getelementptr inbounds ptr, ptr %27, i64 2
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(74) %8, ptr noundef null, i1 noundef zeroext false)
  store i32 %30, ptr %6, align 4, !tbaa !13
  %31 = load i32, ptr %6, align 4, !tbaa !13
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %26
  %34 = load i32, ptr %6, align 4, !tbaa !13
  store i32 %34, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

35:                                               ; preds = %26
  br label %36

36:                                               ; preds = %35, %22
  %37 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !21
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 -6, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

41:                                               ; preds = %36
  %42 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !19
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %52

45:                                               ; preds = %41
  %46 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !19
  %48 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 10
  %49 = load i32, ptr %48, align 8, !tbaa !20
  %50 = load i32, ptr %6, align 4, !tbaa !13
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void %47(i32 noundef %49, i32 noundef %50, ptr noundef %51, i32 noundef 1, i32 noundef 0)
  br label %52

52:                                               ; preds = %45, %41
  %53 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !21
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %54, align 8, !tbaa !22
  %57 = getelementptr inbounds ptr, ptr %56, i64 3
  %58 = load ptr, ptr %57, align 8
  %59 = call noundef i32 %58(ptr noundef nonnull align 8 dereferenceable(74) %54, ptr noundef %55)
  store i32 %59, ptr %6, align 4, !tbaa !13
  %60 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 4
  %61 = load ptr, ptr %60, align 8, !tbaa !19
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %70

63:                                               ; preds = %52
  %64 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 10
  %67 = load i32, ptr %66, align 8, !tbaa !20
  %68 = load i32, ptr %6, align 4, !tbaa !13
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  call void %65(i32 noundef %67, i32 noundef %68, ptr noundef %69, i32 noundef 1, i32 noundef 100)
  br label %70

70:                                               ; preds = %63, %52
  br label %71

71:                                               ; preds = %70, %14
  %72 = load i32, ptr %6, align 4, !tbaa !13
  store i32 %72, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

73:                                               ; preds = %71, %40, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

declare void @_ZN3ccf11ConWriteCCFEPKcP5cbCCFPFvjNS_10_ccfResultES1_11_cbStateCCFjEj(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #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 = { "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, !6, i64 64}
!10 = !{!"_ZTS8CCFUtils", !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !6, i64 64, !11, i64 72, !11, i64 73}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTSN3ccf10_ccfResultE", !7, i64 0}
!15 = !{!10, !11, i64 32}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !6, i64 24}
!20 = !{!10, !12, i64 56}
!21 = !{!10, !6, i64 8}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8CCFUtils16WriteCCFNoPromptEPKc(ptr noundef nonnull align 8 dereferenceable(74) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i8, ptr %4, align 8, !tbaa !12, !range !13, !noundef !14
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %14

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = load i32, ptr %12, align 8, !tbaa !17
  tail call void @_ZN3ccf11ConWriteCCFEPKcP5cbCCFPFvjNS_10_ccfResultES1_11_cbStateCCFjEj(ptr noundef %1, ptr noundef %9, ptr noundef %11, i32 noundef %13)
  br label %39

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %17, label %.thread

17:                                               ; preds = %14
  %18 = load ptr, ptr %0, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load ptr, ptr %19, align 8
  %21 = tail call noundef i32 %20(ptr noundef nonnull align 8 dereferenceable(74) %0, ptr noundef null, i1 noundef zeroext false)
  %.not16 = icmp eq i32 %21, 0
  br i1 %.not16, label %22, label %39

22:                                               ; preds = %17
  %.pr = load ptr, ptr %15, align 8, !tbaa !18
  %.not17 = icmp eq ptr %.pr, null
  br i1 %.not17, label %39, label %.thread

.thread:                                          ; preds = %14, %22
  %23 = phi ptr [ %16, %14 ], [ %.pr, %22 ]
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %.not18 = icmp eq ptr %25, null
  br i1 %.not18, label %29, label %26

26:                                               ; preds = %.thread
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  %28 = load i32, ptr %27, align 8, !tbaa !17
  tail call void %25(i32 noundef %28, i32 noundef 0, ptr noundef %1, i32 noundef 1, i32 noundef 0)
  %.pre = load ptr, ptr %15, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %26, %.thread
  %30 = phi ptr [ %.pre, %26 ], [ %23, %.thread ]
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %31, i64 24
  %33 = load ptr, ptr %32, align 8
  %34 = tail call noundef i32 %33(ptr noundef nonnull align 8 dereferenceable(74) %30, ptr noundef %1)
  %35 = load ptr, ptr %24, align 8, !tbaa !16
  %.not19 = icmp eq ptr %35, null
  br i1 %.not19, label %39, label %36

36:                                               ; preds = %29
  %37 = getelementptr inbounds i8, ptr %0, i64 56
  %38 = load i32, ptr %37, align 8, !tbaa !17
  tail call void %35(i32 noundef %38, i32 noundef %34, ptr noundef %1, i32 noundef 1, i32 noundef 100)
  br label %39

39:                                               ; preds = %7, %36, %29, %22, %17
  %.011 = phi i32 [ %21, %17 ], [ -6, %22 ], [ 0, %7 ], [ %34, %36 ], [ %34, %29 ]
  ret i32 %.011
}

declare void @_ZN3ccf11ConWriteCCFEPKcP5cbCCFPFvjNS_10_ccfResultES1_11_cbStateCCFjEj(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { "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" }

!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, !7, i64 64}
!6 = !{!"_ZTS8CCFUtils", !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !7, i64 64, !10, i64 72, !10, i64 73}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 32}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !7, i64 40}
!16 = !{!6, !7, i64 24}
!17 = !{!6, !11, i64 56}
!18 = !{!6, !7, i64 8}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !9, i64 0}


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