; LLVM IR from EarlGray/language-incubator :: fp/secd (secd)

; 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.secd_parser = type { i32, ptr, i32, i32, [256 x i8], [256 x i8], i32 }

@.str.102 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.103 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.104 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.105 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.106 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.107 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.108 = external hidden unnamed_addr constant [9 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @init_parser(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @lexnext(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @test_lexer() #2 {
  %1 = alloca %struct.secd_parser, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 544, ptr %1) #3
  %4 = call ptr @init_parser(ptr noundef %1, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  br label %5

5:                                                ; preds = %27, %0
  %6 = call i32 @lexnext(ptr noundef %1)
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = icmp ne i32 -1, %6
  br i1 %7, label %8, label %28

8:                                                ; preds = %5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %9, label %24 [
    i32 -2, label %10
    i32 -3, label %14
    i32 -4, label %18
    i32 40, label %20
    i32 41, label %22
  ]

10:                                               ; preds = %8
  %11 = getelementptr inbounds %struct.secd_parser, ptr %1, i32 0, i32 4
  %12 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 0
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.102, ptr noundef %12)
  br label %27

14:                                               ; preds = %8
  %15 = getelementptr inbounds %struct.secd_parser, ptr %1, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.103, i32 noundef %16)
  br label %27

18:                                               ; preds = %8
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.104)
  store i32 1, ptr %3, align 4
  br label %30

20:                                               ; preds = %8
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.105)
  br label %27

22:                                               ; preds = %8
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.106)
  br label %27

24:                                               ; preds = %8
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.107, i32 noundef %25)
  br label %27

27:                                               ; preds = %24, %22, %20, %14, %10
  br label %5, !llvm.loop !12

28:                                               ; preds = %5
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.108)
  store i32 0, ptr %3, align 4
  br label %30

30:                                               ; preds = %28, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 544, ptr %1) #3
  %31 = load i32, ptr %3, align 4
  switch i32 %31, label %33 [
    i32 0, label %32
    i32 1, label %32
  ]

32:                                               ; preds = %30, %30
  ret void

33:                                               ; preds = %30
  unreachable
}

attributes #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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 20}
!10 = !{!"secd_parser", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 280, !6, i64 536}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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.secd_parser = type { i32, ptr, i32, i32, [256 x i8], [256 x i8], i32 }

@.str.102 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.103 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.104 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.105 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.106 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.107 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.108 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @init_parser(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @lexnext(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @test_lexer() local_unnamed_addr #2 {
  %1 = alloca %struct.secd_parser, align 8
  call void @llvm.lifetime.start.p0(i64 544, ptr nonnull %1) #3
  %2 = call ptr @init_parser(ptr noundef nonnull %1, ptr noundef null)
  %3 = getelementptr inbounds i8, ptr %1, i64 20
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  br label %5

5:                                                ; preds = %.backedge, %0
  %6 = call i32 @lexnext(ptr noundef nonnull %1)
  switch i32 %6, label %16 [
    i32 -1, label %.loopexit2
    i32 -2, label %7
    i32 -3, label %9
    i32 -4, label %.loopexit
    i32 40, label %12
    i32 41, label %14
  ]

7:                                                ; preds = %5
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.102, ptr noundef nonnull %4)
  br label %.backedge

9:                                                ; preds = %5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.103, i32 noundef %10)
  br label %.backedge

12:                                               ; preds = %5
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.105)
  br label %.backedge

14:                                               ; preds = %5
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.106)
  br label %.backedge

16:                                               ; preds = %5
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.107, i32 noundef %6)
  br label %.backedge

.backedge:                                        ; preds = %16, %14, %12, %9, %7
  br label %5, !llvm.loop !11

.loopexit2:                                       ; preds = %5
  br label %.loopexit

.loopexit:                                        ; preds = %5, %.loopexit2
  %.str.108.sink = phi ptr [ @.str.108, %.loopexit2 ], [ @.str.104, %5 ]
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.108.sink)
  call void @llvm.lifetime.end.p0(i64 544, ptr nonnull %1) #3
  ret void
}

attributes #0 = { nofree 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !7, i64 20}
!6 = !{!"secd_parser", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !8, i64 24, !8, i64 280, !7, i64 536}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass