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

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

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

declare i32 @fputc(i32 noundef, ptr noundef) #1

; 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
declare dso_local i32 @substitue(i8 noundef signext, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @command(ptr noundef %0, ptr noundef %1, ...) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [1 x %struct.__va_list_tag], align 16
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = 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 24, ptr %6) #4
  %10 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %69, %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %11
  store i32 2, ptr %8, align 4
  br label %72

19:                                               ; preds = %11
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 37
  br i1 %25, label %26, label %57

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %27 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  %28 = getelementptr inbounds %struct.__va_list_tag, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 16
  %30 = icmp ule i32 %29, 40
  br i1 %30, label %31, label %36

31:                                               ; preds = %26
  %32 = getelementptr inbounds %struct.__va_list_tag, ptr %27, i32 0, i32 3
  %33 = load ptr, ptr %32, align 16
  %34 = getelementptr i8, ptr %33, i32 %29
  %35 = add i32 %29, 8
  store i32 %35, ptr %28, align 16
  br label %40

36:                                               ; preds = %26
  %37 = getelementptr inbounds %struct.__va_list_tag, ptr %27, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8
  %39 = getelementptr i8, ptr %38, i32 8
  store ptr %39, ptr %37, align 8
  br label %40

40:                                               ; preds = %36, %31
  %41 = phi ptr [ %34, %31 ], [ %38, %36 ]
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %7, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = call i32 @substitue(i8 noundef signext %47, ptr noundef %48, ptr noundef %49)
  %51 = icmp slt i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %40
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %54

53:                                               ; preds = %40
  store i32 0, ptr %8, align 4
  br label %54

54:                                               ; preds = %53, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %55 = load i32, ptr %8, align 4
  switch i32 %55, label %72 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  br label %68

57:                                               ; preds = %19
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i32 @fputc(i32 noundef %62, ptr noundef %63)
  %65 = icmp eq i32 %64, -1
  br i1 %65, label %66, label %67

66:                                               ; preds = %57
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %72

67:                                               ; preds = %57
  br label %68

68:                                               ; preds = %67, %56
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %7, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %7, align 8, !tbaa !9
  br label %11, !llvm.loop !12

72:                                               ; preds = %66, %54, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %73 = load i32, ptr %8, align 4
  switch i32 %73, label %81 [
    i32 2, label %74
  ]

74:                                               ; preds = %72
  %75 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %75)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = call i32 @fputc(i32 noundef 10, ptr noundef %76)
  %78 = icmp eq i32 %77, -1
  br i1 %78, label %79, label %80

79:                                               ; preds = %74
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

80:                                               ; preds = %74
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

81:                                               ; preds = %80, %79, %72
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  %82 = load i32, ptr %3, align 4
  ret i32 %82
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nocallback nofree nosync nounwind willreturn }
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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, 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"

%struct.__va_list_tag = type { i32, i32, ptr, ptr }

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @substitue(i8 noundef signext, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @command(ptr noundef %0, ptr nocapture noundef readonly %1, ...) local_unnamed_addr #2 {
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @llvm.va_start.p0(ptr nonnull %3)
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  br label %6

6:                                                ; preds = %32, %2
  %.018 = phi i64 [ 0, %2 ], [ %33, %32 ]
  %7 = getelementptr inbounds i8, ptr %1, i64 %.018
  %8 = load i8, ptr %7, align 1, !tbaa !5
  switch i8 %8, label %28 [
    i8 0, label %.critedge
    i8 37, label %9
  ]

9:                                                ; preds = %6
  %10 = load i32, ptr %3, align 16
  %11 = icmp ult i32 %10, 41
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load ptr, ptr %5, align 16
  %14 = zext nneg i32 %10 to i64
  %15 = getelementptr i8, ptr %13, i64 %14
  %16 = add nuw nsw i32 %10, 8
  store i32 %16, ptr %3, align 16
  br label %20

17:                                               ; preds = %9
  %18 = load ptr, ptr %4, align 8
  %19 = getelementptr i8, ptr %18, i64 8
  store ptr %19, ptr %4, align 8
  br label %20

20:                                               ; preds = %17, %12
  %21 = phi ptr [ %15, %12 ], [ %18, %17 ]
  %22 = load ptr, ptr %21, align 8, !tbaa !8
  %23 = add i64 %.018, 1
  %24 = getelementptr inbounds i8, ptr %1, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = call i32 @substitue(i8 noundef signext %25, ptr noundef %22, ptr noundef %0)
  %27 = icmp sgt i32 %26, -1
  br i1 %27, label %32, label %.loopexit

28:                                               ; preds = %6
  %29 = sext i8 %8 to i32
  %30 = call i32 @fputc(i32 noundef %29, ptr noundef %0)
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %.loopexit, label %32

32:                                               ; preds = %20, %28
  %.119 = phi i64 [ %23, %20 ], [ %.018, %28 ]
  %33 = add i64 %.119, 1
  br label %6, !llvm.loop !10

.critedge:                                        ; preds = %6
  call void @llvm.va_end.p0(ptr nonnull %3)
  %34 = call i32 @fputc(i32 noundef 10, ptr noundef %0)
  %35 = icmp eq i32 %34, -1
  %. = sext i1 %35 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %20, %28, %.critedge
  %.4 = phi i32 [ %., %.critedge ], [ -1, %28 ], [ -1, %20 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret i32 %.4
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nocallback nofree nosync nounwind willreturn }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass