; LLVM IR from EarlGray/language-incubator :: fp/secd (secd)

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

@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.92 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.93 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.94 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @atom_type(ptr noundef) #0

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @is_nil(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @cell_index(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cell_type(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @get_car(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @get_cdr(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @not_nil(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @list_next(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @symname(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @lookup_env(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.secd, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i32 @cell_type(ptr noundef %15)
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %23, label %18

18:                                               ; preds = %2
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.92) #6
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.9) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %88

23:                                               ; preds = %2
  br label %24

24:                                               ; preds = %84, %82, %23
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i32 @not_nil(ptr noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %85

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call ptr @get_car(ptr noundef %29)
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call i32 @is_nil(ptr noundef %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %28
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call ptr @list_next(ptr noundef %35)
  store ptr %36, ptr %6, align 8, !tbaa !5
  store i32 2, ptr %7, align 4
  br label %82, !llvm.loop !11

37:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = call ptr @get_car(ptr noundef %38)
  store ptr %39, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call ptr @get_cdr(ptr noundef %40)
  store ptr %41, ptr %10, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %77, %75, %37
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = call i32 @not_nil(ptr noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %78

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = call ptr @get_car(ptr noundef %47)
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = call i32 @atom_type(ptr noundef %49)
  %51 = icmp ne i32 %50, 2
  br i1 %51, label %52, label %61

52:                                               ; preds = %46
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = call i64 @cell_index(ptr noundef %54)
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.93, i64 noundef %55) #6
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = call ptr @list_next(ptr noundef %57)
  store ptr %58, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = call ptr @list_next(ptr noundef %59)
  store ptr %60, ptr %10, align 8, !tbaa !5
  store i32 4, ptr %7, align 4
  br label %75, !llvm.loop !13

61:                                               ; preds = %46
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = call ptr @symname(ptr noundef %63)
  %65 = call i32 @strcasecmp(ptr noundef %62, ptr noundef %64) #7
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %70, label %67

67:                                               ; preds = %61
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = call ptr @get_car(ptr noundef %68)
  store ptr %69, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %75

70:                                               ; preds = %61
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = call ptr @list_next(ptr noundef %71)
  store ptr %72, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = call ptr @list_next(ptr noundef %73)
  store ptr %74, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %75

75:                                               ; preds = %70, %67, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  %76 = load i32, ptr %7, align 4
  switch i32 %76, label %81 [
    i32 0, label %77
    i32 4, label %42
  ]

77:                                               ; preds = %75
  br label %42, !llvm.loop !13

78:                                               ; preds = %42
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call ptr @list_next(ptr noundef %79)
  store ptr %80, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %81

81:                                               ; preds = %78, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %82

82:                                               ; preds = %81, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %83 = load i32, ptr %7, align 4
  switch i32 %83, label %88 [
    i32 0, label %84
    i32 2, label %24
  ]

84:                                               ; preds = %82
  br label %24, !llvm.loop !11

85:                                               ; preds = %24
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.94, ptr noundef %86)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %88

88:                                               ; preds = %85, %82, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %89 = load ptr, ptr %3, align 8
  ret ptr %89
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcasecmp(ptr noundef, ptr noundef) #5

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!10, !6, i64 8}
!10 = !{!"secd", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.92 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.93 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.94 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @atom_type(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @is_nil(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @cell_index(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cell_type(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @get_car(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @get_cdr(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @not_nil(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @list_next(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @symname(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @lookup_env(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call i32 @cell_type(ptr noundef %4)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %.preheader, label %8

.preheader:                                       ; preds = %2
  %7 = tail call i32 @not_nil(ptr noundef %4)
  %.not49 = icmp eq i32 %7, 0
  br i1 %.not49, label %._crit_edge52, label %.lr.ph51

8:                                                ; preds = %2
  %9 = load ptr, ptr @stderr, align 8, !tbaa !10
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.92) #4
  %11 = load ptr, ptr @stderr, align 8, !tbaa !10
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.9) #4
  br label %36

.lr.ph51:                                         ; preds = %.preheader, %._crit_edge
  %.02750 = phi ptr [ %33, %._crit_edge ], [ %4, %.preheader ]
  %13 = tail call ptr @get_car(ptr noundef %.02750)
  %14 = tail call i32 @is_nil(ptr noundef %13)
  %.not33 = icmp eq i32 %14, 0
  br i1 %.not33, label %15, label %._crit_edge, !llvm.loop !11

15:                                               ; preds = %.lr.ph51
  %16 = tail call ptr @get_car(ptr noundef %13)
  %17 = tail call ptr @get_cdr(ptr noundef %13)
  %18 = tail call i32 @not_nil(ptr noundef %16)
  %.not3446 = icmp eq i32 %18, 0
  br i1 %.not3446, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %29
  %.02348 = phi ptr [ %31, %29 ], [ %17, %15 ]
  %.02547 = phi ptr [ %30, %29 ], [ %16, %15 ]
  %19 = tail call ptr @get_car(ptr noundef %.02547)
  %20 = tail call i32 @atom_type(ptr noundef %19)
  %.not35 = icmp eq i32 %20, 2
  br i1 %.not35, label %25, label %21

21:                                               ; preds = %.lr.ph
  %22 = load ptr, ptr @stderr, align 8, !tbaa !10
  %23 = tail call i64 @cell_index(ptr noundef %19)
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.93, i64 noundef %23) #4
  br label %29, !llvm.loop !13

25:                                               ; preds = %.lr.ph
  %26 = tail call ptr @symname(ptr noundef %19)
  %27 = tail call i32 @strcasecmp(ptr noundef %1, ptr noundef %26) #5
  %.not36 = icmp eq i32 %27, 0
  br i1 %.not36, label %.thread41, label %29

.thread41:                                        ; preds = %25
  %28 = tail call ptr @get_car(ptr noundef %.02348)
  br label %36

29:                                               ; preds = %25, %21
  %30 = tail call ptr @list_next(ptr noundef %.02547)
  %31 = tail call ptr @list_next(ptr noundef %.02348)
  %32 = tail call i32 @not_nil(ptr noundef %30)
  %.not34 = icmp eq i32 %32, 0
  br i1 %.not34, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %29, %15, %.lr.ph51
  %33 = tail call ptr @list_next(ptr noundef %.02750)
  %34 = tail call i32 @not_nil(ptr noundef %33)
  %.not = icmp eq i32 %34, 0
  br i1 %.not, label %._crit_edge52, label %.lr.ph51

._crit_edge52:                                    ; preds = %._crit_edge, %.preheader
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.94, ptr noundef %1)
  br label %36

36:                                               ; preds = %.thread41, %._crit_edge52, %8
  %.5 = phi ptr [ null, %._crit_edge52 ], [ null, %8 ], [ %28, %.thread41 ]
  ret ptr %.5
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @strcasecmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { 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 = { mustprogress nofree 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 #4 = { cold 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, !7, i64 8}
!6 = !{!"secd", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass