; LLVM IR from AngelJumbo/lavat :: lavat (tb_strerror)

; 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.tb_global_t = type { i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i64, [36 x ptr], %struct.cap_trie_t, %struct.bytebuf_t, %struct.bytebuf_t, %struct.cellbuf_t, %struct.cellbuf_t, %struct.termios, i32, i32, i32, ptr, ptr, [1024 x i8] }
%struct.cap_trie_t = type { i8, ptr, i64, i32, i16, i8 }
%struct.bytebuf_t = type { ptr, i64, i64 }
%struct.cellbuf_t = type { i32, i32, ptr }
%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@global = external hidden global %struct.tb_global_t, align 8
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @tb_strerror(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %4, label %17 [
    i32 0, label %5
    i32 -2, label %6
    i32 -3, label %7
    i32 -5, label %8
    i32 -6, label %9
    i32 -7, label %10
    i32 -8, label %11
    i32 -9, label %12
    i32 -17, label %13
    i32 -22, label %14
    i32 -21, label %15
    i32 -1, label %16
    i32 -4, label %16
    i32 -10, label %16
    i32 -11, label %16
    i32 -12, label %16
    i32 -13, label %16
    i32 -14, label %16
    i32 -15, label %16
    i32 -16, label %16
    i32 -18, label %16
    i32 -19, label %16
    i32 -20, label %16
  ]

5:                                                ; preds = %1
  store ptr @.str.3, ptr %2, align 8
  br label %20

6:                                                ; preds = %1
  store ptr @.str.4, ptr %2, align 8
  br label %20

7:                                                ; preds = %1
  store ptr @.str.5, ptr %2, align 8
  br label %20

8:                                                ; preds = %1
  store ptr @.str.6, ptr %2, align 8
  br label %20

9:                                                ; preds = %1
  store ptr @.str.7, ptr %2, align 8
  br label %20

10:                                               ; preds = %1
  store ptr @.str.8, ptr %2, align 8
  br label %20

11:                                               ; preds = %1
  store ptr @.str.9, ptr %2, align 8
  br label %20

12:                                               ; preds = %1
  store ptr @.str.10, ptr %2, align 8
  br label %20

13:                                               ; preds = %1
  store ptr @.str.11, ptr %2, align 8
  br label %20

14:                                               ; preds = %1
  store ptr @.str.12, ptr %2, align 8
  br label %20

15:                                               ; preds = %1
  store ptr @.str.13, ptr %2, align 8
  br label %20

16:                                               ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1
  br label %17

17:                                               ; preds = %16, %1
  %18 = load i32, ptr getelementptr inbounds (%struct.tb_global_t, ptr @global, i32 0, i32 27), align 8, !tbaa !9
  %19 = call i32 @__xpg_strerror_r(i32 noundef %18, ptr noundef getelementptr inbounds (%struct.tb_global_t, ptr @global, i32 0, i32 31), i64 noundef 1024) #2
  store ptr getelementptr inbounds (%struct.tb_global_t, ptr @global, i32 0, i32 31), ptr %2, align 8
  br label %20

20:                                               ; preds = %17, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
  %21 = load ptr, ptr %2, align 8
  ret ptr %21
}

; Function Attrs: nounwind
declare i32 @__xpg_strerror_r(i32 noundef, ptr noundef, i64 noundef) #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 = { 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 = { 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, !6, i64 552}
!10 = !{!"tb_global_t", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !11, i64 72, !12, i64 80, !7, i64 88, !13, i64 376, !15, i64 408, !15, i64 432, !16, i64 456, !16, i64 472, !17, i64 488, !6, i64 548, !6, i64 552, !6, i64 556, !11, i64 560, !11, i64 568, !7, i64 576}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"cap_trie_t", !7, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !14, i64 28, !7, i64 30}
!14 = !{!"short", !7, i64 0}
!15 = !{!"bytebuf_t", !11, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!"cellbuf_t", !6, i64 0, !6, i64 4, !11, i64 8}
!17 = !{!"termios", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !7, i64 17, !6, i64 52, !6, i64 56}


; 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.tb_global_t = type { i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i64, [36 x ptr], %struct.cap_trie_t, %struct.bytebuf_t, %struct.bytebuf_t, %struct.cellbuf_t, %struct.cellbuf_t, %struct.termios, i32, i32, i32, ptr, ptr, [1024 x i8] }
%struct.cap_trie_t = type { i8, ptr, i64, i32, i16, i8 }
%struct.bytebuf_t = type { ptr, i64, i64 }
%struct.cellbuf_t = type { i32, i32, ptr }
%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@global = external hidden global %struct.tb_global_t, align 8
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [60 x i8], align 1
@switch.table.tb_strerror = private unnamed_addr constant [23 x ptr] [ptr @.str.12, ptr @.str.13, ptr @.str.3, ptr @.str.3, ptr @.str.3, ptr @.str.11, ptr @.str.3, ptr @.str.3, ptr @.str.3, ptr @.str.3, ptr @.str.3, ptr @.str.3, ptr @.str.3, ptr @.str.10, ptr @.str.9, ptr @.str.8, ptr @.str.7, ptr @.str.6, ptr @.str.3, ptr @.str.5, ptr @.str.4, ptr @.str.3, ptr @.str.3], align 8

; Function Attrs: nounwind uwtable
define dso_local nonnull ptr @tb_strerror(i32 noundef %0) local_unnamed_addr #0 {
  %switch.tableidx = add i32 %0, 22
  %2 = icmp ult i32 %switch.tableidx, 23
  br i1 %2, label %switch.hole_check, label %3

3:                                                ; preds = %switch.hole_check, %1
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @global, i64 552), align 8, !tbaa !5
  %5 = tail call i32 @__xpg_strerror_r(i32 noundef %4, ptr noundef nonnull getelementptr inbounds (i8, ptr @global, i64 576), i64 noundef 1024) #2
  br label %7

switch.hole_check:                                ; preds = %1
  %switch.shifted = lshr i32 6021155, %switch.tableidx
  %switch.lobit = trunc i32 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup, label %3

switch.lookup:                                    ; preds = %switch.hole_check
  %6 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [23 x ptr], ptr @switch.table.tb_strerror, i64 0, i64 %6
  %switch.load = load ptr, ptr %switch.gep, align 8
  br label %7

7:                                                ; preds = %switch.lookup, %3
  %.0 = phi ptr [ getelementptr inbounds (i8, ptr @global, i64 576), %3 ], [ %switch.load, %switch.lookup ]
  ret ptr %.0
}

; Function Attrs: nounwind
declare i32 @__xpg_strerror_r(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = { 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 = { 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, !7, i64 552}
!6 = !{!"tb_global_t", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !10, i64 72, !11, i64 80, !8, i64 88, !12, i64 376, !14, i64 408, !14, i64 432, !15, i64 456, !15, i64 472, !16, i64 488, !7, i64 548, !7, i64 552, !7, i64 556, !10, i64 560, !10, i64 568, !8, i64 576}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"cap_trie_t", !8, i64 0, !10, i64 8, !11, i64 16, !7, i64 24, !13, i64 28, !8, i64 30}
!13 = !{!"short", !8, i64 0}
!14 = !{!"bytebuf_t", !10, i64 0, !11, i64 8, !11, i64 16}
!15 = !{!"cellbuf_t", !7, i64 0, !7, i64 4, !10, i64 8}
!16 = !{!"termios", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 17, !7, i64 52, !7, i64 56}


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