; LLVM IR from tangjz/acm-icpc :: spoj/DIVCNT1.ll (Z7writelno)

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

@_ZZ7writelnoE4BASE = external hidden global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7writelno(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i128, align 16
  %4 = alloca i128, align 16
  %5 = getelementptr inbounds { i64, i64 }, ptr %3, i32 0, i32 0
  store i64 %0, ptr %5, align 16
  %6 = getelementptr inbounds { i64, i64 }, ptr %3, i32 0, i32 1
  store i64 %1, ptr %6, align 8
  %7 = load i128, ptr %3, align 16, !tbaa !5
  store i128 %7, ptr %4, align 16, !tbaa !5
  %8 = load i128, ptr %4, align 16, !tbaa !5
  %9 = load i64, ptr @_ZZ7writelnoE4BASE, align 8, !tbaa !9
  %10 = zext i64 %9 to i128
  %11 = icmp ult i128 %8, %10
  br i1 %11, label %12, label %16

12:                                               ; preds = %2
  %13 = load i128, ptr %4, align 16, !tbaa !5
  %14 = trunc i128 %13 to i64
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %14)
  br label %28

16:                                               ; preds = %2
  %17 = load i128, ptr %4, align 16, !tbaa !5
  %18 = load i64, ptr @_ZZ7writelnoE4BASE, align 8, !tbaa !9
  %19 = zext i64 %18 to i128
  %20 = udiv i128 %17, %19
  %21 = trunc i128 %20 to i64
  %22 = load i128, ptr %4, align 16, !tbaa !5
  %23 = load i64, ptr @_ZZ7writelnoE4BASE, align 8, !tbaa !9
  %24 = zext i64 %23 to i128
  %25 = urem i128 %22, %24
  %26 = trunc i128 %25 to i64
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %21, i64 noundef %26)
  br label %28

28:                                               ; preds = %16, %12
  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 = !{!"__int128", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long 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"

@_ZZ7writelnoE4BASE = external hidden local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z7writelno(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.sroa.2.0.insert.ext = zext i64 %1 to i128
  %.sroa.2.0.insert.shift = shl nuw i128 %.sroa.2.0.insert.ext, 64
  %.sroa.0.0.insert.ext = zext i64 %0 to i128
  %.sroa.0.0.insert.insert = or disjoint i128 %.sroa.2.0.insert.shift, %.sroa.0.0.insert.ext
  %3 = load i64, ptr @_ZZ7writelnoE4BASE, align 8, !tbaa !5
  %4 = zext i64 %3 to i128
  %5 = icmp ult i128 %.sroa.0.0.insert.insert, %4
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %0)
  br label %14

8:                                                ; preds = %2
  %.frozen = freeze i128 %4
  %9 = udiv i128 %.sroa.0.0.insert.insert, %.frozen
  %10 = trunc i128 %9 to i64
  %11 = mul i128 %9, %.frozen
  %.decomposed = sub i128 %.sroa.0.0.insert.insert, %11
  %12 = trunc nuw i128 %.decomposed to i64
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %10, i64 noundef %12)
  br label %14

14:                                               ; preds = %8, %6
  ret void
}

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


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass