; LLVM IR from kmxz/overlayfs-tools :: sh (substitue)

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

@var_names = external dso_local global [5 x ptr], align 16
@vars = external dso_local global [5 x ptr], align 16
@.str.17 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @quote(ptr noundef, ptr noundef) #2

; 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 i32 @substitue(i8 noundef signext %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %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
  store i8 %0, ptr %5, align 1, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !8
  store ptr %2, ptr %7, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !10
  br label %11

11:                                               ; preds = %33, %3
  %12 = load i32, ptr %8, align 4, !tbaa !10
  %13 = icmp slt i32 %12, 5
  br i1 %13, label %14, label %36

14:                                               ; preds = %11
  %15 = load i32, ptr %8, align 4, !tbaa !10
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x ptr], ptr @vars, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !8
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %32

20:                                               ; preds = %14
  %21 = load i32, ptr %8, align 4, !tbaa !10
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5 x ptr], ptr @var_names, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !8
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = sext i8 %26 to i32
  %28 = load i8, ptr %5, align 1, !tbaa !5
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %20
  br label %36

32:                                               ; preds = %20, %14
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %8, align 4, !tbaa !10
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %8, align 4, !tbaa !10
  br label %11, !llvm.loop !12

36:                                               ; preds = %31, %11
  %37 = load i32, ptr %8, align 4, !tbaa !10
  %38 = icmp eq i32 %37, 5
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %72

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %41 = load i32, ptr %8, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5 x ptr], ptr @vars, i64 0, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !8
  %45 = call i64 @strlen(ptr noundef %44) #5
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %10, align 4, !tbaa !10
  %47 = load ptr, ptr %6, align 8, !tbaa !8
  %48 = load i32, ptr %8, align 4, !tbaa !10
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [5 x ptr], ptr @vars, i64 0, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !8
  %52 = load i32, ptr %10, align 4, !tbaa !10
  %53 = sext i32 %52 to i64
  %54 = call i32 @strncmp(ptr noundef %47, ptr noundef %51, i64 noundef %53) #5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %40
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %71

57:                                               ; preds = %40
  %58 = load i32, ptr %10, align 4, !tbaa !10
  %59 = load ptr, ptr %6, align 8, !tbaa !8
  %60 = sext i32 %58 to i64
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  store ptr %61, ptr %6, align 8, !tbaa !8
  %62 = load ptr, ptr %7, align 8, !tbaa !8
  %63 = load i32, ptr %8, align 4, !tbaa !10
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5 x ptr], ptr @var_names, i64 0, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !8
  %67 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.17, ptr noundef %66) #4
  %68 = load ptr, ptr %6, align 8, !tbaa !8
  %69 = load ptr, ptr %7, align 8, !tbaa !8
  %70 = call i32 @quote(ptr noundef %68, ptr noundef %69)
  store i32 %70, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %71

71:                                               ; preds = %57, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %72

72:                                               ; preds = %71, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %73 = load i32, ptr %4, align 4
  ret i32 %73
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@var_names = external dso_local local_unnamed_addr global [5 x ptr], align 16
@vars = external dso_local local_unnamed_addr global [5 x ptr], align 16
@.str.17 = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @quote(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @substitue(i8 noundef signext %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = load ptr, ptr @vars, align 16, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %9, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr @var_names, align 16, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = icmp eq i8 %7, %0
  br i1 %8, label %.thread, label %9

9:                                                ; preds = %3, %5
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @vars, i64 8), align 8, !tbaa !5
  %.not.1 = icmp eq ptr %10, null
  br i1 %.not.1, label %15, label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @var_names, i64 8), align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp eq i8 %13, %0
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %11, %9
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @vars, i64 16), align 16, !tbaa !5
  %.not.2 = icmp eq ptr %16, null
  br i1 %.not.2, label %21, label %17

17:                                               ; preds = %15
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @var_names, i64 16), align 16, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = icmp eq i8 %19, %0
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %17, %15
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @vars, i64 24), align 8, !tbaa !5
  %.not.3 = icmp eq ptr %22, null
  br i1 %.not.3, label %27, label %23

23:                                               ; preds = %21
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @var_names, i64 24), align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = icmp eq i8 %25, %0
  br i1 %26, label %.thread, label %27

27:                                               ; preds = %23, %21
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @vars, i64 32), align 16, !tbaa !5
  %.not.4 = icmp eq ptr %28, null
  br i1 %.not.4, label %44, label %29

29:                                               ; preds = %27
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @var_names, i64 32), align 16, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = icmp eq i8 %31, %0
  br i1 %32, label %.thread, label %44

.thread:                                          ; preds = %5, %11, %17, %23, %29
  %.01620.lcssa.wide = phi i64 [ 0, %5 ], [ 1, %11 ], [ 2, %17 ], [ 3, %23 ], [ 4, %29 ]
  %33 = getelementptr inbounds [5 x ptr], ptr @vars, i64 0, i64 %.01620.lcssa.wide
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %34) #3
  %sext = shl i64 %35, 32
  %36 = ashr exact i64 %sext, 32
  %37 = tail call i32 @strncmp(ptr noundef %1, ptr noundef %34, i64 noundef %36) #3
  %.not17 = icmp eq i32 %37, 0
  br i1 %.not17, label %38, label %44

38:                                               ; preds = %.thread
  %39 = getelementptr inbounds i8, ptr %1, i64 %36
  %40 = getelementptr inbounds [5 x ptr], ptr @var_names, i64 0, i64 %.01620.lcssa.wide
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.17, ptr noundef %41) #4
  %43 = tail call i32 @quote(ptr noundef %39, ptr noundef %2)
  br label %44

44:                                               ; preds = %27, %29, %38, %.thread
  %.1 = phi i32 [ %43, %38 ], [ -1, %.thread ], [ -1, %29 ], [ -1, %27 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #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 = { 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 #3 = { nounwind willreturn memory(read) }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass