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

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

@keyname._keyname = external hidden global [16 x i8], align 16
@keyname.key_names = external hidden global [322 x ptr], align 16
@.str.133 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.322 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.323 = external hidden unnamed_addr constant [93 x i8], align 1
@__PRETTY_FUNCTION__.keyname = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @keyname(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sge i32 %3, 0
  br i1 %4, label %5, label %13

5:                                                ; preds = %1
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 128
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = call ptr @unctrl(i64 noundef %10)
  %12 = call ptr @strcpy(ptr noundef @keyname._keyname, ptr noundef %11) #5
  br label %36

13:                                               ; preds = %5, %1
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = call zeroext i1 @has_key(i32 noundef %14)
  br i1 %15, label %16, label %33

16:                                               ; preds = %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sub nsw i32 %17, 257
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [322 x ptr], ptr @keyname.key_names, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = call i64 @strlen(ptr noundef %21) #6
  %23 = icmp ult i64 %22, 16
  br i1 %23, label %24, label %25

24:                                               ; preds = %16
  br label %26

25:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.322, ptr noundef @.str.323, i32 noundef 124, ptr noundef @__PRETTY_FUNCTION__.keyname) #7
  unreachable

26:                                               ; preds = %24
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 257
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [322 x ptr], ptr @keyname.key_names, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call ptr @strcpy(ptr noundef @keyname._keyname, ptr noundef %31) #5
  br label %35

33:                                               ; preds = %13
  %34 = call ptr @strcpy(ptr noundef @keyname._keyname, ptr noundef @.str.133) #5
  br label %35

35:                                               ; preds = %33, %26
  br label %36

36:                                               ; preds = %35, %8
  ret ptr @keyname._keyname
}

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #1

declare ptr @unctrl(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @has_key(i32 noundef) #0

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

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

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 = { 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 = { "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 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@keyname._keyname = external hidden global [16 x i8], align 16
@keyname.key_names = external hidden local_unnamed_addr global [322 x ptr], align 16
@.str.133 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.322 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.323 = external hidden unnamed_addr constant [93 x i8], align 1
@__PRETTY_FUNCTION__.keyname = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @keyname(i32 noundef %0) local_unnamed_addr #0 {
  %or.cond = icmp ult i32 %0, 128
  br i1 %or.cond, label %2, label %5

2:                                                ; preds = %1
  %3 = zext nneg i32 %0 to i64
  %4 = tail call ptr @unctrl(i64 noundef %3) #5
  br label %15

5:                                                ; preds = %1
  %6 = tail call zeroext i1 @has_key(i32 noundef %0)
  br i1 %6, label %7, label %15

7:                                                ; preds = %5
  %8 = add nsw i32 %0, -257
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [322 x ptr], ptr @keyname.key_names, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %11) #6
  %13 = icmp ult i64 %12, 16
  br i1 %13, label %15, label %14

14:                                               ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.322, ptr noundef nonnull @.str.323, i32 noundef 124, ptr noundef nonnull @__PRETTY_FUNCTION__.keyname) #7
  unreachable

15:                                               ; preds = %5, %7, %2
  %.sink = phi ptr [ %4, %2 ], [ %11, %7 ], [ @.str.133, %5 ]
  %16 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @keyname._keyname, ptr noundef nonnull dereferenceable(1) %.sink) #5
  ret ptr @keyname._keyname
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #1

declare ptr @unctrl(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @has_key(i32 noundef) local_unnamed_addr #0

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

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

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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 "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 = { nounwind willreturn memory(read) }
attributes #7 = { noreturn 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/C++ TBAA"}


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