; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 5/1493. One Step from Happiness (main)

; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = srem i32 %7, 10
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sdiv i32 %9, 10
  %11 = srem i32 %10, 10
  %12 = add nsw i32 %8, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sdiv i32 %13, 100
  %15 = srem i32 %14, 10
  %16 = add nsw i32 %12, %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sdiv i32 %17, 1000
  %19 = srem i32 %18, 10
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sdiv i32 %20, 10000
  %22 = srem i32 %21, 10
  %23 = add nsw i32 %19, %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sdiv i32 %24, 100000
  %26 = srem i32 %25, 10
  %27 = add nsw i32 %23, %26
  %28 = icmp eq i32 %16, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %0
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %61

31:                                               ; preds = %0
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 2
  store i32 %33, ptr %2, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = srem i32 %34, 10
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sdiv i32 %36, 10
  %38 = srem i32 %37, 10
  %39 = add nsw i32 %35, %38
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sdiv i32 %40, 100
  %42 = srem i32 %41, 10
  %43 = add nsw i32 %39, %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sdiv i32 %44, 1000
  %46 = srem i32 %45, 10
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sdiv i32 %47, 10000
  %49 = srem i32 %48, 10
  %50 = add nsw i32 %46, %49
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sdiv i32 %51, 100000
  %53 = srem i32 %52, 10
  %54 = add nsw i32 %50, %53
  %55 = icmp eq i32 %43, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %31
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  br label %60

58:                                               ; preds = %31
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.1)
  br label %60

60:                                               ; preds = %58, %56
  store i32 0, ptr %3, align 4
  br label %61

61:                                               ; preds = %60, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %62 = load i32, ptr %3, align 4
  switch i32 %62, label %65 [
    i32 0, label %63
    i32 1, label %63
  ]

63:                                               ; preds = %61, %61
  %64 = load i32, ptr %1, align 4
  ret i32 %64

65:                                               ; preds = %61
  unreachable
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

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

attributes #0 = { mustprogress norecurse 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 = { inlinehint 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr %1, align 4, !tbaa !5
  %5 = srem i32 %4, 10
  %6 = sdiv i32 %4, 10
  %7 = srem i32 %6, 10
  %8 = add nsw i32 %7, %5
  %9 = sdiv i32 %4, 100
  %10 = srem i32 %9, 10
  %11 = add nsw i32 %8, %10
  %12 = sdiv i32 %4, 1000
  %13 = srem i32 %12, 10
  %14 = sdiv i32 %4, 10000
  %15 = srem i32 %14, 10
  %16 = add nsw i32 %13, %15
  %17 = sdiv i32 %4, 100000
  %.lhs.trunc = trunc nsw i32 %17 to i16
  %18 = srem i16 %.lhs.trunc, 10
  %.sext = sext i16 %18 to i32
  %19 = add nsw i32 %16, %.sext
  %20 = icmp eq i32 %11, %19
  br i1 %20, label %39, label %21

21:                                               ; preds = %0
  %22 = add nsw i32 %3, -1
  store i32 %22, ptr %1, align 4, !tbaa !5
  %23 = srem i32 %22, 10
  %24 = sdiv i32 %22, 10
  %25 = srem i32 %24, 10
  %26 = add nsw i32 %25, %23
  %27 = sdiv i32 %22, 100
  %28 = srem i32 %27, 10
  %29 = add nsw i32 %26, %28
  %30 = sdiv i32 %22, 1000
  %31 = srem i32 %30, 10
  %32 = sdiv i32 %22, 10000
  %33 = srem i32 %32, 10
  %34 = add nsw i32 %31, %33
  %35 = sdiv i32 %22, 100000
  %.lhs.trunc1 = trunc nsw i32 %35 to i16
  %36 = srem i16 %.lhs.trunc1, 10
  %.sext2 = sext i16 %36 to i32
  %37 = add nsw i32 %34, %.sext2
  %38 = icmp eq i32 %29, %37
  %.str..str.1 = select i1 %38, ptr @.str, ptr @.str.1
  br label %39

39:                                               ; preds = %21, %0
  %.str.sink = phi ptr [ @.str, %0 ], [ %.str..str.1, %21 ]
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull %.str.sink)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) 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 = { mustprogress norecurse 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 = { inlinehint 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass