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

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

@options = external hidden global [3 x %struct.sc_option_item], align 16
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.sc_option, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  %10 = getelementptr inbounds %struct.sc_option, ptr %7, i32 0, i32 0
  store ptr @options, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.sc_option, ptr %7, i32 0, i32 1
  store i32 3, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.sc_option, ptr %7, i32 0, i32 2
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %13, ptr %12, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %41, %2
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %44

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = call signext i8 @sc_option_at(ptr noundef %7, i32 noundef %20, ptr noundef %6)
  store i8 %21, ptr %9, align 1, !tbaa !15
  %22 = load i8, ptr %9, align 1, !tbaa !15
  %23 = sext i8 %22 to i32
  switch i32 %23, label %40 [
    i32 109, label %24
    i32 107, label %27
    i32 104, label %30
    i32 63, label %33
  ]

24:                                               ; preds = %19
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %25)
  br label %40

27:                                               ; preds = %19
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %28)
  br label %40

30:                                               ; preds = %19
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %31)
  br label %40

33:                                               ; preds = %19
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %38)
  br label %40

40:                                               ; preds = %33, %30, %27, %24, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !16

44:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  ret i32 0
}

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

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

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

; 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 = { "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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"sc_option", !10, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!7, !7, 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 }

@options = external hidden global [3 x %struct.sc_option_item], align 16
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.sc_option, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  store ptr @options, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 3, ptr %5, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %1, ptr %6, align 8, !tbaa !12
  %7 = icmp sgt i32 %0, 1
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %23, %2
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %23 ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = call signext i8 @sc_option_at(ptr noundef nonnull %4, i32 noundef %8, ptr noundef nonnull %3) #4
  switch i8 %9, label %23 [
    i8 109, label %10
    i8 107, label %13
    i8 104, label %16
    i8 63, label %19
  ]

10:                                               ; preds = %.lr.ph
  %11 = load ptr, ptr %3, align 8, !tbaa !13
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %11)
  br label %23

13:                                               ; preds = %.lr.ph
  %14 = load ptr, ptr %3, align 8, !tbaa !13
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %14)
  br label %23

16:                                               ; preds = %.lr.ph
  %17 = load ptr, ptr %3, align 8, !tbaa !13
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %17)
  br label %23

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %21)
  br label %23

23:                                               ; preds = %19, %16, %13, %10, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14
}

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

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

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

; 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 = { "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 = { 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 #4 = { 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 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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass