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

@stdout = external global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@stdin = 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: 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
declare noalias ptr @strdup(ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #3

declare i32 @fflush(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @linenoise(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [4096 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4096, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %8 = call i32 @isatty(i32 noundef 0) #5
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %12, label %10

10:                                               ; preds = %1
  %11 = call ptr @linenoiseNoTTY()
  store ptr %11, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %68

12:                                               ; preds = %1
  %13 = call i32 @isUnsupportedTerm()
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %58

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %16)
  %18 = load ptr, ptr @stdout, align 8, !tbaa !5
  %19 = call i32 @fflush(ptr noundef %18)
  %20 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 0
  %21 = load ptr, ptr @stdin, align 8, !tbaa !5
  %22 = call ptr @fgets(ptr noundef %20, i32 noundef 4096, ptr noundef %21)
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %15
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %57

25:                                               ; preds = %15
  %26 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 0
  %27 = call i64 @strlen(ptr noundef %26) #6
  store i64 %27, ptr %7, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %49, %25
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %47

31:                                               ; preds = %28
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = sub i64 %32, 1
  %34 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = sext i8 %35 to i32
  %37 = icmp eq i32 %36, 10
  br i1 %37, label %45, label %38

38:                                               ; preds = %31
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = sub i64 %39, 1
  %41 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %43, 13
  br label %45

45:                                               ; preds = %38, %31
  %46 = phi i1 [ true, %31 ], [ %44, %38 ]
  br label %47

47:                                               ; preds = %45, %28
  %48 = phi i1 [ false, %28 ], [ %46, %45 ]
  br i1 %48, label %49, label %54

49:                                               ; preds = %47
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = add i64 %50, -1
  store i64 %51, ptr %7, align 8, !tbaa !9
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 %52
  store i8 0, ptr %53, align 1, !tbaa !11
  br label %28, !llvm.loop !12

54:                                               ; preds = %47
  %55 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 0
  %56 = call noalias ptr @strdup(ptr noundef %55) #5
  store ptr %56, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %57

57:                                               ; preds = %54, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %68

58:                                               ; preds = %12
  %59 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 0
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = call i32 @linenoiseRaw(ptr noundef %59, i64 noundef 4096, ptr noundef %60)
  store i32 %61, ptr %5, align 4, !tbaa !14
  %62 = load i32, ptr %5, align 4, !tbaa !14
  %63 = icmp eq i32 %62, -1
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %68

65:                                               ; preds = %58
  %66 = getelementptr inbounds [4096 x i8], ptr %4, i64 0, i64 0
  %67 = call noalias ptr @strdup(ptr noundef %66) #5
  store ptr %67, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %68

68:                                               ; preds = %65, %64, %57, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4096, ptr %4) #5
  %69 = load ptr, ptr %2, align 8
  ret ptr %69
}

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @linenoiseNoTTY() #4

; Function Attrs: nounwind uwtable
declare hidden i32 @isUnsupportedTerm() #4

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @linenoiseRaw(ptr noundef, i64 noundef, ptr noundef) #4

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 "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 = { "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 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !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"

@stdout = external local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@stdin = 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 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: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @linenoise(ptr noundef %0) local_unnamed_addr #4 {
  %2 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %2) #6
  %3 = tail call i32 @isatty(i32 noundef 0) #6
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call ptr @linenoiseNoTTY()
  br label %26

6:                                                ; preds = %1
  %7 = tail call i32 @isUnsupportedTerm()
  %.not12 = icmp eq i32 %7, 0
  br i1 %.not12, label %21, label %8

8:                                                ; preds = %6
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %0)
  %10 = load ptr, ptr @stdout, align 8, !tbaa !5
  %11 = tail call i32 @fflush(ptr noundef %10)
  %12 = load ptr, ptr @stdin, align 8, !tbaa !5
  %13 = call ptr @fgets(ptr noundef nonnull %2, i32 noundef 4096, ptr noundef %12)
  %14 = icmp eq ptr %13, null
  br i1 %14, label %26, label %15

15:                                               ; preds = %8
  %16 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #7
  %.not1314 = icmp eq i64 %16, 0
  br i1 %.not1314, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.critedge2
  %.015 = phi i64 [ %17, %.critedge2 ], [ %16, %15 ]
  %17 = add i64 %.015, -1
  %18 = getelementptr inbounds [4096 x i8], ptr %2, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !9
  switch i8 %19, label %.critedge [
    i8 10, label %.critedge2
    i8 13, label %.critedge2
  ]

.critedge2:                                       ; preds = %.lr.ph, %.lr.ph
  store i8 0, ptr %18, align 1, !tbaa !9
  %.not13 = icmp eq i64 %17, 0
  br i1 %.not13, label %.critedge, label %.lr.ph, !llvm.loop !10

.critedge:                                        ; preds = %.critedge2, %.lr.ph, %15
  %20 = call noalias ptr @strdup(ptr noundef nonnull %2) #6
  br label %26

21:                                               ; preds = %6
  %22 = call i32 @linenoiseRaw(ptr noundef nonnull %2, i64 noundef 4096, ptr noundef %0)
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %26, label %24

24:                                               ; preds = %21
  %25 = call noalias ptr @strdup(ptr noundef nonnull %2) #6
  br label %26

26:                                               ; preds = %21, %.critedge, %8, %24, %4
  %.1 = phi ptr [ %25, %24 ], [ %5, %4 ], [ %20, %.critedge ], [ null, %8 ], [ null, %21 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %2) #6
  ret ptr %.1
}

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden ptr @linenoiseNoTTY() local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden i32 @isUnsupportedTerm() local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @linenoiseRaw(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass