; LLVM IR from adventure-db/adventure :: lib/linenoise (linenoise)

; 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.linenoiseState = type { i32, i32, ptr, i64, ptr, i64, i64, i64, i64, i64, i64, i32 }

@mlmode = external hidden global i32, align 4

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @linenoiseEditInsert(ptr noundef %0, i8 noundef signext %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.linenoiseState, ptr %6, i32 0, i32 8
  %8 = load i64, ptr %7, align 8, !tbaa !10
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.linenoiseState, ptr %9, i32 0, i32 3
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %12 = icmp ult i64 %8, %11
  br i1 %12, label %13, label %118

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.linenoiseState, ptr %14, i32 0, i32 8
  %16 = load i64, ptr %15, align 8, !tbaa !10
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.linenoiseState, ptr %17, i32 0, i32 6
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = icmp eq i64 %16, %19
  br i1 %20, label %21, label %70

21:                                               ; preds = %13
  %22 = load i8, ptr %5, align 1, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.linenoiseState, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.linenoiseState, ptr %26, i32 0, i32 6
  %28 = load i64, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds i8, ptr %25, i64 %28
  store i8 %22, ptr %29, align 1, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.linenoiseState, ptr %30, i32 0, i32 6
  %32 = load i64, ptr %31, align 8, !tbaa !15
  %33 = add i64 %32, 1
  store i64 %33, ptr %31, align 8, !tbaa !15
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.linenoiseState, ptr %34, i32 0, i32 8
  %36 = load i64, ptr %35, align 8, !tbaa !10
  %37 = add i64 %36, 1
  store i64 %37, ptr %35, align 8, !tbaa !10
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.linenoiseState, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.linenoiseState, ptr %41, i32 0, i32 8
  %43 = load i64, ptr %42, align 8, !tbaa !10
  %44 = getelementptr inbounds i8, ptr %40, i64 %43
  store i8 0, ptr %44, align 1, !tbaa !9
  %45 = load i32, ptr @mlmode, align 4, !tbaa !17
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %67, label %47

47:                                               ; preds = %21
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.linenoiseState, ptr %48, i32 0, i32 5
  %50 = load i64, ptr %49, align 8, !tbaa !18
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.linenoiseState, ptr %51, i32 0, i32 8
  %53 = load i64, ptr %52, align 8, !tbaa !10
  %54 = add i64 %50, %53
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.linenoiseState, ptr %55, i32 0, i32 9
  %57 = load i64, ptr %56, align 8, !tbaa !19
  %58 = icmp ult i64 %54, %57
  br i1 %58, label %59, label %67

59:                                               ; preds = %47
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.linenoiseState, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !20
  %63 = call i64 @write(i32 noundef %62, ptr noundef %5, i64 noundef 1)
  %64 = icmp eq i64 %63, -1
  br i1 %64, label %65, label %66

65:                                               ; preds = %59
  store i32 -1, ptr %3, align 4
  br label %119

66:                                               ; preds = %59
  br label %69

67:                                               ; preds = %47, %21
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  call void @refreshLine(ptr noundef %68)
  br label %69

69:                                               ; preds = %67, %66
  br label %117

70:                                               ; preds = %13
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.linenoiseState, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.linenoiseState, ptr %74, i32 0, i32 6
  %76 = load i64, ptr %75, align 8, !tbaa !15
  %77 = getelementptr inbounds i8, ptr %73, i64 %76
  %78 = getelementptr inbounds i8, ptr %77, i64 1
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.linenoiseState, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !16
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.linenoiseState, ptr %82, i32 0, i32 6
  %84 = load i64, ptr %83, align 8, !tbaa !15
  %85 = getelementptr inbounds i8, ptr %81, i64 %84
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.linenoiseState, ptr %86, i32 0, i32 8
  %88 = load i64, ptr %87, align 8, !tbaa !10
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.linenoiseState, ptr %89, i32 0, i32 6
  %91 = load i64, ptr %90, align 8, !tbaa !15
  %92 = sub i64 %88, %91
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %78, ptr align 1 %85, i64 %92, i1 false)
  %93 = load i8, ptr %5, align 1, !tbaa !9
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.linenoiseState, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !16
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.linenoiseState, ptr %97, i32 0, i32 6
  %99 = load i64, ptr %98, align 8, !tbaa !15
  %100 = getelementptr inbounds i8, ptr %96, i64 %99
  store i8 %93, ptr %100, align 1, !tbaa !9
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.linenoiseState, ptr %101, i32 0, i32 8
  %103 = load i64, ptr %102, align 8, !tbaa !10
  %104 = add i64 %103, 1
  store i64 %104, ptr %102, align 8, !tbaa !10
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.linenoiseState, ptr %105, i32 0, i32 6
  %107 = load i64, ptr %106, align 8, !tbaa !15
  %108 = add i64 %107, 1
  store i64 %108, ptr %106, align 8, !tbaa !15
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.linenoiseState, ptr %109, i32 0, i32 2
  %111 = load ptr, ptr %110, align 8, !tbaa !16
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.linenoiseState, ptr %112, i32 0, i32 8
  %114 = load i64, ptr %113, align 8, !tbaa !10
  %115 = getelementptr inbounds i8, ptr %111, i64 %114
  store i8 0, ptr %115, align 1, !tbaa !9
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  call void @refreshLine(ptr noundef %116)
  br label %117

117:                                              ; preds = %70, %69
  br label %118

118:                                              ; preds = %117, %2
  store i32 0, ptr %3, align 4
  br label %119

119:                                              ; preds = %118, %65
  %120 = load i32, ptr %3, align 4
  ret i32 %120
}

; Function Attrs: nounwind uwtable
declare hidden void @refreshLine(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

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

!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, !13, i64 56}
!11 = !{!"linenoiseState", !12, i64 0, !12, i64 4, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !12, i64 80}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!11, !13, i64 16}
!15 = !{!11, !13, i64 40}
!16 = !{!11, !6, i64 8}
!17 = !{!12, !12, i64 0}
!18 = !{!11, !13, i64 32}
!19 = !{!11, !13, i64 64}
!20 = !{!11, !12, i64 4}


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

@mlmode = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @linenoiseEditInsert(ptr noundef %0, i8 noundef signext %1) local_unnamed_addr #1 {
  %3 = alloca i8, align 1
  store i8 %1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load i64, ptr %4, align 8, !tbaa !8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = icmp ult i64 %5, %7
  br i1 %8, label %9, label %50

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %12 = icmp eq i64 %5, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  br i1 %12, label %15, label %37

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %14, i64 %5
  store i8 %1, ptr %16, align 1, !tbaa !5
  %17 = load i64, ptr %10, align 8, !tbaa !14
  %18 = add i64 %17, 1
  store i64 %18, ptr %10, align 8, !tbaa !14
  %19 = load i64, ptr %4, align 8, !tbaa !8
  %20 = add i64 %19, 1
  store i64 %20, ptr %4, align 8, !tbaa !8
  %21 = load ptr, ptr %13, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 %20
  store i8 0, ptr %22, align 1, !tbaa !5
  %23 = load i32, ptr @mlmode, align 4, !tbaa !16
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %24, label %.sink.split

24:                                               ; preds = %15
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  %26 = load i64, ptr %25, align 8, !tbaa !17
  %27 = load i64, ptr %4, align 8, !tbaa !8
  %28 = add i64 %27, %26
  %29 = getelementptr inbounds i8, ptr %0, i64 64
  %30 = load i64, ptr %29, align 8, !tbaa !18
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %32, label %.sink.split

32:                                               ; preds = %24
  %33 = getelementptr inbounds i8, ptr %0, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !19
  %35 = call i64 @write(i32 noundef %34, ptr noundef nonnull %3, i64 noundef 1) #3
  %36 = icmp eq i64 %35, -1
  br i1 %36, label %51, label %50

37:                                               ; preds = %9
  %38 = getelementptr inbounds i8, ptr %14, i64 %11
  %39 = getelementptr inbounds i8, ptr %38, i64 1
  %40 = sub i64 %5, %11
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %39, ptr align 1 %38, i64 %40, i1 false)
  %41 = load ptr, ptr %13, align 8, !tbaa !15
  %42 = load i64, ptr %10, align 8, !tbaa !14
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  store i8 %1, ptr %43, align 1, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !8
  %45 = add i64 %44, 1
  store i64 %45, ptr %4, align 8, !tbaa !8
  %46 = load i64, ptr %10, align 8, !tbaa !14
  %47 = add i64 %46, 1
  store i64 %47, ptr %10, align 8, !tbaa !14
  %48 = load ptr, ptr %13, align 8, !tbaa !15
  %49 = getelementptr inbounds i8, ptr %48, i64 %45
  store i8 0, ptr %49, align 1, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %15, %24, %37
  tail call void @refreshLine(ptr noundef nonnull %0)
  br label %50

50:                                               ; preds = %.sink.split, %32, %2
  br label %51

51:                                               ; preds = %32, %50
  %.0 = phi i32 [ 0, %50 ], [ -1, %32 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @refreshLine(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nofree "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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !12, i64 56}
!9 = !{!"linenoiseState", !10, i64 0, !10, i64 4, !11, i64 8, !12, i64 16, !11, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !10, i64 80}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"long", !6, i64 0}
!13 = !{!9, !12, i64 16}
!14 = !{!9, !12, i64 40}
!15 = !{!9, !11, i64 8}
!16 = !{!10, !10, i64 0}
!17 = !{!9, !12, i64 32}
!18 = !{!9, !12, i64 64}
!19 = !{!9, !10, i64 4}


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