; LLVM IR from DionysiosB/CodeForces :: 0200-0299 (228A-IsYourHorseShoeOnTheOtherHoof)

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [4 x i64], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %0
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 4
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 0
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i64, ptr %10, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %13)
  br label %15

15:                                               ; preds = %9
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !9

18:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  %19 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 1
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 0
  %22 = load i64, ptr %21, align 16, !tbaa !11
  %23 = icmp eq i64 %20, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %18
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %24, %18
  %28 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 2
  %29 = load i64, ptr %28, align 16, !tbaa !11
  %30 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 0
  %31 = load i64, ptr %30, align 16, !tbaa !11
  %32 = icmp eq i64 %29, %31
  br i1 %32, label %39, label %33

33:                                               ; preds = %27
  %34 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 2
  %35 = load i64, ptr %34, align 16, !tbaa !11
  %36 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 1
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = icmp eq i64 %35, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %33, %27
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %39, %33
  %43 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 3
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 0
  %46 = load i64, ptr %45, align 16, !tbaa !11
  %47 = icmp eq i64 %44, %46
  br i1 %47, label %60, label %48

48:                                               ; preds = %42
  %49 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 3
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 1
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = icmp eq i64 %50, %52
  br i1 %53, label %60, label %54

54:                                               ; preds = %48
  %55 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 3
  %56 = load i64, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds [4 x i64], ptr %2, i64 0, i64 2
  %58 = load i64, ptr %57, align 16, !tbaa !11
  %59 = icmp eq i64 %56, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %54, %48, %42
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %60, %54
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %64)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #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 i32 @__isoc99_scanf(ptr noundef, ...) #2

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

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

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [4 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %7)
  %9 = load i64, ptr %3, align 8
  %10 = load i64, ptr %1, align 16, !tbaa !5
  %11 = icmp eq i64 %9, %10
  %spec.select = zext i1 %11 to i32
  %12 = load i64, ptr %5, align 16
  %13 = icmp eq i64 %12, %10
  %14 = icmp eq i64 %12, %9
  %or.cond = or i1 %13, %14
  %15 = select i1 %11, i32 2, i32 1
  %.1 = select i1 %or.cond, i32 %15, i32 %spec.select
  %16 = load i64, ptr %7, align 8, !tbaa !5
  %17 = icmp eq i64 %16, %10
  %18 = icmp eq i64 %16, %9
  %or.cond12 = or i1 %17, %18
  %19 = icmp eq i64 %16, %12
  %or.cond14 = or i1 %19, %or.cond12
  %20 = zext i1 %or.cond14 to i32
  %.2 = add nuw nsw i32 %.1, %20
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.2)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #3
  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

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

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

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass