; LLVM IR from artagnon/phoenixfs :: xdiff (xutils)

; 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.s_mmbuffer = type { ptr, i64 }
%struct.s_xdemitcb = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [30 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: 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 @xdl_emit_diffrec(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca [3 x %struct.s_mmbuffer], align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 2, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 48, ptr %13) #3
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 0
  %17 = getelementptr inbounds %struct.s_mmbuffer, ptr %16, i32 0, i32 0
  store ptr %15, ptr %17, align 16, !tbaa !13
  %18 = load i64, ptr %10, align 8, !tbaa !9
  %19 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 0
  %20 = getelementptr inbounds %struct.s_mmbuffer, ptr %19, i32 0, i32 1
  store i64 %18, ptr %20, align 8, !tbaa !15
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 1
  %23 = getelementptr inbounds %struct.s_mmbuffer, ptr %22, i32 0, i32 0
  store ptr %21, ptr %23, align 16, !tbaa !13
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 1
  %26 = getelementptr inbounds %struct.s_mmbuffer, ptr %25, i32 0, i32 1
  store i64 %24, ptr %26, align 8, !tbaa !15
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = icmp sgt i64 %27, 0
  br i1 %28, label %29, label %48

29:                                               ; preds = %5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = sub nsw i64 %31, 1
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !16
  %35 = sext i8 %34 to i32
  %36 = icmp ne i32 %35, 10
  br i1 %36, label %37, label %48

37:                                               ; preds = %29
  %38 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 2
  %39 = getelementptr inbounds %struct.s_mmbuffer, ptr %38, i32 0, i32 0
  store ptr @.str, ptr %39, align 16, !tbaa !13
  %40 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 2
  %41 = getelementptr inbounds %struct.s_mmbuffer, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 16, !tbaa !13
  %43 = call i64 @strlen(ptr noundef %42) #4
  %44 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 2
  %45 = getelementptr inbounds %struct.s_mmbuffer, ptr %44, i32 0, i32 1
  store i64 %43, ptr %45, align 8, !tbaa !15
  %46 = load i32, ptr %12, align 4, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %12, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %37, %29, %5
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.s_xdemitcb, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.s_xdemitcb, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  %55 = getelementptr inbounds [3 x %struct.s_mmbuffer], ptr %13, i64 0, i64 0
  %56 = load i32, ptr %12, align 4, !tbaa !11
  %57 = call i32 %51(ptr noundef %54, ptr noundef %55, i32 noundef %56)
  %58 = icmp slt i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %48
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %61

60:                                               ; preds = %48
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %61

61:                                               ; preds = %60, %59
  call void @llvm.lifetime.end.p0(i64 48, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %62 = load i32, ptr %6, align 4
  ret i32 %62
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(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 = { 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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"s_mmbuffer", !6, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"s_xdemitcb", !6, i64 0, !6, i64 8}
!19 = !{!18, !6, i64 0}


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

@.str = external hidden unnamed_addr constant [30 x i8], align 1

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

; 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
define dso_local range(i32 -1, 1) i32 @xdl_emit_diffrec(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #1 {
  %6 = alloca [3 x %struct.s_mmbuffer], align 16
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %6) #3
  store ptr %2, ptr %6, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %3, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %0, ptr %8, align 16, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  store i64 %1, ptr %9, align 8, !tbaa !11
  %10 = icmp sgt i64 %1, 0
  br i1 %10, label %11, label %19

11:                                               ; preds = %5
  %12 = getelementptr i8, ptr %0, i64 %1
  %13 = getelementptr i8, ptr %12, i64 -1
  %14 = load i8, ptr %13, align 1, !tbaa !12
  %.not = icmp eq i8 %14, 10
  br i1 %.not, label %19, label %15

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %6, i64 32
  store ptr @.str, ptr %16, align 16, !tbaa !5
  %17 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str) #4
  %18 = getelementptr inbounds i8, ptr %6, i64 40
  store i64 %17, ptr %18, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %15, %11, %5
  %.0 = phi i32 [ 3, %15 ], [ 2, %11 ], [ 2, %5 ]
  %20 = getelementptr inbounds i8, ptr %4, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %4, align 8, !tbaa !15
  %23 = call i32 %21(ptr noundef %22, ptr noundef nonnull %6, i32 noundef %.0) #3
  %.lobit = ashr i32 %23, 31
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %6) #3
  ret i32 %.lobit
}

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

attributes #0 = { mustprogress 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 = { 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 }
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, !7, i64 0}
!6 = !{!"s_mmbuffer", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !7, i64 8}
!14 = !{!"s_xdemitcb", !7, i64 0, !7, i64 8}
!15 = !{!14, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass