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

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

%union.rxi_arg_val = type { %struct.anon.3 }
%struct.anon.3 = type { %union.anon, i32, i32 }
%union.anon = type { ptr }
%struct.rebol_ext_api = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.anon = type { i32, i32 }

@RL = external global ptr, align 8
@words_sqlite_arg = external global ptr, align 8

; 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
define dso_local signext i8 @fetch_mode(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %union.rxi_arg_val, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %16 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %16, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %17 = load ptr, ptr @RL, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rebol_ext_api, ptr %17, i32 0, i32 31
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = call i32 %19(ptr noundef %20, i32 noundef %21, ptr noundef %12)
  store i32 %22, ptr %14, align 4, !tbaa !9
  %23 = load i32, ptr %14, align 4, !tbaa !9
  %24 = icmp eq i32 16, %23
  br i1 %24, label %28, label %25

25:                                               ; preds = %5
  %26 = load i32, ptr %14, align 4, !tbaa !9
  %27 = icmp eq i32 19, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %25, %5
  %29 = load ptr, ptr @RL, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.rebol_ext_api, ptr %29, i32 0, i32 26
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load ptr, ptr @words_sqlite_arg, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !14
  %35 = call i32 %31(ptr noundef %32, i32 noundef %34)
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = sub i32 %35, %36
  store i32 %37, ptr %13, align 4, !tbaa !9
  br label %45

38:                                               ; preds = %25
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = icmp eq i32 5, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load i64, ptr %12, align 4, !tbaa !14
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %13, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %41, %38
  br label %45

45:                                               ; preds = %44, %28
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = icmp uge i32 %46, 0
  br i1 %47, label %48, label %56

48:                                               ; preds = %45
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = icmp ult i32 %49, %50
  br i1 %51, label %52, label %56

52:                                               ; preds = %48
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds i32, ptr %54, i64 0
  store i32 %53, ptr %55, align 4, !tbaa !9
  store i8 1, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %57

56:                                               ; preds = %48, %45
  store i8 0, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %57

57:                                               ; preds = %56, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #2
  %58 = load i8, ptr %6, align 1
  ret i8 %58
}

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 248}
!12 = !{!"rebol_ext_api", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336}
!13 = !{!12, !6, i64 208}
!14 = !{!7, !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"

%union.rxi_arg_val = type { %struct.anon.3 }
%struct.anon.3 = type { %union.anon, i32, i32 }
%union.anon = type { ptr }

@RL = external local_unnamed_addr global ptr, align 8
@words_sqlite_arg = external local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local signext range(i8 0, 2) i8 @fetch_mode(ptr noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %union.rxi_arg_val, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #2
  %7 = load ptr, ptr @RL, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 248
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = call i32 %9(ptr noundef %0, i32 noundef %1, ptr noundef nonnull %6) #2
  switch i32 %10, label %.thread [
    i32 19, label %11
    i32 16, label %11
    i32 5, label %19
  ]

11:                                               ; preds = %5, %5
  %12 = load ptr, ptr @RL, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 208
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr @words_sqlite_arg, align 8, !tbaa !5
  %16 = load i32, ptr %6, align 8, !tbaa !12
  %17 = call i32 %14(ptr noundef %15, i32 noundef %16) #2
  %18 = sub i32 %17, %3
  br label %22

19:                                               ; preds = %5
  %20 = load i64, ptr %6, align 8, !tbaa !12
  %21 = trunc i64 %20 to i32
  br label %22

22:                                               ; preds = %11, %19
  %.013 = phi i32 [ %18, %11 ], [ %21, %19 ]
  %23 = icmp ult i32 %.013, %4
  br i1 %23, label %24, label %.thread

24:                                               ; preds = %22
  store i32 %.013, ptr %2, align 4, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %5, %22, %24
  %.0 = phi i8 [ 1, %24 ], [ 0, %22 ], [ 0, %5 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #2
  ret i8 %.0
}

attributes #0 = { mustprogress 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 = { 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 = !{!10, !6, i64 248}
!10 = !{!"rebol_ext_api", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336}
!11 = !{!10, !6, i64 208}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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