; LLVM IR from tangjz/acm-icpc :: codeforces/gym/100624K.ll (Z3idxi)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@out = external dso_local global [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3idxi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sle i32 %3, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  %6 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @out, ptr noundef @.str.5) #2
  br label %65

7:                                                ; preds = %1
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %11, label %14

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @out, ptr noundef @.str.6, i32 noundef %12) #2
  br label %64

14:                                               ; preds = %7
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = load i32, ptr @k, align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  %19 = icmp sle i32 %15, %18
  br i1 %19, label %20, label %25

20:                                               ; preds = %14
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sub nsw i32 %21, %22
  %24 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @out, ptr noundef @.str.7, i32 noundef %23) #2
  br label %63

25:                                               ; preds = %14
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = load i32, ptr @k, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = icmp sle i32 %26, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %25
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sub nsw i32 %34, %35
  %37 = load i32, ptr @k, align 4, !tbaa !5
  %38 = sub nsw i32 %36, %37
  %39 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @out, ptr noundef @.str.8, i32 noundef %38) #2
  br label %62

40:                                               ; preds = %25
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = load i32, ptr @k, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = load i32, ptr @k, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  %49 = icmp sle i32 %41, %48
  br i1 %49, label %50, label %59

50:                                               ; preds = %40
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  %54 = load i32, ptr @k, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = sub nsw i32 %55, %56
  %58 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @out, ptr noundef @.str.9, i32 noundef %57) #2
  br label %61

59:                                               ; preds = %40
  %60 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @out, ptr noundef @.str.10) #2
  br label %61

61:                                               ; preds = %59, %50
  br label %62

62:                                               ; preds = %61, %33
  br label %63

63:                                               ; preds = %62, %20
  br label %64

64:                                               ; preds = %63, %11
  br label %65

65:                                               ; preds = %64, %5
  ret void
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #1

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

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local local_unnamed_addr global i32, align 4
@out = external dso_local global [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z3idxi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 1
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @out, ptr noundef nonnull dereferenceable(1) @.str.5) #2
  br label %28

5:                                                ; preds = %1
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp slt i32 %6, %0
  br i1 %.not, label %9, label %7

7:                                                ; preds = %5
  %8 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @out, ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %0) #2
  br label %28

9:                                                ; preds = %5
  %10 = load i32, ptr @k, align 4, !tbaa !5
  %11 = add nsw i32 %10, %6
  %.not12 = icmp slt i32 %11, %0
  br i1 %.not12, label %15, label %12

12:                                               ; preds = %9
  %13 = sub nsw i32 %0, %6
  %14 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @out, ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %13) #2
  br label %28

15:                                               ; preds = %9
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = add nsw i32 %16, %11
  %.not13 = icmp slt i32 %17, %0
  br i1 %.not13, label %21, label %18

18:                                               ; preds = %15
  %19 = sub i32 %0, %11
  %20 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @out, ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %19) #2
  br label %28

21:                                               ; preds = %15
  %22 = add nsw i32 %17, %10
  %.not14 = icmp slt i32 %22, %0
  br i1 %.not14, label %26, label %23

23:                                               ; preds = %21
  %24 = sub i32 %0, %17
  %25 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @out, ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %24) #2
  br label %28

26:                                               ; preds = %21
  %27 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @out, ptr noundef nonnull dereferenceable(1) @.str.10) #2
  br label %28

28:                                               ; preds = %7, %18, %26, %23, %12, %3
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, 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" }
attributes #2 = { 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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass