; LLVM IR from marcinbor85/microshell :: src/src (ush_read_utils)

; 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.ush_object = type { ptr, i32, i32, i32, ptr, i64, i64, i32, i64, i64, i64, i8, ptr, ptr, ptr, %struct.ush_node_object, ptr, ptr, ptr, i64, i64, ptr, i64, i32, i32, ptr, ptr, ptr, i64, i64, i64 }
%struct.ush_node_object = type { ptr, i64, ptr, ptr, ptr, ptr }
%struct.ush_descriptor = type { ptr, ptr, i64, ptr, i64, i64, ptr, ptr }

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ush_read_char_by_escape_state(ptr noundef %0, i8 noundef signext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  store i8 1, ptr %5, align 1, !tbaa !10
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ush_object, ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %44

10:                                               ; preds = %2
  %11 = load i8, ptr %4, align 1, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ush_object, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds %struct.ush_descriptor, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ush_object, ptr %17, i32 0, i32 8
  %19 = load i64, ptr %18, align 8, !tbaa !20
  %20 = add i64 %19, 1
  store i64 %20, ptr %18, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %16, i64 %19
  store i8 %11, ptr %21, align 1, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ush_object, ptr %22, i32 0, i32 8
  %24 = load i64, ptr %23, align 8, !tbaa !20
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ush_object, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds %struct.ush_descriptor, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !21
  %30 = icmp uge i64 %24, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %10
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ush_object, ptr %32, i32 0, i32 8
  store i64 0, ptr %33, align 8, !tbaa !20
  br label %34

34:                                               ; preds = %31, %10
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ush_object, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct.ush_descriptor, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ush_object, ptr %40, i32 0, i32 8
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !9
  br label %97

44:                                               ; preds = %2
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ush_object, ptr %45, i32 0, i32 7
  %47 = load i32, ptr %46, align 8, !tbaa !12
  %48 = icmp eq i32 %47, 1
  br i1 %48, label %49, label %64

49:                                               ; preds = %44
  %50 = load i8, ptr %4, align 1, !tbaa !9
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %51, 91
  br i1 %52, label %57, label %53

53:                                               ; preds = %49
  %54 = load i8, ptr %4, align 1, !tbaa !9
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 79
  br i1 %56, label %57, label %60

57:                                               ; preds = %53, %49
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ush_object, ptr %58, i32 0, i32 7
  store i32 2, ptr %59, align 8, !tbaa !12
  br label %63

60:                                               ; preds = %53
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ush_object, ptr %61, i32 0, i32 7
  store i32 0, ptr %62, align 8, !tbaa !12
  br label %63

63:                                               ; preds = %60, %57
  store i8 0, ptr %5, align 1, !tbaa !10
  br label %96

64:                                               ; preds = %44
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ush_object, ptr %65, i32 0, i32 7
  %67 = load i32, ptr %66, align 8, !tbaa !12
  %68 = icmp eq i32 %67, 2
  br i1 %68, label %69, label %95

69:                                               ; preds = %64
  %70 = load i8, ptr %4, align 1, !tbaa !9
  %71 = sext i8 %70 to i32
  %72 = icmp eq i32 %71, 65
  br i1 %72, label %73, label %74

73:                                               ; preds = %69
  br label %92

74:                                               ; preds = %69
  %75 = load i8, ptr %4, align 1, !tbaa !9
  %76 = sext i8 %75 to i32
  %77 = icmp eq i32 %76, 66
  br i1 %77, label %78, label %79

78:                                               ; preds = %74
  br label %91

79:                                               ; preds = %74
  %80 = load i8, ptr %4, align 1, !tbaa !9
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 67
  br i1 %82, label %83, label %84

83:                                               ; preds = %79
  br label %90

84:                                               ; preds = %79
  %85 = load i8, ptr %4, align 1, !tbaa !9
  %86 = sext i8 %85 to i32
  %87 = icmp eq i32 %86, 68
  br i1 %87, label %88, label %89

88:                                               ; preds = %84
  br label %89

89:                                               ; preds = %88, %84
  br label %90

90:                                               ; preds = %89, %83
  br label %91

91:                                               ; preds = %90, %78
  br label %92

92:                                               ; preds = %91, %73
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ush_object, ptr %93, i32 0, i32 7
  store i32 0, ptr %94, align 8, !tbaa !12
  store i8 0, ptr %5, align 1, !tbaa !10
  br label %95

95:                                               ; preds = %92, %64
  br label %96

96:                                               ; preds = %95, %63
  br label %97

97:                                               ; preds = %96, %34
  %98 = load i8, ptr %5, align 1, !tbaa !10, !range !22, !noundef !23
  %99 = trunc i8 %98 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  ret i1 %99
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!13, !14, i64 48}
!13 = !{!"ush_object", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !6, i64 24, !15, i64 32, !15, i64 40, !14, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !11, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !16, i64 112, !6, i64 160, !6, i64 168, !6, i64 176, !15, i64 184, !15, i64 192, !6, i64 200, !15, i64 208, !14, i64 216, !14, i64 220, !6, i64 224, !6, i64 232, !6, i64 240, !15, i64 248, !15, i64 256, !15, i64 264}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"ush_node_object", !6, i64 0, !15, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!13, !6, i64 0}
!18 = !{!19, !6, i64 8}
!19 = !{!"ush_descriptor", !6, i64 0, !6, i64 8, !15, i64 16, !6, i64 24, !15, i64 32, !15, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!13, !15, i64 56}
!21 = !{!19, !15, i64 16}
!22 = !{i8 0, i8 2}
!23 = !{}


; 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 nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @ush_read_char_by_escape_state(ptr nocapture noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i32, ptr %3, align 8, !tbaa !5
  switch i32 %4, label %26 [
    i32 0, label %5
    i32 1, label %23
    i32 2, label %25
  ]

5:                                                ; preds = %2
  %6 = load ptr, ptr %0, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = load i64, ptr %9, align 8, !tbaa !17
  %11 = add i64 %10, 1
  store i64 %11, ptr %9, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %8, i64 %10
  store i8 %1, ptr %12, align 1, !tbaa !18
  %13 = load i64, ptr %9, align 8, !tbaa !17
  %14 = load ptr, ptr %0, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !19
  %.not = icmp ult i64 %13, %16
  br i1 %.not, label %18, label %17

17:                                               ; preds = %5
  store i64 0, ptr %9, align 8, !tbaa !17
  br label %18

18:                                               ; preds = %17, %5
  %19 = phi i64 [ 0, %17 ], [ %13, %5 ]
  %20 = getelementptr inbounds i8, ptr %14, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 %19
  store i8 0, ptr %22, align 1, !tbaa !18
  br label %26

23:                                               ; preds = %2
  %switch.selectcmp.case1 = icmp eq i8 %1, 91
  %switch.selectcmp.case2 = icmp eq i8 %1, 79
  %switch.selectcmp = or i1 %switch.selectcmp.case1, %switch.selectcmp.case2
  %24 = select i1 %switch.selectcmp, i32 2, i32 0
  store i32 %24, ptr %3, align 8, !tbaa !5
  br label %26

25:                                               ; preds = %2
  store i32 0, ptr %3, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %2, %23, %25, %18
  %.0 = phi i1 [ true, %18 ], [ false, %23 ], [ false, %25 ], [ true, %2 ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, 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, !10, i64 48}
!6 = !{!"ush_object", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !10, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !12, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !13, i64 112, !7, i64 160, !7, i64 168, !7, i64 176, !11, i64 184, !11, i64 192, !7, i64 200, !11, i64 208, !10, i64 216, !10, i64 220, !7, i64 224, !7, i64 232, !7, i64 240, !11, i64 248, !11, i64 256, !11, i64 264}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"ush_node_object", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !7, i64 8}
!16 = !{!"ush_descriptor", !7, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 56}
!17 = !{!6, !11, i64 56}
!18 = !{!8, !8, i64 0}
!19 = !{!16, !11, i64 16}


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