; LLVM IR from albertobsd/keyhunt :: gmp256k1/Int.ll (ZN3Int3DivEPS_S0_)

; 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.Int = type { [1 x %struct.__mpz_struct] }
%struct.__mpz_struct = type { i32, i32, ptr }

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @__gmpz_cmp(ptr noundef, ptr noundef) #0

declare void @__gmpz_set_ui(ptr noundef, i64 noundef) #1

declare void @__gmpz_set(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3Int3DivEPS_S0_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  %8 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %8, i64 0, i64 0
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.Int, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %11, i64 0, i64 0
  %13 = call i32 @__gmpz_cmp(ptr noundef %9, ptr noundef %12) #3
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %24

18:                                               ; preds = %15
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.Int, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %20, i64 0, i64 0
  %22 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %23 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %22, i64 0, i64 0
  call void @__gmpz_set(ptr noundef %21, ptr noundef %23)
  br label %24

24:                                               ; preds = %18, %15
  call void @_ZN3Int5CLEAREv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  br label %84

25:                                               ; preds = %3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.Int, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %27, i64 0, i64 0
  %29 = getelementptr inbounds %struct.__mpz_struct, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  br label %41

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.Int, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %35, i64 0, i64 0
  %37 = getelementptr inbounds %struct.__mpz_struct, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp sgt i32 %38, 0
  %40 = zext i1 %39 to i32
  br label %41

41:                                               ; preds = %33, %32
  %42 = phi i32 [ -1, %32 ], [ %40, %33 ]
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %84

46:                                               ; preds = %41
  %47 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %48 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %47, i64 0, i64 0
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.Int, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %50, i64 0, i64 0
  %52 = call i32 @__gmpz_cmp(ptr noundef %48, ptr noundef %51) #3
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %62

54:                                               ; preds = %46
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN3Int5CLEAREv(ptr noundef nonnull align 8 dereferenceable(16) %58)
  br label %59

59:                                               ; preds = %57, %54
  %60 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %61 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %60, i64 0, i64 0
  call void @__gmpz_set_ui(ptr noundef %61, i64 noundef 1)
  br label %84

62:                                               ; preds = %46
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %76

65:                                               ; preds = %62
  %66 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %67 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %66, i64 0, i64 0
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.Int, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %69, i64 0, i64 0
  %71 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %72 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %71, i64 0, i64 0
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %class.Int, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %74, i64 0, i64 0
  call void @__gmpz_fdiv_qr(ptr noundef %67, ptr noundef %70, ptr noundef %72, ptr noundef %75)
  br label %84

76:                                               ; preds = %62
  %77 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %78 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %77, i64 0, i64 0
  %79 = getelementptr inbounds %class.Int, ptr %7, i32 0, i32 0
  %80 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %79, i64 0, i64 0
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %class.Int, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %82, i64 0, i64 0
  call void @__gmpz_fdiv_q(ptr noundef %78, ptr noundef %80, ptr noundef %83)
  br label %84

84:                                               ; preds = %76, %65, %59, %44, %24
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3Int5CLEAREv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

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

declare void @__gmpz_fdiv_qr(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @__gmpz_fdiv_q(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nounwind willreturn memory(read) "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" }
attributes #2 = { 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 #3 = { nounwind willreturn memory(read) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"_ZTS12__mpz_struct", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !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.2 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @__gmpz_cmp(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @__gmpz_set_ui(ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @__gmpz_set(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3Int3DivEPS_S0_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 align 2 {
  %4 = tail call i32 @__gmpz_cmp(ptr noundef nonnull %0, ptr noundef %1) #4
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %.not16 = icmp eq ptr %2, null
  br i1 %.not16, label %8, label %7

7:                                                ; preds = %6
  tail call void @__gmpz_set(ptr noundef nonnull %2, ptr noundef nonnull %0)
  br label %8

8:                                                ; preds = %7, %6
  tail call void @_ZN3Int5CLEAREv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br label %22

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %14

12:                                               ; preds = %9
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %22

14:                                               ; preds = %9
  %15 = icmp eq i32 %4, 0
  %.not15 = icmp eq ptr %2, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %14
  br i1 %.not15, label %18, label %17

17:                                               ; preds = %16
  tail call void @_ZN3Int5CLEAREv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  br label %18

18:                                               ; preds = %17, %16
  tail call void @__gmpz_set_ui(ptr noundef nonnull %0, i64 noundef 1)
  br label %22

19:                                               ; preds = %14
  br i1 %.not15, label %21, label %20

20:                                               ; preds = %19
  tail call void @__gmpz_fdiv_qr(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %22

21:                                               ; preds = %19
  tail call void @__gmpz_fdiv_q(ptr noundef nonnull %0, ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %22

22:                                               ; preds = %21, %20, %18, %12, %8
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3Int5CLEAREv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

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

declare void @__gmpz_fdiv_qr(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @__gmpz_fdiv_q(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(read) "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" }
attributes #2 = { 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 #3 = { 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 #4 = { nounwind willreturn memory(read) }

!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, !7, i64 4}
!6 = !{!"_ZTS12__mpz_struct", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}


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