; LLVM IR from tezc/sc :: option (option_test)

; 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.sc_option_item = type { i8, ptr }
%struct.sc_option = type { ptr, i32, ptr }

@__const.test1.argv = external hidden unnamed_addr constant [5 x ptr], align 16
@options = external hidden global [4 x %struct.sc_option_item], align 16
@.str.5 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.test1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test1() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca [5 x ptr], align 16
  %4 = alloca %struct.sc_option, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 5, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.test1.argv, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #6
  %7 = getelementptr inbounds %struct.sc_option, ptr %4, i32 0, i32 0
  store ptr @options, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.sc_option, ptr %4, i32 0, i32 1
  store i32 4, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds %struct.sc_option, ptr %4, i32 0, i32 2
  %10 = getelementptr inbounds [5 x ptr], ptr %3, i64 0, i64 0
  store ptr %10, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %55, %0
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %58

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #6
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = call signext i8 @sc_option_at(ptr noundef %4, i32 noundef %17, ptr noundef %1)
  store i8 %18, ptr %6, align 1, !tbaa !14
  %19 = load i8, ptr %6, align 1, !tbaa !14
  %20 = sext i8 %19 to i32
  switch i32 %20, label %53 [
    i32 115, label %21
    i32 109, label %29
    i32 107, label %37
    i32 104, label %44
    i32 63, label %52
  ]

21:                                               ; preds = %16
  %22 = load ptr, ptr %1, align 8, !tbaa !15
  %23 = load i8, ptr %22, align 1, !tbaa !14
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  br label %28

27:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 27, ptr noundef @__PRETTY_FUNCTION__.test1) #7
  unreachable

28:                                               ; preds = %26
  br label %54

29:                                               ; preds = %16
  %30 = load ptr, ptr %1, align 8, !tbaa !15
  %31 = load i8, ptr %30, align 1, !tbaa !14
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  br label %36

35:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 30, ptr noundef @__PRETTY_FUNCTION__.test1) #7
  unreachable

36:                                               ; preds = %34
  br label %54

37:                                               ; preds = %16
  %38 = load ptr, ptr %1, align 8, !tbaa !15
  %39 = call i32 @strcmp(ptr noundef %38, ptr noundef @.str.7) #8
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  br label %43

42:                                               ; preds = %37
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.6, i32 noundef 33, ptr noundef @__PRETTY_FUNCTION__.test1) #7
  unreachable

43:                                               ; preds = %41
  br label %54

44:                                               ; preds = %16
  %45 = load ptr, ptr %1, align 8, !tbaa !15
  %46 = load i8, ptr %45, align 1, !tbaa !14
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  br label %51

50:                                               ; preds = %44
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 36, ptr noundef @__PRETTY_FUNCTION__.test1) #7
  unreachable

51:                                               ; preds = %49
  br label %54

52:                                               ; preds = %16
  br label %53

53:                                               ; preds = %52, %16
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.6, i32 noundef 40, ptr noundef @__PRETTY_FUNCTION__.test1) #7
  unreachable

54:                                               ; preds = %51, %43, %36, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #6
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !5
  br label %11, !llvm.loop !16

58:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare signext i8 @sc_option_at(ptr noundef, i32 noundef, ptr noundef) #3

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #5

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind willreturn memory(read) }

!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, !11, i64 0}
!10 = !{!"sc_option", !11, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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.sc_option_item = type { i8, ptr }
%struct.sc_option = type { ptr, i32, ptr }

@__const.test1.argv = external hidden unnamed_addr constant [5 x ptr], align 16
@options = external hidden global [4 x %struct.sc_option_item], align 16
@.str.5 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.test1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test1() local_unnamed_addr #0 {
  %1 = alloca ptr, align 8
  %2 = alloca [5 x ptr], align 16
  %3 = alloca %struct.sc_option, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %2, ptr noundef nonnull align 16 dereferenceable(40) @__const.test1.argv, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #6
  store ptr @options, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 4, ptr %4, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %2, ptr %5, align 8, !tbaa !12
  %6 = call signext i8 @sc_option_at(ptr noundef nonnull %3, i32 noundef 1, ptr noundef nonnull %1) #6
  switch i8 %6, label %27 [
    i8 115, label %7
    i8 109, label %12
    i8 107, label %17
    i8 104, label %22
  ]

7:                                                ; preds = %0
  %8 = load ptr, ptr %1, align 8, !tbaa !13
  %9 = load i8, ptr %8, align 1, !tbaa !14
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %28, label %11

11:                                               ; preds = %78, %60, %42, %7
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, i32 noundef 27, ptr noundef nonnull @__PRETTY_FUNCTION__.test1) #7
  unreachable

12:                                               ; preds = %0
  %13 = load ptr, ptr %1, align 8, !tbaa !13
  %14 = load i8, ptr %13, align 1, !tbaa !14
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %28, label %16

16:                                               ; preds = %74, %56, %38, %12
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, i32 noundef 30, ptr noundef nonnull @__PRETTY_FUNCTION__.test1) #7
  unreachable

17:                                               ; preds = %0
  %18 = load ptr, ptr %1, align 8, !tbaa !13
  %19 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %18, ptr noundef nonnull dereferenceable(1) @.str.7) #8
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %28, label %21

21:                                               ; preds = %70, %52, %34, %17
  call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.6, i32 noundef 33, ptr noundef nonnull @__PRETTY_FUNCTION__.test1) #7
  unreachable

22:                                               ; preds = %0
  %23 = load ptr, ptr %1, align 8, !tbaa !13
  %24 = load i8, ptr %23, align 1, !tbaa !14
  %25 = icmp eq i8 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %66, %48, %30, %22
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, i32 noundef 36, ptr noundef nonnull @__PRETTY_FUNCTION__.test1) #7
  unreachable

27:                                               ; preds = %64, %46, %28, %0
  call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.6, i32 noundef 40, ptr noundef nonnull @__PRETTY_FUNCTION__.test1) #7
  unreachable

28:                                               ; preds = %22, %17, %12, %7
  %29 = call signext i8 @sc_option_at(ptr noundef nonnull %3, i32 noundef 2, ptr noundef nonnull %1) #6
  switch i8 %29, label %27 [
    i8 115, label %42
    i8 109, label %38
    i8 107, label %34
    i8 104, label %30
  ]

30:                                               ; preds = %28
  %31 = load ptr, ptr %1, align 8, !tbaa !13
  %32 = load i8, ptr %31, align 1, !tbaa !14
  %33 = icmp eq i8 %32, 0
  br i1 %33, label %46, label %26

34:                                               ; preds = %28
  %35 = load ptr, ptr %1, align 8, !tbaa !13
  %36 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %35, ptr noundef nonnull dereferenceable(1) @.str.7) #8
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %46, label %21

38:                                               ; preds = %28
  %39 = load ptr, ptr %1, align 8, !tbaa !13
  %40 = load i8, ptr %39, align 1, !tbaa !14
  %41 = icmp eq i8 %40, 0
  br i1 %41, label %46, label %16

42:                                               ; preds = %28
  %43 = load ptr, ptr %1, align 8, !tbaa !13
  %44 = load i8, ptr %43, align 1, !tbaa !14
  %45 = icmp eq i8 %44, 0
  br i1 %45, label %46, label %11

46:                                               ; preds = %42, %38, %34, %30
  %47 = call signext i8 @sc_option_at(ptr noundef nonnull %3, i32 noundef 3, ptr noundef nonnull %1) #6
  switch i8 %47, label %27 [
    i8 115, label %60
    i8 109, label %56
    i8 107, label %52
    i8 104, label %48
  ]

48:                                               ; preds = %46
  %49 = load ptr, ptr %1, align 8, !tbaa !13
  %50 = load i8, ptr %49, align 1, !tbaa !14
  %51 = icmp eq i8 %50, 0
  br i1 %51, label %64, label %26

52:                                               ; preds = %46
  %53 = load ptr, ptr %1, align 8, !tbaa !13
  %54 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %53, ptr noundef nonnull dereferenceable(1) @.str.7) #8
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %64, label %21

56:                                               ; preds = %46
  %57 = load ptr, ptr %1, align 8, !tbaa !13
  %58 = load i8, ptr %57, align 1, !tbaa !14
  %59 = icmp eq i8 %58, 0
  br i1 %59, label %64, label %16

60:                                               ; preds = %46
  %61 = load ptr, ptr %1, align 8, !tbaa !13
  %62 = load i8, ptr %61, align 1, !tbaa !14
  %63 = icmp eq i8 %62, 0
  br i1 %63, label %64, label %11

64:                                               ; preds = %60, %56, %52, %48
  %65 = call signext i8 @sc_option_at(ptr noundef nonnull %3, i32 noundef 4, ptr noundef nonnull %1) #6
  switch i8 %65, label %27 [
    i8 115, label %78
    i8 109, label %74
    i8 107, label %70
    i8 104, label %66
  ]

66:                                               ; preds = %64
  %67 = load ptr, ptr %1, align 8, !tbaa !13
  %68 = load i8, ptr %67, align 1, !tbaa !14
  %69 = icmp eq i8 %68, 0
  br i1 %69, label %82, label %26

70:                                               ; preds = %64
  %71 = load ptr, ptr %1, align 8, !tbaa !13
  %72 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %71, ptr noundef nonnull dereferenceable(1) @.str.7) #8
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %82, label %21

74:                                               ; preds = %64
  %75 = load ptr, ptr %1, align 8, !tbaa !13
  %76 = load i8, ptr %75, align 1, !tbaa !14
  %77 = icmp eq i8 %76, 0
  br i1 %77, label %82, label %16

78:                                               ; preds = %64
  %79 = load ptr, ptr %1, align 8, !tbaa !13
  %80 = load i8, ptr %79, align 1, !tbaa !14
  %81 = icmp eq i8 %80, 0
  br i1 %81, label %82, label %11

82:                                               ; preds = %78, %74, %70, %66
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret void
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare signext i8 @sc_option_at(ptr noundef, i32 noundef, ptr 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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind willreturn memory(read) }

!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 0}
!6 = !{!"sc_option", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass