; LLVM IR from google/latency-benchmark :: src/win (getopt)

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

@optarg = external dso_local global ptr, align 8
@optind = external dso_local global i32, align 4
@opterr = external dso_local global i32, align 4
@getopt.pIndexPosition = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@optopt = external dso_local global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %21

13:                                               ; preds = %3
  %14 = load ptr, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %14, i32 1
  store ptr %15, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  %19 = load ptr, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  store ptr %19, ptr %8, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %18, %13
  br label %21

21:                                               ; preds = %20, %3
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %60

24:                                               ; preds = %21
  %25 = load i32, ptr @optind, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp sge i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = load i32, ptr @optind, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr @optind, align 4, !tbaa !5
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds ptr, ptr %30, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  store ptr %35, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 47, %38
  br i1 %39, label %40, label %48

40:                                               ; preds = %29
  %41 = load ptr, ptr %8, align 8, !tbaa !9
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 45, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load i32, ptr @optind, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr @optind, align 4, !tbaa !5
  store ptr null, ptr @optarg, align 8, !tbaa !9
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

48:                                               ; preds = %40, %29
  %49 = load ptr, ptr %8, align 8, !tbaa !9
  %50 = call i32 @strcmp(ptr noundef %49, ptr noundef @.str) #4
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %56, label %52

52:                                               ; preds = %48
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = call i32 @strcmp(ptr noundef %53, ptr noundef @.str.1) #4
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %52, %48
  store ptr null, ptr @optarg, align 8, !tbaa !9
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

57:                                               ; preds = %52
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %8, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %57, %21
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = icmp eq i32 58, %63
  br i1 %64, label %65, label %72

65:                                               ; preds = %60
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = load i8, ptr %66, align 1, !tbaa !11
  store i8 %67, ptr @optopt, align 1, !tbaa !11
  %68 = load i32, ptr @opterr, align 4, !tbaa !5
  %69 = icmp ne i32 %68, 0
  %70 = zext i1 %69 to i64
  %71 = select i1 %69, i32 63, i32 58
  store i32 %71, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

72:                                               ; preds = %60
  %73 = load ptr, ptr %7, align 8, !tbaa !9
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = sext i8 %75 to i32
  %77 = call ptr @strchr(ptr noundef %73, i32 noundef %76) #4
  store ptr %77, ptr %9, align 8, !tbaa !9
  %78 = icmp eq ptr %77, null
  br i1 %78, label %79, label %91

79:                                               ; preds = %72
  store ptr null, ptr @optarg, align 8, !tbaa !9
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  %80 = load ptr, ptr %8, align 8, !tbaa !9
  %81 = load i8, ptr %80, align 1, !tbaa !11
  store i8 %81, ptr @optopt, align 1, !tbaa !11
  %82 = load i32, ptr @opterr, align 4, !tbaa !5
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %85

84:                                               ; preds = %79
  br label %89

85:                                               ; preds = %79
  %86 = load ptr, ptr %8, align 8, !tbaa !9
  %87 = load i8, ptr %86, align 1, !tbaa !11
  %88 = sext i8 %87 to i32
  br label %89

89:                                               ; preds = %85, %84
  %90 = phi i32 [ 63, %84 ], [ %88, %85 ]
  store i32 %90, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

91:                                               ; preds = %72
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  %93 = getelementptr inbounds i8, ptr %92, i64 1
  %94 = load i8, ptr %93, align 1, !tbaa !11
  %95 = sext i8 %94 to i32
  %96 = icmp eq i32 58, %95
  br i1 %96, label %97, label %131

97:                                               ; preds = %91
  %98 = load ptr, ptr %8, align 8, !tbaa !9
  %99 = getelementptr inbounds i8, ptr %98, i64 1
  %100 = load i8, ptr %99, align 1, !tbaa !11
  %101 = sext i8 %100 to i32
  %102 = icmp ne i32 0, %101
  br i1 %102, label %103, label %106

103:                                              ; preds = %97
  %104 = load ptr, ptr %8, align 8, !tbaa !9
  %105 = getelementptr inbounds i8, ptr %104, i64 1
  store ptr %105, ptr @optarg, align 8, !tbaa !9
  br label %130

106:                                              ; preds = %97
  %107 = load i32, ptr @optind, align 4, !tbaa !5
  %108 = load i32, ptr %5, align 4, !tbaa !5
  %109 = icmp slt i32 %107, %108
  br i1 %109, label %110, label %117

110:                                              ; preds = %106
  %111 = load ptr, ptr %6, align 8, !tbaa !9
  %112 = load i32, ptr @optind, align 4, !tbaa !5
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr @optind, align 4, !tbaa !5
  %114 = sext i32 %112 to i64
  %115 = getelementptr inbounds ptr, ptr %111, i64 %114
  %116 = load ptr, ptr %115, align 8, !tbaa !9
  store ptr %116, ptr @optarg, align 8, !tbaa !9
  br label %129

117:                                              ; preds = %106
  store ptr null, ptr @optarg, align 8, !tbaa !9
  %118 = load ptr, ptr %8, align 8, !tbaa !9
  %119 = load i8, ptr %118, align 1, !tbaa !11
  store i8 %119, ptr @optopt, align 1, !tbaa !11
  %120 = load i32, ptr @opterr, align 4, !tbaa !5
  %121 = icmp ne i32 %120, 0
  br i1 %121, label %122, label %123

122:                                              ; preds = %117
  br label %127

123:                                              ; preds = %117
  %124 = load ptr, ptr %8, align 8, !tbaa !9
  %125 = load i8, ptr %124, align 1, !tbaa !11
  %126 = sext i8 %125 to i32
  br label %127

127:                                              ; preds = %123, %122
  %128 = phi i32 [ 63, %122 ], [ %126, %123 ]
  store i32 %128, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

129:                                              ; preds = %110
  br label %130

130:                                              ; preds = %129, %103
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  br label %133

131:                                              ; preds = %91
  store ptr null, ptr @optarg, align 8, !tbaa !9
  %132 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %132, ptr @getopt.pIndexPosition, align 8, !tbaa !9
  br label %133

133:                                              ; preds = %131, %130
  %134 = load ptr, ptr %8, align 8, !tbaa !9
  %135 = load i8, ptr %134, align 1, !tbaa !11
  %136 = sext i8 %135 to i32
  store i32 %136, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %137

137:                                              ; preds = %133, %127, %89, %65, %56, %45, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %138 = load i32, ptr %4, align 4
  ret i32 %138
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 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 = { 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 #3 = { nounwind }
attributes #4 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


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

@optarg = external dso_local local_unnamed_addr global ptr, align 8
@optind = external dso_local local_unnamed_addr global i32, align 4
@opterr = external dso_local local_unnamed_addr global i32, align 4
@getopt.pIndexPosition = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@optopt = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local range(i32 -128, 128) i32 @getopt(i32 noundef %0, ptr nocapture noundef readonly %1, ptr noundef readonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %select.unfold, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 1
  store ptr %6, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %.not30 = icmp eq i8 %7, 0
  br i1 %.not30, label %select.unfold, label %26

select.unfold:                                    ; preds = %5, %3
  %8 = load i32, ptr @optind, align 4, !tbaa !10
  %.not31 = icmp slt i32 %8, %0
  br i1 %.not31, label %10, label %9

9:                                                ; preds = %select.unfold
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  br label %62

10:                                               ; preds = %select.unfold
  %11 = add nsw i32 %8, 1
  store i32 %11, ptr @optind, align 4, !tbaa !10
  %12 = sext i32 %8 to i64
  %13 = getelementptr inbounds ptr, ptr %1, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !9
  switch i8 %15, label %16 [
    i8 47, label %17
    i8 45, label %17
  ]

16:                                               ; preds = %10
  store i32 %8, ptr @optind, align 4, !tbaa !10
  store ptr null, ptr @optarg, align 8, !tbaa !5
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  br label %62

17:                                               ; preds = %10, %10
  %18 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %14, ptr noundef nonnull dereferenceable(1) @.str) #2
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %14, ptr noundef nonnull dereferenceable(1) @.str.1) #2
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %17
  store ptr null, ptr @optarg, align 8, !tbaa !5
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  br label %62

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %14, i64 1
  %.pr = load i8, ptr %25, align 1, !tbaa !9
  br label %26

26:                                               ; preds = %5, %24
  %27 = phi i8 [ %7, %5 ], [ %.pr, %24 ]
  %.1 = phi ptr [ %6, %5 ], [ %25, %24 ]
  %28 = icmp eq i8 %27, 58
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  store i8 58, ptr @optopt, align 1, !tbaa !9
  %30 = load i32, ptr @opterr, align 4, !tbaa !10
  %.not39 = icmp eq i32 %30, 0
  %31 = select i1 %.not39, i32 58, i32 63
  br label %62

32:                                               ; preds = %26
  %33 = sext i8 %27 to i32
  %34 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %2, i32 noundef %33) #2
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %40

36:                                               ; preds = %32
  store ptr null, ptr @optarg, align 8, !tbaa !5
  store ptr null, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  %37 = load i8, ptr %.1, align 1, !tbaa !9
  store i8 %37, ptr @optopt, align 1, !tbaa !9
  %38 = load i32, ptr @opterr, align 4, !tbaa !10
  %.not38 = icmp eq i32 %38, 0
  %39 = sext i8 %37 to i32
  %spec.select = select i1 %.not38, i32 %39, i32 63
  br label %62

40:                                               ; preds = %32
  %41 = getelementptr inbounds i8, ptr %34, i64 1
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = icmp eq i8 %42, 58
  br i1 %43, label %44, label %59

44:                                               ; preds = %40
  %45 = getelementptr inbounds i8, ptr %.1, i64 1
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %.not34 = icmp eq i8 %46, 0
  br i1 %.not34, label %47, label %59

47:                                               ; preds = %44
  %48 = load i32, ptr @optind, align 4, !tbaa !10
  %49 = icmp slt i32 %48, %0
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = add nsw i32 %48, 1
  store i32 %51, ptr @optind, align 4, !tbaa !10
  %52 = sext i32 %48 to i64
  %53 = getelementptr inbounds ptr, ptr %1, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  br label %59

55:                                               ; preds = %47
  store ptr null, ptr @optarg, align 8, !tbaa !5
  %56 = load i8, ptr %.1, align 1, !tbaa !9
  store i8 %56, ptr @optopt, align 1, !tbaa !9
  %57 = load i32, ptr @opterr, align 4, !tbaa !10
  %.not35 = icmp eq i32 %57, 0
  %58 = sext i8 %56 to i32
  %spec.select41 = select i1 %.not35, i32 %58, i32 63
  br label %62

59:                                               ; preds = %40, %50, %44
  %storemerge37 = phi ptr [ %54, %50 ], [ %45, %44 ], [ null, %40 ]
  %storemerge = phi ptr [ null, %50 ], [ null, %44 ], [ %.1, %40 ]
  store ptr %storemerge37, ptr @optarg, align 8, !tbaa !5
  store ptr %storemerge, ptr @getopt.pIndexPosition, align 8, !tbaa !5
  %60 = load i8, ptr %.1, align 1, !tbaa !9
  %61 = sext i8 %60 to i32
  br label %62

62:                                               ; preds = %55, %36, %59, %29, %23, %16, %9
  %.0 = phi i32 [ -1, %9 ], [ -1, %16 ], [ -1, %23 ], [ %31, %29 ], [ %61, %59 ], [ %spec.select, %36 ], [ %spec.select41, %55 ]
  ret i32 %.0
}

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

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

attributes #0 = { mustprogress nofree nounwind willreturn memory(readwrite, argmem: read, 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" }
attributes #1 = { 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 #2 = { 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 = !{!"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 = !{!"int", !7, i64 0}


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