; LLVM IR from krig/LISP :: komplott (builtin_sub)

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

%struct.object_t = type { ptr, ptr, i32 }

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @itos(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_atom(ptr noundef) #1

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i64 @atol(ptr noundef nonnull) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @builtin_sub(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.object_t, ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %31

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.object_t, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %26

13:                                               ; preds = %8
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.object_t, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds %struct.object_t, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %26

20:                                               ; preds = %13
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.object_t, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.object_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  br label %27

26:                                               ; preds = %13, %8
  br label %27

27:                                               ; preds = %26, %20
  %28 = phi ptr [ %25, %20 ], [ @.str.2, %26 ]
  %29 = call i64 @atol(ptr noundef %28) #4
  %30 = sub nsw i64 0, %29
  store i64 %30, ptr %3, align 8, !tbaa !14
  br label %88

31:                                               ; preds = %1
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.object_t, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %49

36:                                               ; preds = %31
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.object_t, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %40 = getelementptr inbounds %struct.object_t, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %43, label %49

43:                                               ; preds = %36
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.object_t, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !12
  %47 = getelementptr inbounds %struct.object_t, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !12
  br label %50

49:                                               ; preds = %36, %31
  br label %50

50:                                               ; preds = %49, %43
  %51 = phi ptr [ %48, %43 ], [ @.str.2, %49 ]
  %52 = call i64 @atol(ptr noundef %51) #4
  store i64 %52, ptr %3, align 8, !tbaa !14
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.object_t, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  store ptr %55, ptr %2, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %83, %50
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %87

59:                                               ; preds = %56
  %60 = load i64, ptr %3, align 8, !tbaa !14
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.object_t, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !12
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %78

65:                                               ; preds = %59
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.object_t, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !12
  %69 = getelementptr inbounds %struct.object_t, ptr %68, i32 0, i32 2
  %70 = load i32, ptr %69, align 8, !tbaa !13
  %71 = icmp eq i32 %70, 1
  br i1 %71, label %72, label %78

72:                                               ; preds = %65
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.object_t, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !12
  %76 = getelementptr inbounds %struct.object_t, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !12
  br label %79

78:                                               ; preds = %65, %59
  br label %79

79:                                               ; preds = %78, %72
  %80 = phi ptr [ %77, %72 ], [ @.str.2, %78 ]
  %81 = call i64 @atol(ptr noundef %80) #4
  %82 = sub nsw i64 %60, %81
  store i64 %82, ptr %3, align 8, !tbaa !14
  br label %83

83:                                               ; preds = %79
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.object_t, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !9
  store ptr %86, ptr %2, align 8, !tbaa !5
  br label %56, !llvm.loop !16

87:                                               ; preds = %56
  br label %88

88:                                               ; preds = %87, %27
  %89 = load i64, ptr %3, align 8, !tbaa !14
  %90 = call ptr @itos(i64 noundef %89)
  %91 = call ptr @new_atom(ptr noundef %90)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %91
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint nounwind willreturn memory(read) 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 }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"object_t", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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 [1 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @itos(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_atom(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i64 @atol(ptr nocapture noundef nonnull) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @builtin_sub(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %.not20 = icmp eq ptr %5, null
  br i1 %4, label %6, label %17

6:                                                ; preds = %1
  br i1 %.not20, label %13, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = load ptr, ptr %5, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %6, %7, %11
  %14 = phi ptr [ %12, %11 ], [ @.str.2, %7 ], [ @.str.2, %6 ]
  %15 = tail call i64 @atol(ptr nocapture noundef %14) #2
  %16 = sub nsw i64 0, %15
  br label %.loopexit

17:                                               ; preds = %1
  br i1 %.not20, label %.lr.ph.preheader, label %18

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %5, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %.lr.ph.preheader

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !11
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %22, %18, %17
  %24 = phi ptr [ %23, %22 ], [ @.str.2, %18 ], [ @.str.2, %17 ]
  %25 = tail call i64 @atol(ptr nocapture noundef %24) #2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %33
  %.01424 = phi ptr [ %.014, %33 ], [ %3, %.lr.ph.preheader ]
  %.023 = phi i64 [ %36, %33 ], [ %25, %.lr.ph.preheader ]
  %26 = load ptr, ptr %.01424, align 8, !tbaa !11
  %.not19 = icmp eq ptr %26, null
  br i1 %.not19, label %33, label %27

27:                                               ; preds = %.lr.ph
  %28 = getelementptr inbounds i8, ptr %26, i64 16
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  %32 = load ptr, ptr %26, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %.lr.ph, %27, %31
  %34 = phi ptr [ %32, %31 ], [ @.str.2, %27 ], [ @.str.2, %.lr.ph ]
  %35 = tail call i64 @atol(ptr nocapture noundef %34) #2
  %36 = sub nsw i64 %.023, %35
  %37 = getelementptr inbounds i8, ptr %.01424, i64 8
  %.014 = load ptr, ptr %37, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.014, null
  br i1 %.not18, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %33, %13
  %.1 = phi i64 [ %16, %13 ], [ %36, %33 ]
  %38 = tail call ptr @itos(i64 noundef %.1)
  %39 = tail call ptr @new_atom(ptr noundef %38)
  ret ptr %39
}

attributes #0 = { 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #2 = { 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 8}
!6 = !{!"object_t", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass