; LLVM IR from 0intro/wmii :: lib/libstuff/x11/colors (loadcolor)

; 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.CTuple = type { %struct.Color, %struct.Color, %struct.Color, [64 x i8] }
%struct.Color = type { i16, i16, i16, i16, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @loadcolor(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [128 x i8], align 16
  %9 = alloca [4 x ptr], align 16
  %10 = 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 128, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 112, i1 false)
  %12 = getelementptr inbounds [128 x i8], ptr %8, i64 0, i64 0
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %26

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = ptrtoint ptr %17 to i64
  %20 = ptrtoint ptr %18 to i64
  %21 = sub i64 %19, %20
  %22 = add nsw i64 %21, 1
  %23 = trunc i64 %22 to i32
  %24 = call i32 @min(i32 noundef %23, i32 noundef 128)
  %25 = sext i32 %24 to i64
  br label %27

26:                                               ; preds = %3
  br label %27

27:                                               ; preds = %26, %16
  %28 = phi i64 [ %25, %16 ], [ 128, %26 ]
  %29 = trunc i64 %28 to i32
  %30 = call i32 @utflcpy(ptr noundef %12, ptr noundef %13, i32 noundef %29)
  %31 = getelementptr inbounds [4 x ptr], ptr %9, i64 0, i64 0
  %32 = getelementptr inbounds [128 x i8], ptr %8, i64 0, i64 0
  %33 = call i32 @stokenize(ptr noundef %31, i32 noundef 4, ptr noundef %32, ptr noundef @.str)
  %34 = icmp ugt i32 3, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

36:                                               ; preds = %27
  %37 = getelementptr inbounds [4 x ptr], ptr %9, i64 0, i64 0
  %38 = load ptr, ptr %37, align 16, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.CTuple, ptr %39, i32 0, i32 1
  %41 = call zeroext i1 @parsecolor(ptr noundef %38, ptr noundef %40)
  br i1 %41, label %42, label %54

42:                                               ; preds = %36
  %43 = getelementptr inbounds [4 x ptr], ptr %9, i64 0, i64 1
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.CTuple, ptr %45, i32 0, i32 0
  %47 = call zeroext i1 @parsecolor(ptr noundef %44, ptr noundef %46)
  br i1 %47, label %48, label %54

48:                                               ; preds = %42
  %49 = getelementptr inbounds [4 x ptr], ptr %9, i64 0, i64 2
  %50 = load ptr, ptr %49, align 16, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.CTuple, ptr %51, i32 0, i32 2
  %53 = call zeroext i1 @parsecolor(ptr noundef %50, ptr noundef %52)
  br i1 %53, label %55, label %54

54:                                               ; preds = %48, %42, %36
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

55:                                               ; preds = %48
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.CTuple, ptr %56, i32 0, i32 3
  %58 = getelementptr inbounds [64 x i8], ptr %57, i64 0, i64 0
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.CTuple, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.CTuple, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.CTuple, ptr %63, i32 0, i32 2
  %65 = getelementptr inbounds { i64, i64 }, ptr %60, i32 0, i32 0
  %66 = load i64, ptr %65, align 8
  %67 = getelementptr inbounds { i64, i64 }, ptr %60, i32 0, i32 1
  %68 = load i64, ptr %67, align 8
  %69 = call i32 (ptr, i32, ptr, ...) @snprint(ptr noundef %58, i32 noundef 64, ptr noundef @.str.1, i64 %66, i64 %68, ptr noundef byval(%struct.Color) align 8 %62, ptr noundef byval(%struct.Color) align 8 %64)
  %70 = getelementptr inbounds [4 x ptr], ptr %9, i64 0, i64 2
  %71 = load ptr, ptr %70, align 16, !tbaa !5
  %72 = getelementptr inbounds [4 x ptr], ptr %9, i64 0, i64 2
  %73 = load ptr, ptr %72, align 16, !tbaa !5
  %74 = call i64 @strlen(ptr noundef %73) #6
  %75 = getelementptr inbounds i8, ptr %71, i64 %74
  %76 = getelementptr inbounds [128 x i8], ptr %8, i64 0, i64 0
  %77 = ptrtoint ptr %75 to i64
  %78 = ptrtoint ptr %76 to i64
  %79 = sub i64 %77, %78
  %80 = trunc i64 %79 to i32
  store i32 %80, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

81:                                               ; preds = %55, %54, %35
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %8) #5
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @utflcpy(ptr noundef, ptr noundef, i32 noundef) #3

declare i32 @min(i32 noundef, i32 noundef) #3

declare i32 @stokenize(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3

declare zeroext i1 @parsecolor(ptr noundef, ptr noundef) #3

declare i32 @snprint(ptr noundef, i32 noundef, ptr noundef, ...) #3

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

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 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 #5 = { nounwind }
attributes #6 = { 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"}


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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @loadcolor(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [128 x i8], align 16
  %5 = alloca [4 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %0, i8 0, i64 112, i1 false)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %13, label %6

6:                                                ; preds = %3
  %7 = ptrtoint ptr %2 to i64
  %8 = ptrtoint ptr %1 to i64
  %9 = sub i64 %7, %8
  %10 = trunc i64 %9 to i32
  %11 = add i32 %10, 1
  %12 = tail call i32 @min(i32 noundef %11, i32 noundef 128) #5
  br label %13

13:                                               ; preds = %3, %6
  %14 = phi i32 [ %12, %6 ], [ 128, %3 ]
  %15 = call i32 @utflcpy(ptr noundef nonnull %4, ptr noundef %1, i32 noundef %14) #5
  %16 = call i32 @stokenize(ptr noundef nonnull %5, i32 noundef 4, ptr noundef nonnull %4, ptr noundef nonnull @.str) #5
  %17 = icmp ult i32 %16, 3
  br i1 %17, label %44, label %18

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = call zeroext i1 @parsecolor(ptr noundef %19, ptr noundef nonnull %20) #5
  br i1 %21, label %22, label %44

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %5, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = call zeroext i1 @parsecolor(ptr noundef %24, ptr noundef nonnull %0) #5
  br i1 %25, label %26, label %44

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %5, i64 16
  %28 = load ptr, ptr %27, align 16, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 32
  %30 = call zeroext i1 @parsecolor(ptr noundef %28, ptr noundef nonnull %29) #5
  br i1 %30, label %31, label %44

31:                                               ; preds = %26
  %32 = getelementptr inbounds i8, ptr %0, i64 48
  %33 = load i64, ptr %20, align 8
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  %35 = load i64, ptr %34, align 8
  %36 = call i32 (ptr, i32, ptr, ...) @snprint(ptr noundef nonnull %32, i32 noundef 64, ptr noundef nonnull @.str.1, i64 %33, i64 %35, ptr noundef nonnull byval(%struct.Color) align 8 %0, ptr noundef nonnull byval(%struct.Color) align 8 %29) #5
  %37 = load ptr, ptr %27, align 16, !tbaa !5
  %38 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %37) #6
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = ptrtoint ptr %39 to i64
  %41 = ptrtoint ptr %4 to i64
  %42 = sub i64 %40, %41
  %43 = trunc i64 %42 to i32
  br label %44

44:                                               ; preds = %18, %22, %26, %13, %31
  %.0 = phi i32 [ %43, %31 ], [ 0, %13 ], [ 0, %26 ], [ 0, %22 ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #5
  ret i32 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @utflcpy(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @min(i32 noundef, i32 noundef) local_unnamed_addr #3

declare i32 @stokenize(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare zeroext i1 @parsecolor(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @snprint(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #3

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { 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 #5 = { nounwind }
attributes #6 = { 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"}


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