; LLVM IR from 0intro/wmii :: lib/libstuff/x11/keys (parsekey)

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

@modkey_names = external dso_local global [9 x ptr], align 16
@parsekey.keys = external hidden global [16 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @parsekey(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 @tokenize(ptr noundef @parsekey.keys, i32 noundef 16, ptr noundef %13, i8 noundef signext 45)
  store i32 %14, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %49, %3
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %52

19:                                               ; preds = %15
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %44, %19
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [9 x ptr], ptr @modkey_names, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %47

26:                                               ; preds = %20
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [9 x ptr], ptr @modkey_names, i64 0, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16 x ptr], ptr @parsekey.keys, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = call i32 @strcasecmp(ptr noundef %30, ptr noundef %34) #5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %43, label %37

37:                                               ; preds = %26
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = shl i32 1, %38
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = or i32 %41, %39
  store i32 %42, ptr %40, align 4, !tbaa !9
  br label %48

43:                                               ; preds = %26
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %9, align 4, !tbaa !9
  br label %20, !llvm.loop !11

47:                                               ; preds = %20
  br label %52

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !13

52:                                               ; preds = %47, %15
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %69

55:                                               ; preds = %52
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %64

58:                                               ; preds = %55
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [16 x ptr], ptr @parsekey.keys, i64 0, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %62, ptr %63, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %58, %55
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = sub nsw i32 %66, 1
  %68 = icmp eq i32 %65, %67
  store i1 %68, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

69:                                               ; preds = %52
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = icmp eq i32 %70, %71
  store i1 %72, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

73:                                               ; preds = %69, %64
  call void @llvm.lifetime.end.p0(i64 4, 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
  %74 = load i1, ptr %4, align 1
  ret i1 %74
}

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

declare i32 @tokenize(ptr noundef, i32 noundef, ptr noundef, i8 noundef signext) #2

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

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

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

@modkey_names = external dso_local local_unnamed_addr global [9 x ptr], align 16
@parsekey.keys = external hidden global [16 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @parsekey(ptr noundef %0, ptr nocapture noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  store i32 0, ptr %1, align 4, !tbaa !5
  %4 = tail call i32 @tokenize(ptr noundef nonnull @parsekey.keys, i32 noundef 16, ptr noundef %0, i8 noundef signext 45) #3
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %3
  %6 = load ptr, ptr @modkey_names, align 16, !tbaa !9
  %.not30 = icmp eq ptr %6, null
  br i1 %.not30, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %12
  %indvars.iv39 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next40, %12 ]
  %7 = getelementptr inbounds [16 x ptr], ptr @parsekey.keys, i64 0, i64 %indvars.iv39
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %.preheader, %17
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %17 ]
  %10 = phi ptr [ %6, %.preheader ], [ %19, %17 ]
  %11 = tail call i32 @strcasecmp(ptr noundef nonnull %10, ptr noundef %8) #4
  %.not25 = icmp eq i32 %11, 0
  br i1 %.not25, label %12, label %17

12:                                               ; preds = %9
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  %14 = shl nuw i32 1, %13
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = or i32 %15, %14
  store i32 %16, ptr %1, align 4, !tbaa !5
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !11

17:                                               ; preds = %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds [9 x ptr], ptr @modkey_names, i64 0, i64 %indvars.iv.next
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %.loopexit.loopexit, label %9, !llvm.loop !13

.loopexit.loopexit:                               ; preds = %17
  %20 = trunc nuw nsw i64 %indvars.iv39 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %12, %.loopexit.loopexit, %3, %.preheader.lr.ph
  %.02029 = phi i32 [ 0, %.preheader.lr.ph ], [ 0, %3 ], [ %20, %.loopexit.loopexit ], [ %4, %12 ]
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %28, label %21

21:                                               ; preds = %.loopexit
  %.not24 = icmp eq i32 %4, 0
  br i1 %.not24, label %26, label %22

22:                                               ; preds = %21
  %23 = zext nneg i32 %.02029 to i64
  %24 = getelementptr inbounds [16 x ptr], ptr @parsekey.keys, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr %2, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %22, %21
  %27 = add nsw i32 %4, -1
  br label %28

28:                                               ; preds = %.loopexit, %26
  %.pn = phi i32 [ %27, %26 ], [ %4, %.loopexit ]
  %.0 = icmp eq i32 %.02029, %.pn
  ret i1 %.0
}

declare i32 @tokenize(ptr noundef, i32 noundef, ptr noundef, i8 noundef signext) local_unnamed_addr #1

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

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 = { "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(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 #3 = { nounwind }
attributes #4 = { 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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass