; LLVM IR from Angold-4/chainsaw :: src/debug/main.ll (Z7consumeP6bufferP5InterP6Editor)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7consumeP6bufferP5InterP6Editor(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.buffer, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.buffer, ptr %8, i32 0, i32 2
  %10 = load i8, ptr %9, align 8, !tbaa !9, !range !14, !noundef !15
  %11 = trunc i8 %10 to i1
  br i1 %11, label %13, label %12

12:                                               ; preds = %3
  br label %48

13:                                               ; preds = %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.buffer, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !16
  switch i32 %16, label %41 [
    i32 0, label %42
    i32 1, label %17
    i32 2, label %22
    i32 3, label %28
    i32 4, label %34
  ]

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.buffer, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  call void (ptr, ptr, ...) @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448) %18, ptr noundef %21)
  br label %42

22:                                               ; preds = %13
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.buffer, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = call noundef zeroext i1 @_ZN5Inter4ExecEPc(ptr noundef nonnull align 8 dereferenceable(240) %23, ptr noundef %26)
  br label %42

28:                                               ; preds = %13
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.buffer, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = call noundef i32 @_ZN6Editor4OpenEPc(ptr noundef nonnull align 8 dereferenceable(448) %29, ptr noundef %32)
  br label %42

34:                                               ; preds = %13
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.buffer, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = call noundef i32 @_ZN6Editor7LoadOutEPc(ptr noundef nonnull align 8 dereferenceable(448) %35, ptr noundef %38)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN5Inter9RemoveTmpEv(ptr noundef nonnull align 8 dereferenceable(240) %40)
  br label %42

41:                                               ; preds = %13
  br label %42

42:                                               ; preds = %41, %34, %28, %22, %17, %13
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %43 = getelementptr inbounds %struct.buffer, ptr %7, i32 0, i32 0
  store ptr null, ptr %43, align 8, !tbaa !17
  %44 = getelementptr inbounds %struct.buffer, ptr %7, i32 0, i32 1
  store i64 0, ptr %44, align 8, !tbaa !18
  %45 = getelementptr inbounds %struct.buffer, ptr %7, i32 0, i32 2
  store i8 0, ptr %45, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.buffer, ptr %7, i32 0, i32 3
  store i32 0, ptr %46, align 4, !tbaa !16
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %47, ptr align 8 %7, i64 24, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  br label %48

48:                                               ; preds = %42, %12
  ret void
}

declare void @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, ...) #1

declare noundef zeroext i1 @_ZN5Inter4ExecEPc(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) #1

declare noundef i32 @_ZN6Editor4OpenEPc(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef) #1

declare noundef i32 @_ZN6Editor7LoadOutEPc(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef) #1

declare void @_ZN5Inter9RemoveTmpEv(ptr noundef nonnull align 8 dereferenceable(240)) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 16}
!10 = !{!"_ZTS6buffer", !6, i64 0, !11, i64 8, !12, i64 16, !13, i64 20}
!11 = !{!"long", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!10, !13, i64 20}
!17 = !{!10, !6, i64 0}
!18 = !{!10, !11, i64 8}
!19 = !{i64 0, i64 8, !5, i64 8, i64 8, !20, i64 16, i64 1, !21, i64 20, i64 4, !22}
!20 = !{!11, !11, i64 0}
!21 = !{!12, !12, i64 0}
!22 = !{!13, !13, 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 void @_Z7consumeP6bufferP5InterP6Editor(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !13, !noundef !14
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %22

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = load i32, ptr %8, align 4, !tbaa !15
  switch i32 %9, label %21 [
    i32 4, label %18
    i32 1, label %10
    i32 2, label %12
    i32 3, label %15
  ]

10:                                               ; preds = %7
  %11 = load ptr, ptr %0, align 8, !tbaa !16
  tail call void (ptr, ptr, ...) @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448) %2, ptr noundef %11)
  br label %21

12:                                               ; preds = %7
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = tail call noundef zeroext i1 @_ZN5Inter4ExecEPc(ptr noundef nonnull align 8 dereferenceable(240) %1, ptr noundef %13)
  br label %21

15:                                               ; preds = %7
  %16 = load ptr, ptr %0, align 8, !tbaa !16
  %17 = tail call noundef i32 @_ZN6Editor4OpenEPc(ptr noundef nonnull align 8 dereferenceable(448) %2, ptr noundef %16)
  br label %21

18:                                               ; preds = %7
  %19 = load ptr, ptr %0, align 8, !tbaa !16
  %20 = tail call noundef i32 @_ZN6Editor7LoadOutEPc(ptr noundef nonnull align 8 dereferenceable(448) %2, ptr noundef %19)
  tail call void @_ZN5Inter9RemoveTmpEv(ptr noundef nonnull align 8 dereferenceable(240) %1)
  br label %21

21:                                               ; preds = %7, %18, %15, %12, %10
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(17) %0, i8 0, i64 17, i1 false)
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %22

22:                                               ; preds = %3, %21
  ret void
}

declare void @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, ...) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN5Inter4ExecEPc(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) local_unnamed_addr #1

declare noundef i32 @_ZN6Editor4OpenEPc(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef) local_unnamed_addr #1

declare noundef i32 @_ZN6Editor7LoadOutEPc(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef) local_unnamed_addr #1

declare void @_ZN5Inter9RemoveTmpEv(ptr noundef nonnull align 8 dereferenceable(240)) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 nounwind willreturn memory(argmem: write) }

!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, !11, i64 16}
!6 = !{!"_ZTS6buffer", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !12, i64 20}
!16 = !{!6, !7, i64 0}
!17 = !{!12, !12, i64 0}


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