; LLVM IR from justinxu9905/bustub-2022-fall :: third_party/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 }

@hintsCallback = external hidden global ptr, align 8
@freeHintsCallback = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; 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 void @refreshShowHints(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [64 x i8], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %7) #4
  %13 = load ptr, ptr @hintsCallback, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %98

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.linenoiseState, ptr %18, i32 0, i32 8
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = add i64 %17, %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.linenoiseState, ptr %22, i32 0, i32 9
  %24 = load i64, ptr %23, align 8, !tbaa !14
  %25 = icmp ult i64 %21, %24
  br i1 %25, label %26, label %98

26:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 -1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %27 = load ptr, ptr @hintsCallback, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.linenoiseState, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = call ptr %27(ptr noundef %30, ptr noundef %8, ptr noundef %9)
  store ptr %31, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %97

34:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = call i64 @strlen(ptr noundef %35) #5
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.linenoiseState, ptr %38, i32 0, i32 9
  %40 = load i64, ptr %39, align 8, !tbaa !14
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.linenoiseState, ptr %43, i32 0, i32 8
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = add i64 %42, %45
  %47 = sub i64 %40, %46
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %12, align 4, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %34
  %53 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %53, ptr %11, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %52, %34
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %61

57:                                               ; preds = %54
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = icmp eq i32 %58, -1
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  store i32 37, ptr %8, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %60, %57, %54
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = icmp ne i32 %62, -1
  br i1 %63, label %67, label %64

64:                                               ; preds = %61
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %72

67:                                               ; preds = %64, %61
  %68 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %68, i64 noundef 64, ptr noundef @.str.1, i32 noundef %69, i32 noundef %70) #4
  br label %74

72:                                               ; preds = %64
  %73 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  store i8 0, ptr %73, align 16, !tbaa !16
  br label %74

74:                                               ; preds = %72, %67
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %77 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %78 = call i64 @strlen(ptr noundef %77) #5
  %79 = trunc i64 %78 to i32
  call void @abAppend(ptr noundef %75, ptr noundef %76, i32 noundef %79)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i32, ptr %11, align 4, !tbaa !9
  call void @abAppend(ptr noundef %80, ptr noundef %81, i32 noundef %82)
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = icmp ne i32 %83, -1
  br i1 %84, label %88, label %85

85:                                               ; preds = %74
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %85, %74
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  call void @abAppend(ptr noundef %89, ptr noundef @.str.2, i32 noundef 4)
  br label %90

90:                                               ; preds = %88, %85
  %91 = load ptr, ptr @freeHintsCallback, align 8, !tbaa !5
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %96

93:                                               ; preds = %90
  %94 = load ptr, ptr @freeHintsCallback, align 8, !tbaa !5
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  call void %94(ptr noundef %95)
  br label %96

96:                                               ; preds = %93, %90
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %97

97:                                               ; preds = %96, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %98

98:                                               ; preds = %97, %15, %3
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
declare hidden void @abAppend(ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 56}
!12 = !{!"linenoiseState", !10, i64 0, !10, 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, !10, i64 80}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 64}
!15 = !{!12, !6, i64 8}
!16 = !{!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"

@hintsCallback = external hidden local_unnamed_addr global ptr, align 8
@freeHintsCallback = external hidden local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; 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 void @refreshShowHints(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca [64 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #5
  %7 = load ptr, ptr @hintsCallback, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %51, label %8

8:                                                ; preds = %3
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = add i64 %11, %9
  %13 = getelementptr inbounds i8, ptr %1, i64 64
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ult i64 %12, %14
  br i1 %15, label %16, label %51

16:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  store i32 -1, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  store i32 0, ptr %6, align 4, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = call ptr %7(ptr noundef %18, ptr noundef nonnull %5, ptr noundef nonnull %6) #5
  %.not26 = icmp eq ptr %19, null
  br i1 %.not26, label %50, label %20

20:                                               ; preds = %16
  %21 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %19) #6
  %22 = trunc i64 %21 to i32
  %23 = load i64, ptr %13, align 8, !tbaa !13
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = add i64 %24, %9
  %26 = sub i64 %23, %25
  %27 = trunc i64 %26 to i32
  %spec.select = call i32 @llvm.smin.i32(i32 %22, i32 %27)
  %28 = load i32, ptr %6, align 4
  %29 = icmp eq i32 %28, 1
  %30 = load i32, ptr %5, align 4
  %31 = icmp eq i32 %30, -1
  %or.cond = select i1 %29, i1 %31, i1 false
  br i1 %or.cond, label %.thread, label %32

.thread:                                          ; preds = %20
  store i32 37, ptr %5, align 4, !tbaa !14
  br label %35

32:                                               ; preds = %20
  %33 = icmp ne i32 %30, -1
  %34 = icmp ne i32 %28, 0
  %or.cond3 = or i1 %34, %33
  br i1 %or.cond3, label %35, label %38

35:                                               ; preds = %.thread, %32
  %36 = phi i32 [ 37, %.thread ], [ %30, %32 ]
  %37 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %4, i64 noundef 64, ptr noundef nonnull @.str.1, i32 noundef %28, i32 noundef %36) #5
  br label %39

38:                                               ; preds = %32
  store i8 0, ptr %4, align 16, !tbaa !16
  br label %39

39:                                               ; preds = %38, %35
  %40 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #6
  %41 = trunc i64 %40 to i32
  call void @abAppend(ptr noundef %0, ptr noundef nonnull %4, i32 noundef %41)
  call void @abAppend(ptr noundef %0, ptr noundef nonnull %19, i32 noundef %spec.select)
  %42 = load i32, ptr %5, align 4, !tbaa !14
  %43 = icmp ne i32 %42, -1
  %44 = load i32, ptr %6, align 4
  %45 = icmp ne i32 %44, 0
  %or.cond5 = select i1 %43, i1 true, i1 %45
  br i1 %or.cond5, label %46, label %47

46:                                               ; preds = %39
  call void @abAppend(ptr noundef %0, ptr noundef nonnull @.str.2, i32 noundef 4)
  br label %47

47:                                               ; preds = %39, %46
  %48 = load ptr, ptr @freeHintsCallback, align 8, !tbaa !5
  %.not27 = icmp eq ptr %48, null
  br i1 %.not27, label %50, label %49

49:                                               ; preds = %47
  call void %48(ptr noundef nonnull %19) #5
  br label %50

50:                                               ; preds = %47, %49, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  br label %51

51:                                               ; preds = %50, %8, %3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #5
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @abAppend(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #2 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { 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, !12, i64 56}
!10 = !{!"linenoiseState", !11, i64 0, !11, i64 4, !6, i64 8, !12, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !11, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 64}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass