; LLVM IR from clangen/musikcube :: src/3rdparty/win32_src/pdcurses (util)

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

@unctrl.strbuf = external hidden global [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @unctrl(i64 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = and i64 %6, 2097151
  store i64 %7, ptr %4, align 8, !tbaa !5
  %8 = load i64, ptr %4, align 8, !tbaa !5
  %9 = icmp uge i64 %8, 32
  br i1 %9, label %10, label %16

10:                                               ; preds = %1
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = icmp ne i64 %11, 127
  br i1 %12, label %13, label %16

13:                                               ; preds = %10
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = trunc i64 %14 to i8
  store i8 %15, ptr @unctrl.strbuf, align 1, !tbaa !9
  store i8 0, ptr getelementptr inbounds ([3 x i8], ptr @unctrl.strbuf, i64 0, i64 1), align 1, !tbaa !9
  store ptr @unctrl.strbuf, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %25

16:                                               ; preds = %10, %1
  store i8 94, ptr @unctrl.strbuf, align 1, !tbaa !9
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = icmp eq i64 %17, 127
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i8 63, ptr getelementptr inbounds ([3 x i8], ptr @unctrl.strbuf, i64 0, i64 1), align 1, !tbaa !9
  br label %24

20:                                               ; preds = %16
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = add i64 %21, 64
  %23 = trunc i64 %22 to i8
  store i8 %23, ptr getelementptr inbounds ([3 x i8], ptr @unctrl.strbuf, i64 0, i64 1), align 1, !tbaa !9
  br label %24

24:                                               ; preds = %20, %19
  store ptr @unctrl.strbuf, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %25

25:                                               ; preds = %24, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %26 = load ptr, ptr %2, align 8
  ret ptr %26
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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/C++ TBAA"}
!9 = !{!7, !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"

@unctrl.strbuf = external hidden global [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef nonnull ptr @unctrl(i64 noundef %0) local_unnamed_addr #0 {
  %2 = and i64 %0, 2097151
  %3 = icmp ugt i64 %2, 31
  %4 = icmp ne i64 %2, 127
  %or.cond = and i1 %3, %4
  %5 = trunc i64 %0 to i8
  %6 = icmp eq i64 %2, 127
  %7 = trunc i64 %0 to i8
  %8 = add i8 %7, 64
  %storemerge = select i1 %6, i8 63, i8 %8
  %.sink = select i1 %or.cond, i8 %5, i8 94
  %storemerge7 = select i1 %or.cond, i8 0, i8 %storemerge
  store i8 %.sink, ptr @unctrl.strbuf, align 1
  store i8 %storemerge7, ptr getelementptr inbounds (i8, ptr @unctrl.strbuf, i64 1), align 1, !tbaa !5
  ret ptr @unctrl.strbuf
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass