; LLVM IR from Robert-van-Engelen/lisp :: src (lisp-pr-single)

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

@fin = external dso_local global i32, align 4
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1
@in = external dso_local global [10 x ptr], align 16
@see = external dso_local global i8, align 1
@.str.11 = external hidden unnamed_addr constant [3 x i8], align 1
@ps = external dso_local global [20 x i8], align 16
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [9 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @get() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %3 = load i8, ptr @see, align 1, !tbaa !5
  %4 = sext i8 %3 to i32
  store i32 %4, ptr %2, align 4, !tbaa !8
  %5 = load i32, ptr @fin, align 4, !tbaa !8
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %25

7:                                                ; preds = %0
  %8 = load i32, ptr @fin, align 4, !tbaa !8
  %9 = sub i32 %8, 1
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [10 x ptr], ptr @in, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !10
  %13 = call i32 @getc(ptr noundef %12)
  store i32 %13, ptr %1, align 4, !tbaa !8
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr @see, align 1, !tbaa !5
  %15 = load i32, ptr %1, align 4, !tbaa !8
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %24

17:                                               ; preds = %7
  %18 = load i32, ptr @fin, align 4, !tbaa !8
  %19 = add i32 %18, -1
  store i32 %19, ptr @fin, align 4, !tbaa !8
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [10 x ptr], ptr @in, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %23 = call i32 @fclose(ptr noundef %22)
  store i8 10, ptr @see, align 1, !tbaa !5
  br label %24

24:                                               ; preds = %17, %7
  br label %41

25:                                               ; preds = %0
  %26 = load i8, ptr @see, align 1, !tbaa !5
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 10
  br i1 %28, label %29, label %32

29:                                               ; preds = %25
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef @ps)
  %31 = call ptr @strcpy(ptr noundef @ps, ptr noundef @.str.12) #5
  br label %32

32:                                               ; preds = %29, %25
  %33 = call i32 @getchar()
  store i32 %33, ptr %1, align 4, !tbaa !8
  %34 = icmp eq i32 %33, -1
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = load ptr, ptr @stdin, align 8, !tbaa !10
  %37 = call ptr @freopen(ptr noundef @.str.13, ptr noundef @.str.10, ptr noundef %36)
  store i32 10, ptr %1, align 4, !tbaa !8
  br label %38

38:                                               ; preds = %35, %32
  %39 = load i32, ptr %1, align 4, !tbaa !8
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr @see, align 1, !tbaa !5
  br label %41

41:                                               ; preds = %38, %24
  %42 = load i32, ptr %2, align 4, !tbaa !8
  %43 = trunc i32 %42 to i8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret i8 %43
}

declare i32 @getc(ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare i32 @getchar() #4

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

!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, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, 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"

@fin = external dso_local local_unnamed_addr global i32, align 4
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1
@in = external dso_local local_unnamed_addr global [10 x ptr], align 16
@see = external dso_local local_unnamed_addr global i8, align 1
@.str.11 = external hidden unnamed_addr constant [3 x i8], align 1
@ps = external dso_local global [20 x i8], align 16
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [9 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @get() local_unnamed_addr #1 {
  %1 = load i8, ptr @see, align 1, !tbaa !5
  %2 = load i32, ptr @fin, align 4, !tbaa !8
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %18, label %3

3:                                                ; preds = %0
  %4 = add i32 %2, -1
  %5 = zext i32 %4 to i64
  %6 = getelementptr inbounds [10 x ptr], ptr @in, i64 0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  %8 = tail call i32 @getc(ptr noundef %7)
  %9 = trunc i32 %8 to i8
  store i8 %9, ptr @see, align 1, !tbaa !5
  %10 = icmp eq i32 %8, -1
  br i1 %10, label %11, label %31

11:                                               ; preds = %3
  %12 = load i32, ptr @fin, align 4, !tbaa !8
  %13 = add i32 %12, -1
  store i32 %13, ptr @fin, align 4, !tbaa !8
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds [10 x ptr], ptr @in, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !10
  %17 = tail call i32 @fclose(ptr noundef %16)
  br label %.sink.split

18:                                               ; preds = %0
  %19 = icmp eq i8 %1, 10
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef nonnull @ps)
  %22 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @ps, ptr noundef nonnull dereferenceable(1) @.str.12) #5
  br label %23

23:                                               ; preds = %20, %18
  %24 = tail call i32 @getchar()
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load ptr, ptr @stdin, align 8, !tbaa !10
  %28 = tail call ptr @freopen(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.10, ptr noundef %27) #5
  br label %29

29:                                               ; preds = %26, %23
  %.0 = phi i32 [ 10, %26 ], [ %24, %23 ]
  %30 = trunc i32 %.0 to i8
  br label %.sink.split

.sink.split:                                      ; preds = %29, %11
  %.sink = phi i8 [ 10, %11 ], [ %30, %29 ]
  store i8 %.sink, ptr @see, align 1, !tbaa !5
  br label %31

31:                                               ; preds = %.sink.split, %3
  ret i8 %1
}

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

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

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

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #3

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 #3 = { inlinehint nofree 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 #4 = { "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 }

!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, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}


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