; LLVM IR from aap/librw :: skeleton/skeleton.ll (ZN2sk12EventHandlerENS_5EventEPv)

; 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.sk::Globals" = type { ptr, i32, i32, i32 }

@_ZN2sk7globalsE = external dso_local global %"struct.sk::Globals", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2sk6InitRWEv() #0

declare noundef i32 @_Z15AppEventHandlerN2sk5EventEPv(i32 noundef, ptr noundef) #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2sk11TerminateRWEv() #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2sk12EventHandlerENS_5EventEPv(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = call noundef ptr @_ZN5ImGui13CreateContextEP11ImFontAtlas(ptr noundef null)
  br label %12

12:                                               ; preds = %10, %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = call noundef i32 @_Z15AppEventHandlerN2sk5EventEPv(i32 noundef %13, ptr noundef %14)
  store i32 %15, ptr %6, align 4, !tbaa !11
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 12
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store i32 1, ptr getelementptr inbounds (%"struct.sk::Globals", ptr @_ZN2sk7globalsE, i32 0, i32 3), align 8, !tbaa !13
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %33

19:                                               ; preds = %12
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = icmp eq i32 %20, 2
  br i1 %21, label %22, label %31

22:                                               ; preds = %19
  %23 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %23, label %29 [
    i32 1, label %24
    i32 2, label %28
  ]

24:                                               ; preds = %22
  %25 = call noundef zeroext i1 @_ZN2sk6InitRWEv()
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, i32 1, i32 0
  store i32 %27, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %33

28:                                               ; preds = %22
  call void @_ZN2sk11TerminateRWEv()
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %33

29:                                               ; preds = %22
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30, %19
  %32 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %32, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %33

33:                                               ; preds = %31, %28, %24, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %34 = load i32, ptr %3, align 4
  ret i32 %34
}

declare noundef ptr @_ZN5ImGui13CreateContextEP11ImFontAtlas(ptr noundef) #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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_ZTSN2sk5EventE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN2sk11EventStatusE", !7, i64 0}
!13 = !{!14, !15, i64 16}
!14 = !{!"_ZTSN2sk7GlobalsE", !10, i64 0, !15, i64 8, !15, i64 12, !15, i64 16}
!15 = !{!"int", !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.sk::Globals" = type { ptr, i32, i32, i32 }

@_ZN2sk7globalsE = external dso_local local_unnamed_addr global %"struct.sk::Globals", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2sk6InitRWEv() local_unnamed_addr #0

declare noundef i32 @_Z15AppEventHandlerN2sk5EventEPv(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2sk11TerminateRWEv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2sk12EventHandlerENS_5EventEPv(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %.thread, label %6

.thread:                                          ; preds = %2
  %4 = tail call noundef ptr @_ZN5ImGui13CreateContextEP11ImFontAtlas(ptr noundef null)
  %5 = tail call noundef i32 @_Z15AppEventHandlerN2sk5EventEPv(i32 noundef 0, ptr noundef %1)
  br label %10

6:                                                ; preds = %2
  %7 = tail call noundef i32 @_Z15AppEventHandlerN2sk5EventEPv(i32 noundef %0, ptr noundef %1)
  %8 = icmp eq i32 %0, 12
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  store i32 1, ptr getelementptr inbounds (i8, ptr @_ZN2sk7globalsE, i64 16), align 8, !tbaa !5
  br label %18

10:                                               ; preds = %.thread, %6
  %11 = phi i32 [ %5, %.thread ], [ %7, %6 ]
  %12 = icmp eq i32 %11, 2
  br i1 %12, label %13, label %18

13:                                               ; preds = %10
  switch i32 %0, label %18 [
    i32 1, label %14
    i32 2, label %17
  ]

14:                                               ; preds = %13
  %15 = tail call noundef zeroext i1 @_ZN2sk6InitRWEv()
  %16 = zext i1 %15 to i32
  br label %18

17:                                               ; preds = %13
  tail call void @_ZN2sk11TerminateRWEv()
  br label %18

18:                                               ; preds = %10, %13, %17, %14, %9
  %.0 = phi i32 [ 1, %9 ], [ 1, %17 ], [ %16, %14 ], [ 2, %13 ], [ %11, %10 ]
  ret i32 %.0
}

declare noundef ptr @_ZN5ImGui13CreateContextEP11ImFontAtlas(ptr 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, !10, i64 16}
!6 = !{!"_ZTSN2sk7GlobalsE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}


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