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

; 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 i64, align 8
@.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 uwtable
define dso_local void @look() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  br label %3

3:                                                ; preds = %16, %0
  %4 = load i64, ptr @fin, align 8, !tbaa !5
  %5 = icmp ne i64 %4, 0
  br i1 %5, label %6, label %22

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

15:                                               ; preds = %6
  store i32 1, ptr %2, align 4
  br label %38

16:                                               ; preds = %6
  %17 = load i64, ptr @fin, align 8, !tbaa !5
  %18 = add i64 %17, -1
  store i64 %18, ptr @fin, align 8, !tbaa !5
  %19 = getelementptr inbounds [10 x ptr], ptr @in, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = call i32 @fclose(ptr noundef %20)
  store i8 10, ptr @see, align 1, !tbaa !13
  br label %3, !llvm.loop !14

22:                                               ; preds = %3
  %23 = load i8, ptr @see, align 1, !tbaa !13
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 10
  br i1 %25, label %26, label %29

26:                                               ; preds = %22
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef @ps)
  %28 = call ptr @strcpy(ptr noundef @ps, ptr noundef @.str.12) #5
  br label %29

29:                                               ; preds = %26, %22
  %30 = call i32 @getchar()
  store i32 %30, ptr %1, align 4, !tbaa !11
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr @stdin, align 8, !tbaa !9
  %34 = call ptr @freopen(ptr noundef @.str.13, ptr noundef @.str.10, ptr noundef %33)
  store i32 10, ptr %1, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %32, %29
  %36 = load i32, ptr %1, align 4, !tbaa !11
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr @see, align 1, !tbaa !13
  store i32 0, ptr %2, align 4
  br label %38

38:                                               ; preds = %35, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  %39 = load i32, ptr %2, align 4
  switch i32 %39, label %41 [
    i32 0, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38
  ret void

41:                                               ; preds = %38
  unreachable
}

declare i32 @getc(ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

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

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

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

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

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 = { "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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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 i64, align 8
@.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: nounwind uwtable
define dso_local void @look() local_unnamed_addr #0 {
  %1 = load i64, ptr @fin, align 8, !tbaa !5
  %.not5 = icmp eq i64 %1, 0
  br i1 %.not5, label %._crit_edge, label %.lr.ph

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

8:                                                ; preds = %.lr.ph
  %9 = load i64, ptr @fin, align 8, !tbaa !5
  %10 = add i64 %9, -1
  store i64 %10, ptr @fin, align 8, !tbaa !5
  %11 = getelementptr inbounds [10 x ptr], ptr @in, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = tail call i32 @fclose(ptr noundef %12)
  store i8 10, ptr @see, align 1, !tbaa !11
  %14 = load i64, ptr @fin, align 8, !tbaa !5
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %0
  %.pre = load i8, ptr @see, align 1, !tbaa !11
  %15 = icmp eq i8 %.pre, 10
  br i1 %15, label %._crit_edge.thread, label %18

._crit_edge.thread:                               ; preds = %8, %._crit_edge
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef nonnull @ps)
  %17 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @ps, ptr noundef nonnull dereferenceable(1) @.str.12) #5
  br label %18

18:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %19 = tail call i32 @getchar()
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr @stdin, align 8, !tbaa !9
  %23 = tail call ptr @freopen(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.10, ptr noundef %22) #5
  br label %24

24:                                               ; preds = %21, %18
  %.0 = phi i32 [ 10, %21 ], [ %19, %18 ]
  %25 = trunc i32 %.0 to i8
  store i8 %25, ptr @see, align 1, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %24
  ret void
}

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

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

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

; 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 #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 = { 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 #1 = { 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 #2 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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