; LLVM IR from quantumlib/qsim :: apps/qsim_base.ll (Z10GetOptionsiPPc)

; 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.Options = type <{ %"class.std::__cxx11::basic_string", i32, i32, i32, i32, i32, i8, [3 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@optarg = external global ptr, align 8
@_ZL5usage = external hidden constant [97 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10GetOptionsiPPc(ptr dead_on_unwind noalias writable sret(%struct.Options) align 8 %0, i32 noundef %1, ptr noundef %2) #0 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i1, align 1
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  store i1 false, ptr %7, align 1
  call void @_ZN7OptionsC2Ev(ptr noundef nonnull align 8 dereferenceable(53) %0) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  br label %11

11:                                               ; preds = %51, %3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = call i32 @getopt(i32 noundef %12, ptr noundef %13, ptr noundef @.str) #7
  store i32 %14, ptr %8, align 4, !tbaa !5
  %15 = icmp ne i32 %14, -1
  br i1 %15, label %16, label %52

16:                                               ; preds = %11
  %17 = load i32, ptr %8, align 4, !tbaa !5
  switch i32 %17, label %49 [
    i32 99, label %18
    i32 100, label %27
    i32 115, label %31
    i32 116, label %35
    i32 102, label %39
    i32 118, label %43
    i32 122, label %47
  ]

18:                                               ; preds = %16
  %19 = load ptr, ptr @optarg, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 0
  %21 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32) %20, ptr noundef %19)
          to label %22 unwind label %23

22:                                               ; preds = %18
  br label %51

23:                                               ; preds = %49, %18
  %24 = landingpad { ptr, i32 }
          cleanup
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %9, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @_ZN7OptionsD2Ev(ptr noundef nonnull align 8 dereferenceable(53) %0) #7
  br label %56

27:                                               ; preds = %16
  %28 = load ptr, ptr @optarg, align 8, !tbaa !9
  %29 = call i32 @atoi(ptr noundef %28) #8
  %30 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 1
  store i32 %29, ptr %30, align 8, !tbaa !11
  br label %51

31:                                               ; preds = %16
  %32 = load ptr, ptr @optarg, align 8, !tbaa !9
  %33 = call i32 @atoi(ptr noundef %32) #8
  %34 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 2
  store i32 %33, ptr %34, align 4, !tbaa !17
  br label %51

35:                                               ; preds = %16
  %36 = load ptr, ptr @optarg, align 8, !tbaa !9
  %37 = call i32 @atoi(ptr noundef %36) #8
  %38 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 3
  store i32 %37, ptr %38, align 8, !tbaa !18
  br label %51

39:                                               ; preds = %16
  %40 = load ptr, ptr @optarg, align 8, !tbaa !9
  %41 = call i32 @atoi(ptr noundef %40) #8
  %42 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 4
  store i32 %41, ptr %42, align 4, !tbaa !19
  br label %51

43:                                               ; preds = %16
  %44 = load ptr, ptr @optarg, align 8, !tbaa !9
  %45 = call i32 @atoi(ptr noundef %44) #8
  %46 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 5
  store i32 %45, ptr %46, align 8, !tbaa !20
  br label %51

47:                                               ; preds = %16
  %48 = getelementptr inbounds %struct.Options, ptr %0, i32 0, i32 6
  store i8 1, ptr %48, align 4, !tbaa !21
  br label %51

49:                                               ; preds = %16
  invoke void (ptr, ...) @_ZN4qsim2IO6errorfEPKcz(ptr noundef @_ZL5usage)
          to label %50 unwind label %23

50:                                               ; preds = %49
  call void @exit(i32 noundef 1) #9
  unreachable

51:                                               ; preds = %47, %43, %39, %35, %31, %27, %22
  br label %11, !llvm.loop !22

52:                                               ; preds = %11
  store i1 true, ptr %7, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %53 = load i1, ptr %7, align 1
  br i1 %53, label %55, label %54

54:                                               ; preds = %52
  call void @_ZN7OptionsD2Ev(ptr noundef nonnull align 8 dereferenceable(53) %0) #7
  br label %55

55:                                               ; preds = %54, %52
  ret void

56:                                               ; preds = %23
  %57 = load ptr, ptr %9, align 8
  %58 = load i32, ptr %10, align 4
  %59 = insertvalue { ptr, i32 } poison, ptr %57, 0
  %60 = insertvalue { ptr, i32 } %59, i32 %58, 1
  resume { ptr, i32 } %60
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7OptionsC2Ev(ptr noundef nonnull align 8 dereferenceable(53)) unnamed_addr #1 align 2

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

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4qsim2IO6errorfEPKcz(ptr noundef, ...) #5 align 2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #6

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7OptionsD2Ev(ptr noundef nonnull align 8 dereferenceable(53)) unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { inlinehint mustprogress nounwind willreturn memory(read) 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 #5 = { mustprogress 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"_ZTS7Options", !13, i64 0, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !16, i64 52}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!12, !6, i64 36}
!18 = !{!12, !6, i64 40}
!19 = !{!12, !6, i64 44}
!20 = !{!12, !6, i64 48}
!21 = !{!12, !16, i64 52}
!22 = distinct !{!22, !23}
!23 = !{!"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.Options = type <{ %"class.std::__cxx11::basic_string", i32, i32, i32, i32, i32, i8, [3 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@_ZL5usage = external hidden constant [97 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10GetOptionsiPPc(ptr dead_on_unwind noalias nonnull writable sret(%struct.Options) align 8 %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN7OptionsC2Ev(ptr noundef nonnull align 8 dereferenceable(53) %0) #6
  %4 = getelementptr inbounds i8, ptr %0, i64 52
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = getelementptr inbounds i8, ptr %0, i64 44
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = getelementptr inbounds i8, ptr %0, i64 36
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  br label %10

10:                                               ; preds = %.backedge, %3
  %11 = tail call i32 @getopt(i32 noundef %1, ptr noundef %2, ptr noundef nonnull @.str) #6
  switch i32 %11, label %33 [
    i32 -1, label %34
    i32 99, label %12
    i32 100, label %17
    i32 115, label %20
    i32 116, label %23
    i32 102, label %26
    i32 118, label %29
    i32 122, label %32
  ]

12:                                               ; preds = %10
  %13 = load ptr, ptr @optarg, align 8, !tbaa !5
  %14 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %13)
          to label %.backedge unwind label %15

.backedge:                                        ; preds = %12, %32, %29, %26, %23, %20, %17
  br label %10, !llvm.loop !9

15:                                               ; preds = %12
  %16 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN7OptionsD2Ev(ptr noundef nonnull align 8 dereferenceable(53) %0) #6
  resume { ptr, i32 } %16

17:                                               ; preds = %10
  %18 = load ptr, ptr @optarg, align 8, !tbaa !5
  %19 = tail call i32 @atoi(ptr nocapture noundef %18) #7
  store i32 %19, ptr %9, align 8, !tbaa !11
  br label %.backedge

20:                                               ; preds = %10
  %21 = load ptr, ptr @optarg, align 8, !tbaa !5
  %22 = tail call i32 @atoi(ptr nocapture noundef %21) #7
  store i32 %22, ptr %8, align 4, !tbaa !18
  br label %.backedge

23:                                               ; preds = %10
  %24 = load ptr, ptr @optarg, align 8, !tbaa !5
  %25 = tail call i32 @atoi(ptr nocapture noundef %24) #7
  store i32 %25, ptr %7, align 8, !tbaa !19
  br label %.backedge

26:                                               ; preds = %10
  %27 = load ptr, ptr @optarg, align 8, !tbaa !5
  %28 = tail call i32 @atoi(ptr nocapture noundef %27) #7
  store i32 %28, ptr %6, align 4, !tbaa !20
  br label %.backedge

29:                                               ; preds = %10
  %30 = load ptr, ptr @optarg, align 8, !tbaa !5
  %31 = tail call i32 @atoi(ptr nocapture noundef %30) #7
  store i32 %31, ptr %5, align 8, !tbaa !21
  br label %.backedge

32:                                               ; preds = %10
  store i8 1, ptr %4, align 4, !tbaa !22
  br label %.backedge

33:                                               ; preds = %10
  tail call void (ptr, ...) @_ZN4qsim2IO6errorfEPKcz(ptr noundef nonnull @_ZL5usage)
  tail call void @exit(i32 noundef 1) #8
  unreachable

34:                                               ; preds = %10
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7OptionsC2Ev(ptr noundef nonnull align 8 dereferenceable(53)) unnamed_addr #1 align 2

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4qsim2IO6errorfEPKcz(ptr noundef, ...) local_unnamed_addr #4 align 2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7OptionsD2Ev(ptr noundef nonnull align 8 dereferenceable(53)) unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 "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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #4 = { mustprogress 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !16, i64 32}
!12 = !{!"_ZTS7Options", !13, i64 0, !16, i64 32, !16, i64 36, !16, i64 40, !16, i64 44, !16, i64 48, !17, i64 52}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!12, !16, i64 36}
!19 = !{!12, !16, i64 40}
!20 = !{!12, !16, i64 44}
!21 = !{!12, !16, i64 48}
!22 = !{!12, !17, i64 52}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass