; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/138 Division 1/Problem A/A.ll (Z4openi)

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

%"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] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@n = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@i = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4openi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr @i, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @i, align 4, !tbaa !5
  %10 = load i32, ptr @i, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sge i32 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %104

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -1, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %99, %14
  %16 = load i32, ptr @i, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %102

19:                                               ; preds = %15
  %20 = load i32, ptr @i, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %21)
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 40
  br i1 %25, label %26, label %48

26:                                               ; preds = %19
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = load i32, ptr @i, align 4, !tbaa !5
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29, %26
  %32 = call noundef i32 @_Z4openi(i32 noundef 2)
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = icmp eq i32 %33, -1
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

36:                                               ; preds = %31
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = add nsw i32 %38, %37
  store i32 %39, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr @mx, align 4, !tbaa !5
  %42 = icmp sgt i32 %40, %41
  br i1 %42, label %43, label %47

43:                                               ; preds = %36
  %44 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %44, ptr @l, align 4, !tbaa !5
  %45 = load i32, ptr @i, align 4, !tbaa !5
  store i32 %45, ptr @r, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %46, ptr @mx, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %43, %36
  br label %98

48:                                               ; preds = %19
  %49 = load i32, ptr @i, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %50)
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = sext i8 %52 to i32
  %54 = icmp eq i32 %53, 91
  br i1 %54, label %55, label %77

55:                                               ; preds = %48
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = icmp eq i32 %56, -1
  br i1 %57, label %58, label %60

58:                                               ; preds = %55
  %59 = load i32, ptr @i, align 4, !tbaa !5
  store i32 %59, ptr %6, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %58, %55
  %61 = call noundef i32 @_Z4openi(i32 noundef 1)
  store i32 %61, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = icmp eq i32 %62, -1
  br i1 %63, label %64, label %65

64:                                               ; preds = %60
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

65:                                               ; preds = %60
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = add nsw i32 %67, %66
  store i32 %68, ptr %4, align 4, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = load i32, ptr @mx, align 4, !tbaa !5
  %71 = icmp sgt i32 %69, %70
  br i1 %71, label %72, label %76

72:                                               ; preds = %65
  %73 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %73, ptr @l, align 4, !tbaa !5
  %74 = load i32, ptr @i, align 4, !tbaa !5
  store i32 %74, ptr @r, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %75, ptr @mx, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %72, %65
  br label %97

77:                                               ; preds = %48
  %78 = load i32, ptr @i, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %79)
  %81 = load i8, ptr %80, align 1, !tbaa !9
  %82 = sext i8 %81 to i32
  %83 = icmp eq i32 %82, 41
  br i1 %83, label %84, label %90

84:                                               ; preds = %77
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = icmp eq i32 %85, 1
  br i1 %86, label %87, label %88

87:                                               ; preds = %84
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

88:                                               ; preds = %84
  %89 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %89, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

90:                                               ; preds = %77
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = icmp eq i32 %91, 1
  br i1 %92, label %93, label %96

93:                                               ; preds = %90
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

96:                                               ; preds = %90
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

97:                                               ; preds = %76
  br label %98

98:                                               ; preds = %97, %47
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr @i, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr @i, align 4, !tbaa !5
  br label %15, !llvm.loop !10

102:                                              ; preds = %15
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %103

103:                                              ; preds = %102, %96, %93, %88, %87, %64, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %104

104:                                              ; preds = %103, %13
  %105 = load i32, ptr %2, align 4
  ret i32 %105
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

%"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] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@n = external dso_local local_unnamed_addr global i32, align 4
@mx = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global i32, align 4
@r = external dso_local local_unnamed_addr global i32, align 4
@i = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4openi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @i, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @i, align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp slt i32 %3, %4
  br i1 %.not, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1, %42
  %5 = phi i32 [ %44, %42 ], [ %3, %1 ]
  %.034 = phi i32 [ %.3, %42 ], [ -1, %1 ]
  %.01933 = phi i32 [ %.120, %42 ], [ 0, %1 ]
  %6 = sext i32 %5 to i64
  %7 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %6)
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = icmp eq i8 %8, 40
  %10 = load i32, ptr @i, align 4
  br i1 %9, label %11, label %19

11:                                               ; preds = %.lr.ph
  %12 = tail call noundef i32 @_Z4openi(i32 noundef 2)
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %11
  %15 = icmp eq i32 %.034, -1
  %spec.select = select i1 %15, i32 %10, i32 %.034
  %16 = add nsw i32 %12, %.01933
  %17 = load i32, ptr @mx, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, %17
  %.pre = load i32, ptr @i, align 4, !tbaa !5
  br i1 %18, label %.sink.split, label %42

19:                                               ; preds = %.lr.ph
  %20 = sext i32 %10 to i64
  %21 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %20)
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = icmp eq i8 %22, 91
  %24 = load i32, ptr @i, align 4
  br i1 %23, label %25, label %33

25:                                               ; preds = %19
  %26 = tail call noundef i32 @_Z4openi(i32 noundef 1)
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %.loopexit, label %28

28:                                               ; preds = %25
  %29 = icmp eq i32 %.034, -1
  %spec.select30 = select i1 %29, i32 %24, i32 %.034
  %30 = add nsw i32 %26, %.01933
  %31 = load i32, ptr @mx, align 4, !tbaa !5
  %32 = icmp sgt i32 %30, %31
  %.pre38 = load i32, ptr @i, align 4, !tbaa !5
  br i1 %32, label %.sink.split, label %42

33:                                               ; preds = %19
  %34 = sext i32 %24 to i64
  %35 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %34)
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = icmp eq i8 %36, 41
  %38 = icmp eq i32 %0, 1
  br i1 %37, label %39, label %40

39:                                               ; preds = %33
  %..019 = select i1 %38, i32 -1, i32 %.01933
  br label %.loopexit

40:                                               ; preds = %33
  %41 = add nsw i32 %.01933, 1
  %spec.select31 = select i1 %38, i32 %41, i32 -1
  br label %.loopexit

.sink.split:                                      ; preds = %28, %14
  %spec.select.sink = phi i32 [ %spec.select, %14 ], [ %spec.select30, %28 ]
  %.pre.sink = phi i32 [ %.pre, %14 ], [ %.pre38, %28 ]
  %.sink = phi i32 [ %16, %14 ], [ %30, %28 ]
  store i32 %spec.select.sink, ptr @l, align 4, !tbaa !5
  store i32 %.pre.sink, ptr @r, align 4, !tbaa !5
  store i32 %.sink, ptr @mx, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.sink.split, %14, %28
  %43 = phi i32 [ %.pre, %14 ], [ %.pre38, %28 ], [ %.pre.sink, %.sink.split ]
  %.120 = phi i32 [ %16, %14 ], [ %30, %28 ], [ %.sink, %.sink.split ]
  %.3 = phi i32 [ %spec.select, %14 ], [ %spec.select30, %28 ], [ %spec.select.sink, %.sink.split ]
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @i, align 4, !tbaa !5
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %.lr.ph, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %42, %25, %11, %40, %39, %1
  %.122 = phi i32 [ -1, %1 ], [ %..019, %39 ], [ %spec.select31, %40 ], [ -1, %11 ], [ -1, %25 ], [ -1, %42 ]
  ret i32 %.122
}

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

attributes #0 = { 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" }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass