; LLVM IR from Siskin-framework/Rebol-SQLite :: src (sqlite-command-finalize)

; 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.rxi_cmd_frame = type { [8 x %union.rxi_arg_val] }
%union.rxi_arg_val = type { %struct.anon.3 }
%struct.anon.3 = type { %union.anon, i32, i32 }
%union.anon = type { ptr }
%struct.Reb_Handle_Context = type { %union.anon.5, i32, i32, ptr }
%union.anon.5 = type { ptr }
%struct.reb_sqlite_stmt = type { ptr, i32 }
%struct.anon.1 = type <{ ptr, i32 }>

@Handle_SQLiteSTMT = external global i32, align 4
@.str = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @cmd_sqlite_finalize(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %10, i64 0, i64 1
  %12 = getelementptr inbounds %struct.anon.3, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 4, !tbaa !9
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Reb_Handle_Context, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 4, !tbaa !9
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %30

19:                                               ; preds = %2
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Reb_Handle_Context, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !10
  %23 = load i32, ptr @Handle_SQLiteSTMT, align 4, !tbaa !13
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %30, label %25

25:                                               ; preds = %19
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.reb_sqlite_stmt, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = icmp ne ptr %28, null
  br i1 %29, label %38, label %30

30:                                               ; preds = %25, %19, %2
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %33, i64 0, i64 1
  %35 = getelementptr inbounds %struct.anon.1, ptr %34, i32 0, i32 0
  store ptr @.str, ptr %35, align 4, !tbaa !9
  store i32 6, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %45

36:                                               ; No predecessors!
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37, %25
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.reb_sqlite_stmt, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = call i32 @sqlite3_finalize(ptr noundef %41)
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.reb_sqlite_stmt, ptr %43, i32 0, i32 0
  store ptr null, ptr %44, align 8, !tbaa !14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %45

45:                                               ; preds = %38, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %46 = load i32, ptr %3, align 4
  ret i32 %46
}

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

declare i32 @sqlite3_finalize(ptr noundef) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 8}
!11 = !{!"Reb_Handle_Context", !7, i64 0, !12, i64 8, !12, i64 12, !12, i64 14, !6, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"reb_sqlite_stmt", !6, i64 0, !12, i64 8}


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

@Handle_SQLiteSTMT = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 7) i32 @cmd_sqlite_finalize(ptr nocapture noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 4, !tbaa !5
  %5 = load ptr, ptr %4, align 4, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %12, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load i32, ptr %7, align 4, !tbaa !8
  %9 = load i32, ptr @Handle_SQLiteSTMT, align 4, !tbaa !12
  %.not10 = icmp eq i32 %8, %9
  br i1 %.not10, label %10, label %12

10:                                               ; preds = %6
  %11 = load ptr, ptr %5, align 8, !tbaa !13
  %.not11 = icmp eq ptr %11, null
  br i1 %.not11, label %12, label %13

12:                                               ; preds = %2, %6, %10
  store ptr @.str, ptr %3, align 4, !tbaa !5
  br label %15

13:                                               ; preds = %10
  %14 = tail call i32 @sqlite3_finalize(ptr noundef nonnull %11) #2
  store ptr null, ptr %5, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %13, %12
  %.0 = phi i32 [ 6, %12 ], [ 0, %13 ]
  ret i32 %.0
}

declare i32 @sqlite3_finalize(ptr noundef) local_unnamed_addr #1

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"Reb_Handle_Context", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 14, !11, i64 16}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"reb_sqlite_stmt", !11, i64 0, !10, i64 8}


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