; LLVM IR from tangjz/acm-icpc :: uvalive/7561.ll (Z5solvev)

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

@buf = external dso_local global [4 x ptr], align 16
@c = external dso_local global [4 x i32], align 16
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = load i32, ptr @c, align 16, !tbaa !5
  %2 = icmp sge i32 %1, 2
  br i1 %2, label %3, label %10

3:                                                ; preds = %0
  %4 = load i32, ptr @c, align 16, !tbaa !5
  %5 = sub nsw i32 %4, 2
  store i32 %5, ptr @c, align 16, !tbaa !5
  %6 = load ptr, ptr @buf, align 16, !tbaa !9
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %6)
  call void @_Z5solvev()
  %8 = load ptr, ptr @buf, align 16, !tbaa !9
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %8)
  br label %55

10:                                               ; preds = %0
  %11 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 1), align 4, !tbaa !5
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %25

13:                                               ; preds = %10
  %14 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 2), align 8, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %25

16:                                               ; preds = %13
  %17 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 1), align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 1), align 4, !tbaa !5
  %19 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 2), align 8, !tbaa !5
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 2), align 8, !tbaa !5
  %21 = load ptr, ptr getelementptr inbounds ([4 x ptr], ptr @buf, i64 0, i64 1), align 8, !tbaa !9
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %21)
  call void @_Z5solvev()
  %23 = load ptr, ptr getelementptr inbounds ([4 x ptr], ptr @buf, i64 0, i64 2), align 16, !tbaa !9
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %23)
  br label %54

25:                                               ; preds = %13, %10
  %26 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 3), align 4, !tbaa !5
  %27 = icmp sge i32 %26, 2
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 3), align 4, !tbaa !5
  %30 = sub nsw i32 %29, 2
  store i32 %30, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 3), align 4, !tbaa !5
  %31 = load ptr, ptr getelementptr inbounds ([4 x ptr], ptr @buf, i64 0, i64 3), align 8, !tbaa !9
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %31)
  call void @_Z5solvev()
  %33 = load ptr, ptr getelementptr inbounds ([4 x ptr], ptr @buf, i64 0, i64 3), align 8, !tbaa !9
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %33)
  br label %53

35:                                               ; preds = %25
  %36 = load i32, ptr @c, align 16, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %35
  %39 = load i32, ptr @c, align 16, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @c, align 16, !tbaa !5
  %41 = load ptr, ptr @buf, align 16, !tbaa !9
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %41)
  br label %52

43:                                               ; preds = %35
  %44 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 3), align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %51

46:                                               ; preds = %43
  %47 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 3), align 4, !tbaa !5
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr getelementptr inbounds ([4 x i32], ptr @c, i64 0, i64 3), align 4, !tbaa !5
  %49 = load ptr, ptr getelementptr inbounds ([4 x ptr], ptr @buf, i64 0, i64 3), align 8, !tbaa !9
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %49)
  br label %51

51:                                               ; preds = %46, %43
  br label %52

52:                                               ; preds = %51, %38
  br label %53

53:                                               ; preds = %52, %28
  br label %54

54:                                               ; preds = %53, %16
  br label %55

55:                                               ; preds = %54, %3
  ret void
}

declare i32 @printf(ptr noundef, ...) #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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@buf = external dso_local local_unnamed_addr global [4 x ptr], align 16
@c = external dso_local local_unnamed_addr global [4 x i32], align 16
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = load i32, ptr @c, align 16, !tbaa !5
  %2 = icmp sgt i32 %1, 1
  br i1 %2, label %4, label %8

common.ret.sink.split:                            ; preds = %4, %13, %21, %26, %29
  %.sink.in = phi ptr [ getelementptr inbounds (i8, ptr @buf, i64 24), %29 ], [ @buf, %26 ], [ getelementptr inbounds (i8, ptr @buf, i64 24), %21 ], [ getelementptr inbounds (i8, ptr @buf, i64 16), %13 ], [ @buf, %4 ]
  %.sink = load ptr, ptr %.sink.in, align 8, !tbaa !9
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %.sink)
  br label %common.ret

common.ret:                                       ; preds = %common.ret.sink.split, %28
  ret void

4:                                                ; preds = %0
  %5 = add nsw i32 %1, -2
  store i32 %5, ptr @c, align 16, !tbaa !5
  %6 = load ptr, ptr @buf, align 16, !tbaa !9
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %6)
  tail call void @_Z5solvev()
  br label %common.ret.sink.split

8:                                                ; preds = %0
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 4), align 4, !tbaa !5
  %10 = icmp ne i32 %9, 0
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 8
  %12 = icmp ne i32 %11, 0
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %13, label %18

13:                                               ; preds = %8
  %14 = add nsw i32 %9, -1
  store i32 %14, ptr getelementptr inbounds (i8, ptr @c, i64 4), align 4, !tbaa !5
  %15 = add nsw i32 %11, -1
  store i32 %15, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 8, !tbaa !5
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @buf, i64 8), align 8, !tbaa !9
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %16)
  tail call void @_Z5solvev()
  br label %common.ret.sink.split

18:                                               ; preds = %8
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 12), align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 1
  br i1 %20, label %21, label %25

21:                                               ; preds = %18
  %22 = add nsw i32 %19, -2
  store i32 %22, ptr getelementptr inbounds (i8, ptr @c, i64 12), align 4, !tbaa !5
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @buf, i64 24), align 8, !tbaa !9
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %23)
  tail call void @_Z5solvev()
  br label %common.ret.sink.split

25:                                               ; preds = %18
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %28, label %26

26:                                               ; preds = %25
  %27 = add nsw i32 %1, -1
  store i32 %27, ptr @c, align 16, !tbaa !5
  br label %common.ret.sink.split

28:                                               ; preds = %25
  %.not5 = icmp eq i32 %19, 0
  br i1 %.not5, label %common.ret, label %29

29:                                               ; preds = %28
  %30 = add nsw i32 %19, -1
  store i32 %30, ptr getelementptr inbounds (i8, ptr @c, i64 12), align 4, !tbaa !5
  br label %common.ret.sink.split
}

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

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

!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}


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