; LLVM IR from sbu-fsl/kernel-ml :: src/functions (cross_entropy_loss)

; 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.cross_entropy_loss = type { ptr, ptr, ptr }
%struct.matrix = type { i32, i32, i32, %union.anon }
%union.anon = type { ptr }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@__PRETTY_FUNCTION__.derivative_cross_entropy_loss = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @derivative_cross_entropy_loss(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.cross_entropy_loss, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %32

13:                                               ; preds = %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.cross_entropy_loss, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds %struct.matrix, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.cross_entropy_loss, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds %struct.matrix, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.cross_entropy_loss, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %struct.matrix, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !17
  %29 = call ptr @allocate_matrix(i32 noundef %18, i32 noundef %23, i32 noundef %28)
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cross_entropy_loss, ptr %30, i32 0, i32 2
  store ptr %29, ptr %31, align 8, !tbaa !11
  br label %79

32:                                               ; preds = %1
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cross_entropy_loss, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.matrix, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !14
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.cross_entropy_loss, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct.matrix, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = icmp ne i32 %37, %42
  br i1 %43, label %56, label %44

44:                                               ; preds = %32
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cross_entropy_loss, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.matrix, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cross_entropy_loss, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  %53 = getelementptr inbounds %struct.matrix, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = icmp ne i32 %49, %54
  br i1 %55, label %56, label %78

56:                                               ; preds = %44, %32
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.cross_entropy_loss, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  call void @free_matrix(ptr noundef %59)
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.cross_entropy_loss, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = getelementptr inbounds %struct.matrix, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !14
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.cross_entropy_loss, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = getelementptr inbounds %struct.matrix, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !16
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.cross_entropy_loss, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = getelementptr inbounds %struct.matrix, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 8, !tbaa !17
  %75 = call ptr @allocate_matrix(i32 noundef %64, i32 noundef %69, i32 noundef %74)
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.cross_entropy_loss, ptr %76, i32 0, i32 2
  store ptr %75, ptr %77, align 8, !tbaa !11
  br label %78

78:                                               ; preds = %56, %44
  br label %79

79:                                               ; preds = %78, %13
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %250, %79
  %81 = load i32, ptr %3, align 4, !tbaa !9
  %82 = load ptr, ptr %2, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.cross_entropy_loss, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !13
  %85 = getelementptr inbounds %struct.matrix, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 8, !tbaa !14
  %87 = icmp slt i32 %81, %86
  br i1 %87, label %88, label %253

88:                                               ; preds = %80
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.cross_entropy_loss, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  %92 = load i32, ptr %3, align 4, !tbaa !9
  %93 = call ptr @get_row(ptr noundef %91, i32 noundef %92)
  store ptr %93, ptr %8, align 8, !tbaa !5
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = call ptr @softmax(ptr noundef %94)
  store ptr %95, ptr %5, align 8, !tbaa !5
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.cross_entropy_loss, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !13
  %99 = getelementptr inbounds %struct.matrix, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !16
  %101 = load ptr, ptr %2, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.cross_entropy_loss, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !13
  %104 = getelementptr inbounds %struct.matrix, ptr %103, i32 0, i32 2
  %105 = load i32, ptr %104, align 8, !tbaa !17
  %106 = call ptr @allocate_matrix(i32 noundef 1, i32 noundef %100, i32 noundef %105)
  store ptr %106, ptr %6, align 8, !tbaa !5
  %107 = load ptr, ptr %2, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.cross_entropy_loss, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !13
  %110 = getelementptr inbounds %struct.matrix, ptr %109, i32 0, i32 2
  %111 = load i32, ptr %110, align 8, !tbaa !17
  switch i32 %111, label %153 [
    i32 1, label %112
    i32 2, label %132
    i32 0, label %152
  ]

112:                                              ; preds = %88
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.matrix, ptr %113, i32 0, i32 3
  %115 = load ptr, ptr %114, align 8, !tbaa !18
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.matrix, ptr %116, i32 0, i32 1
  %118 = load i32, ptr %117, align 4, !tbaa !16
  %119 = mul nsw i32 0, %118
  %120 = load ptr, ptr %2, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.cross_entropy_loss, ptr %120, i32 0, i32 1
  %122 = load ptr, ptr %121, align 8, !tbaa !19
  %123 = getelementptr inbounds %struct.matrix, ptr %122, i32 0, i32 3
  %124 = load ptr, ptr %123, align 8, !tbaa !18
  %125 = load i32, ptr %3, align 4, !tbaa !9
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds i32, ptr %124, i64 %126
  %128 = load i32, ptr %127, align 4, !tbaa !9
  %129 = add nsw i32 %119, %128
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds float, ptr %115, i64 %130
  store float 1.000000e+00, ptr %131, align 4, !tbaa !20
  br label %153

132:                                              ; preds = %88
  %133 = load ptr, ptr %6, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.matrix, ptr %133, i32 0, i32 3
  %135 = load ptr, ptr %134, align 8, !tbaa !18
  %136 = load ptr, ptr %6, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.matrix, ptr %136, i32 0, i32 1
  %138 = load i32, ptr %137, align 4, !tbaa !16
  %139 = mul nsw i32 0, %138
  %140 = load ptr, ptr %2, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.cross_entropy_loss, ptr %140, i32 0, i32 1
  %142 = load ptr, ptr %141, align 8, !tbaa !19
  %143 = getelementptr inbounds %struct.matrix, ptr %142, i32 0, i32 3
  %144 = load ptr, ptr %143, align 8, !tbaa !18
  %145 = load i32, ptr %3, align 4, !tbaa !9
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds i32, ptr %144, i64 %146
  %148 = load i32, ptr %147, align 4, !tbaa !9
  %149 = add nsw i32 %139, %148
  %150 = sext i32 %149 to i64
  %151 = getelementptr inbounds double, ptr %135, i64 %150
  store double 1.000000e+00, ptr %151, align 8, !tbaa !22
  br label %153

152:                                              ; preds = %88
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 104, ptr noundef @__PRETTY_FUNCTION__.derivative_cross_entropy_loss) #5
  unreachable

153:                                              ; preds = %132, %112, %88
  %154 = load ptr, ptr %2, align 8, !tbaa !5
  %155 = getelementptr inbounds %struct.cross_entropy_loss, ptr %154, i32 0, i32 0
  %156 = load ptr, ptr %155, align 8, !tbaa !13
  %157 = getelementptr inbounds %struct.matrix, ptr %156, i32 0, i32 1
  %158 = load i32, ptr %157, align 4, !tbaa !16
  %159 = load ptr, ptr %2, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.cross_entropy_loss, ptr %159, i32 0, i32 0
  %161 = load ptr, ptr %160, align 8, !tbaa !13
  %162 = getelementptr inbounds %struct.matrix, ptr %161, i32 0, i32 2
  %163 = load i32, ptr %162, align 8, !tbaa !17
  %164 = call ptr @allocate_matrix(i32 noundef 1, i32 noundef %158, i32 noundef %163)
  store ptr %164, ptr %7, align 8, !tbaa !5
  %165 = load ptr, ptr %5, align 8, !tbaa !5
  %166 = load ptr, ptr %6, align 8, !tbaa !5
  %167 = load ptr, ptr %7, align 8, !tbaa !5
  call void @matrix_sub(ptr noundef %165, ptr noundef %166, ptr noundef %167)
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %168

168:                                              ; preds = %242, %153
  %169 = load i32, ptr %4, align 4, !tbaa !9
  %170 = load ptr, ptr %2, align 8, !tbaa !5
  %171 = getelementptr inbounds %struct.cross_entropy_loss, ptr %170, i32 0, i32 0
  %172 = load ptr, ptr %171, align 8, !tbaa !13
  %173 = getelementptr inbounds %struct.matrix, ptr %172, i32 0, i32 1
  %174 = load i32, ptr %173, align 4, !tbaa !16
  %175 = icmp slt i32 %169, %174
  br i1 %175, label %176, label %245

176:                                              ; preds = %168
  %177 = load ptr, ptr %2, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.cross_entropy_loss, ptr %177, i32 0, i32 0
  %179 = load ptr, ptr %178, align 8, !tbaa !13
  %180 = getelementptr inbounds %struct.matrix, ptr %179, i32 0, i32 2
  %181 = load i32, ptr %180, align 8, !tbaa !17
  switch i32 %181, label %241 [
    i32 1, label %182
    i32 2, label %211
    i32 0, label %240
  ]

182:                                              ; preds = %176
  %183 = load ptr, ptr %7, align 8, !tbaa !5
  %184 = getelementptr inbounds %struct.matrix, ptr %183, i32 0, i32 3
  %185 = load ptr, ptr %184, align 8, !tbaa !18
  %186 = load ptr, ptr %7, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.matrix, ptr %186, i32 0, i32 1
  %188 = load i32, ptr %187, align 4, !tbaa !16
  %189 = mul nsw i32 0, %188
  %190 = load i32, ptr %4, align 4, !tbaa !9
  %191 = add nsw i32 %189, %190
  %192 = sext i32 %191 to i64
  %193 = getelementptr inbounds float, ptr %185, i64 %192
  %194 = load float, ptr %193, align 4, !tbaa !20
  %195 = load ptr, ptr %2, align 8, !tbaa !5
  %196 = getelementptr inbounds %struct.cross_entropy_loss, ptr %195, i32 0, i32 2
  %197 = load ptr, ptr %196, align 8, !tbaa !11
  %198 = getelementptr inbounds %struct.matrix, ptr %197, i32 0, i32 3
  %199 = load ptr, ptr %198, align 8, !tbaa !18
  %200 = load i32, ptr %3, align 4, !tbaa !9
  %201 = load ptr, ptr %2, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.cross_entropy_loss, ptr %201, i32 0, i32 2
  %203 = load ptr, ptr %202, align 8, !tbaa !11
  %204 = getelementptr inbounds %struct.matrix, ptr %203, i32 0, i32 1
  %205 = load i32, ptr %204, align 4, !tbaa !16
  %206 = mul nsw i32 %200, %205
  %207 = load i32, ptr %4, align 4, !tbaa !9
  %208 = add nsw i32 %206, %207
  %209 = sext i32 %208 to i64
  %210 = getelementptr inbounds float, ptr %199, i64 %209
  store float %194, ptr %210, align 4, !tbaa !20
  br label %241

211:                                              ; preds = %176
  %212 = load ptr, ptr %7, align 8, !tbaa !5
  %213 = getelementptr inbounds %struct.matrix, ptr %212, i32 0, i32 3
  %214 = load ptr, ptr %213, align 8, !tbaa !18
  %215 = load ptr, ptr %7, align 8, !tbaa !5
  %216 = getelementptr inbounds %struct.matrix, ptr %215, i32 0, i32 1
  %217 = load i32, ptr %216, align 4, !tbaa !16
  %218 = mul nsw i32 0, %217
  %219 = load i32, ptr %4, align 4, !tbaa !9
  %220 = add nsw i32 %218, %219
  %221 = sext i32 %220 to i64
  %222 = getelementptr inbounds double, ptr %214, i64 %221
  %223 = load double, ptr %222, align 8, !tbaa !22
  %224 = load ptr, ptr %2, align 8, !tbaa !5
  %225 = getelementptr inbounds %struct.cross_entropy_loss, ptr %224, i32 0, i32 2
  %226 = load ptr, ptr %225, align 8, !tbaa !11
  %227 = getelementptr inbounds %struct.matrix, ptr %226, i32 0, i32 3
  %228 = load ptr, ptr %227, align 8, !tbaa !18
  %229 = load i32, ptr %3, align 4, !tbaa !9
  %230 = load ptr, ptr %2, align 8, !tbaa !5
  %231 = getelementptr inbounds %struct.cross_entropy_loss, ptr %230, i32 0, i32 2
  %232 = load ptr, ptr %231, align 8, !tbaa !11
  %233 = getelementptr inbounds %struct.matrix, ptr %232, i32 0, i32 1
  %234 = load i32, ptr %233, align 4, !tbaa !16
  %235 = mul nsw i32 %229, %234
  %236 = load i32, ptr %4, align 4, !tbaa !9
  %237 = add nsw i32 %235, %236
  %238 = sext i32 %237 to i64
  %239 = getelementptr inbounds double, ptr %228, i64 %238
  store double %223, ptr %239, align 8, !tbaa !22
  br label %241

240:                                              ; preds = %176
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 124, ptr noundef @__PRETTY_FUNCTION__.derivative_cross_entropy_loss) #5
  unreachable

241:                                              ; preds = %211, %182, %176
  br label %242

242:                                              ; preds = %241
  %243 = load i32, ptr %4, align 4, !tbaa !9
  %244 = add nsw i32 %243, 1
  store i32 %244, ptr %4, align 4, !tbaa !9
  br label %168, !llvm.loop !24

245:                                              ; preds = %168
  %246 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free_matrix(ptr noundef %246)
  %247 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free_matrix(ptr noundef %247)
  %248 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free_matrix(ptr noundef %248)
  %249 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free_matrix(ptr noundef %249)
  br label %250

250:                                              ; preds = %245
  %251 = load i32, ptr %3, align 4, !tbaa !9
  %252 = add nsw i32 %251, 1
  store i32 %252, ptr %3, align 4, !tbaa !9
  br label %80, !llvm.loop !26

253:                                              ; preds = %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

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

declare ptr @allocate_matrix(i32 noundef, i32 noundef, i32 noundef) #2

declare ptr @get_row(ptr noundef, i32 noundef) #2

declare void @free_matrix(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 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

declare ptr @softmax(ptr noundef) #2

declare void @matrix_sub(ptr noundef, ptr noundef, ptr noundef) #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 = { 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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"cross_entropy_loss", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"matrix", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16}
!16 = !{!15, !10, i64 4}
!17 = !{!15, !10, i64 8}
!18 = !{!7, !7, i64 0}
!19 = !{!12, !6, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"double", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@__PRETTY_FUNCTION__.derivative_cross_entropy_loss = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @derivative_cross_entropy_loss(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.sink.split, label %5

5:                                                ; preds = %1
  %6 = load i32, ptr %3, align 8, !tbaa !10
  %7 = load ptr, ptr %0, align 8, !tbaa !13
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %.not = icmp eq i32 %6, %8
  br i1 %.not, label %9, label %14

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %7, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %.not59 = icmp eq i32 %11, %13
  br i1 %.not59, label %22, label %14

14:                                               ; preds = %9, %5
  tail call void @free_matrix(ptr noundef nonnull %3) #3
  br label %.sink.split

.sink.split:                                      ; preds = %1, %14
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = load i32, ptr %15, align 8, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %15, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %15, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = tail call ptr @allocate_matrix(i32 noundef %16, i32 noundef %18, i32 noundef %20) #3
  store ptr %21, ptr %2, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %.sink.split, %9
  %23 = load ptr, ptr %0, align 8, !tbaa !13
  %24 = load i32, ptr %23, align 8, !tbaa !10
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph67, label %._crit_edge68

.lr.ph67:                                         ; preds = %22
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  br label %27

27:                                               ; preds = %.lr.ph67, %._crit_edge
  %indvars.iv77 = phi i64 [ 0, %.lr.ph67 ], [ %indvars.iv.next78, %._crit_edge ]
  %28 = phi ptr [ %23, %.lr.ph67 ], [ %150, %._crit_edge ]
  %29 = trunc nuw nsw i64 %indvars.iv77 to i32
  %30 = tail call ptr @get_row(ptr noundef nonnull %28, i32 noundef %29) #3
  %31 = tail call ptr @softmax(ptr noundef %30) #3
  %32 = load ptr, ptr %0, align 8, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %32, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %32, i64 8
  %36 = load i32, ptr %35, align 8, !tbaa !15
  %37 = tail call ptr @allocate_matrix(i32 noundef 1, i32 noundef %34, i32 noundef %36) #3
  %38 = load ptr, ptr %0, align 8, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %38, i64 8
  %40 = load i32, ptr %39, align 8, !tbaa !15
  switch i32 %40, label %62 [
    i32 1, label %41
    i32 2, label %51
    i32 0, label %61
  ]

41:                                               ; preds = %27
  %42 = getelementptr inbounds i8, ptr %37, i64 16
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = load ptr, ptr %26, align 8, !tbaa !17
  %45 = getelementptr inbounds i8, ptr %44, i64 16
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = getelementptr inbounds i32, ptr %46, i64 %indvars.iv77
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %43, i64 %49
  store float 1.000000e+00, ptr %50, align 4, !tbaa !19
  br label %62

51:                                               ; preds = %27
  %52 = getelementptr inbounds i8, ptr %37, i64 16
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = load ptr, ptr %26, align 8, !tbaa !17
  %55 = getelementptr inbounds i8, ptr %54, i64 16
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = getelementptr inbounds i32, ptr %56, i64 %indvars.iv77
  %58 = load i32, ptr %57, align 4, !tbaa !18
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %53, i64 %59
  store double 1.000000e+00, ptr %60, align 8, !tbaa !21
  br label %62

61:                                               ; preds = %27
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 104, ptr noundef nonnull @__PRETTY_FUNCTION__.derivative_cross_entropy_loss) #4
  unreachable

62:                                               ; preds = %51, %41, %27
  %63 = getelementptr inbounds i8, ptr %38, i64 4
  %64 = load i32, ptr %63, align 4, !tbaa !14
  %65 = tail call ptr @allocate_matrix(i32 noundef 1, i32 noundef %64, i32 noundef %40) #3
  tail call void @matrix_sub(ptr noundef %31, ptr noundef %37, ptr noundef %65) #3
  %66 = load ptr, ptr %0, align 8, !tbaa !13
  %67 = getelementptr inbounds i8, ptr %66, i64 4
  %68 = load i32, ptr %67, align 4, !tbaa !14
  %69 = icmp sgt i32 %68, 0
  br i1 %69, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %62
  %70 = getelementptr inbounds i8, ptr %66, i64 8
  %71 = load i32, ptr %70, align 8, !tbaa !15
  %72 = getelementptr inbounds i8, ptr %65, i64 16
  switch i32 %71, label %._crit_edge [
    i32 0, label %137
    i32 1, label %.lr.ph.split.split.us
    i32 2, label %.lr.ph.split.split.us61
  ]

.lr.ph.split.split.us:                            ; preds = %.lr.ph
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 16
  %75 = getelementptr inbounds i8, ptr %73, i64 4
  %76 = load i32, ptr %75, align 4, !tbaa !14
  %77 = mul nsw i32 %76, %29
  %78 = sext i32 %77 to i64
  %wide.trip.count75 = zext nneg i32 %68 to i64
  %xtraiter89 = and i64 %wide.trip.count75, 3
  %79 = icmp ult i32 %68, 4
  br i1 %79, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.split.split.us.new

.lr.ph.split.split.us.new:                        ; preds = %.lr.ph.split.split.us
  %unroll_iter92 = and i64 %wide.trip.count75, 2147483644
  br label %80

80:                                               ; preds = %80, %.lr.ph.split.split.us.new
  %indvars.iv72 = phi i64 [ 0, %.lr.ph.split.split.us.new ], [ %indvars.iv.next73.3, %80 ]
  %niter93 = phi i64 [ 0, %.lr.ph.split.split.us.new ], [ %niter93.next.3, %80 ]
  %81 = load ptr, ptr %72, align 8, !tbaa !16
  %82 = getelementptr inbounds float, ptr %81, i64 %indvars.iv72
  %83 = load float, ptr %82, align 4, !tbaa !19
  %84 = load ptr, ptr %74, align 8, !tbaa !16
  %85 = getelementptr float, ptr %84, i64 %indvars.iv72
  %86 = getelementptr float, ptr %85, i64 %78
  store float %83, ptr %86, align 4, !tbaa !19
  %indvars.iv.next73 = or disjoint i64 %indvars.iv72, 1
  %87 = load ptr, ptr %72, align 8, !tbaa !16
  %88 = getelementptr inbounds float, ptr %87, i64 %indvars.iv.next73
  %89 = load float, ptr %88, align 4, !tbaa !19
  %90 = load ptr, ptr %74, align 8, !tbaa !16
  %91 = getelementptr float, ptr %90, i64 %indvars.iv.next73
  %92 = getelementptr float, ptr %91, i64 %78
  store float %89, ptr %92, align 4, !tbaa !19
  %indvars.iv.next73.1 = or disjoint i64 %indvars.iv72, 2
  %93 = load ptr, ptr %72, align 8, !tbaa !16
  %94 = getelementptr inbounds float, ptr %93, i64 %indvars.iv.next73.1
  %95 = load float, ptr %94, align 4, !tbaa !19
  %96 = load ptr, ptr %74, align 8, !tbaa !16
  %97 = getelementptr float, ptr %96, i64 %indvars.iv.next73.1
  %98 = getelementptr float, ptr %97, i64 %78
  store float %95, ptr %98, align 4, !tbaa !19
  %indvars.iv.next73.2 = or disjoint i64 %indvars.iv72, 3
  %99 = load ptr, ptr %72, align 8, !tbaa !16
  %100 = getelementptr inbounds float, ptr %99, i64 %indvars.iv.next73.2
  %101 = load float, ptr %100, align 4, !tbaa !19
  %102 = load ptr, ptr %74, align 8, !tbaa !16
  %103 = getelementptr float, ptr %102, i64 %indvars.iv.next73.2
  %104 = getelementptr float, ptr %103, i64 %78
  store float %101, ptr %104, align 4, !tbaa !19
  %indvars.iv.next73.3 = add nuw nsw i64 %indvars.iv72, 4
  %niter93.next.3 = add i64 %niter93, 4
  %niter93.ncmp.3 = icmp eq i64 %niter93.next.3, %unroll_iter92
  br i1 %niter93.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %80, !llvm.loop !23

.lr.ph.split.split.us61:                          ; preds = %.lr.ph
  %105 = load ptr, ptr %2, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i64 16
  %107 = getelementptr inbounds i8, ptr %105, i64 4
  %108 = load i32, ptr %107, align 4, !tbaa !14
  %109 = mul nsw i32 %108, %29
  %110 = sext i32 %109 to i64
  %wide.trip.count = zext nneg i32 %68 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %111 = icmp ult i32 %68, 4
  br i1 %111, label %._crit_edge.loopexit87.unr-lcssa, label %.lr.ph.split.split.us61.new

.lr.ph.split.split.us61.new:                      ; preds = %.lr.ph.split.split.us61
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %112

112:                                              ; preds = %112, %.lr.ph.split.split.us61.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.split.split.us61.new ], [ %indvars.iv.next.3, %112 ]
  %niter = phi i64 [ 0, %.lr.ph.split.split.us61.new ], [ %niter.next.3, %112 ]
  %113 = load ptr, ptr %72, align 8, !tbaa !16
  %114 = getelementptr inbounds double, ptr %113, i64 %indvars.iv
  %115 = load double, ptr %114, align 8, !tbaa !21
  %116 = load ptr, ptr %106, align 8, !tbaa !16
  %117 = getelementptr double, ptr %116, i64 %indvars.iv
  %118 = getelementptr double, ptr %117, i64 %110
  store double %115, ptr %118, align 8, !tbaa !21
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %119 = load ptr, ptr %72, align 8, !tbaa !16
  %120 = getelementptr inbounds double, ptr %119, i64 %indvars.iv.next
  %121 = load double, ptr %120, align 8, !tbaa !21
  %122 = load ptr, ptr %106, align 8, !tbaa !16
  %123 = getelementptr double, ptr %122, i64 %indvars.iv.next
  %124 = getelementptr double, ptr %123, i64 %110
  store double %121, ptr %124, align 8, !tbaa !21
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %125 = load ptr, ptr %72, align 8, !tbaa !16
  %126 = getelementptr inbounds double, ptr %125, i64 %indvars.iv.next.1
  %127 = load double, ptr %126, align 8, !tbaa !21
  %128 = load ptr, ptr %106, align 8, !tbaa !16
  %129 = getelementptr double, ptr %128, i64 %indvars.iv.next.1
  %130 = getelementptr double, ptr %129, i64 %110
  store double %127, ptr %130, align 8, !tbaa !21
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %131 = load ptr, ptr %72, align 8, !tbaa !16
  %132 = getelementptr inbounds double, ptr %131, i64 %indvars.iv.next.2
  %133 = load double, ptr %132, align 8, !tbaa !21
  %134 = load ptr, ptr %106, align 8, !tbaa !16
  %135 = getelementptr double, ptr %134, i64 %indvars.iv.next.2
  %136 = getelementptr double, ptr %135, i64 %110
  store double %133, ptr %136, align 8, !tbaa !21
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit87.unr-lcssa, label %112, !llvm.loop !23

137:                                              ; preds = %.lr.ph
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 124, ptr noundef nonnull @__PRETTY_FUNCTION__.derivative_cross_entropy_loss) #4
  unreachable

._crit_edge.loopexit.unr-lcssa:                   ; preds = %80, %.lr.ph.split.split.us
  %indvars.iv72.unr = phi i64 [ 0, %.lr.ph.split.split.us ], [ %indvars.iv.next73.3, %80 ]
  %lcmp.mod91.not = icmp eq i64 %xtraiter89, 0
  br i1 %lcmp.mod91.not, label %._crit_edge, label %.epil.preheader88

.epil.preheader88:                                ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader88
  %indvars.iv72.epil = phi i64 [ %indvars.iv.next73.epil, %.epil.preheader88 ], [ %indvars.iv72.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter90 = phi i64 [ %epil.iter90.next, %.epil.preheader88 ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %138 = load ptr, ptr %72, align 8, !tbaa !16
  %139 = getelementptr inbounds float, ptr %138, i64 %indvars.iv72.epil
  %140 = load float, ptr %139, align 4, !tbaa !19
  %141 = load ptr, ptr %74, align 8, !tbaa !16
  %142 = getelementptr float, ptr %141, i64 %indvars.iv72.epil
  %143 = getelementptr float, ptr %142, i64 %78
  store float %140, ptr %143, align 4, !tbaa !19
  %indvars.iv.next73.epil = add nuw nsw i64 %indvars.iv72.epil, 1
  %epil.iter90.next = add i64 %epil.iter90, 1
  %epil.iter90.cmp.not = icmp eq i64 %epil.iter90.next, %xtraiter89
  br i1 %epil.iter90.cmp.not, label %._crit_edge, label %.epil.preheader88, !llvm.loop !25

._crit_edge.loopexit87.unr-lcssa:                 ; preds = %112, %.lr.ph.split.split.us61
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.split.split.us61 ], [ %indvars.iv.next.3, %112 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit87.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit87.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit87.unr-lcssa ]
  %144 = load ptr, ptr %72, align 8, !tbaa !16
  %145 = getelementptr inbounds double, ptr %144, i64 %indvars.iv.epil
  %146 = load double, ptr %145, align 8, !tbaa !21
  %147 = load ptr, ptr %106, align 8, !tbaa !16
  %148 = getelementptr double, ptr %147, i64 %indvars.iv.epil
  %149 = getelementptr double, ptr %148, i64 %110
  store double %146, ptr %149, align 8, !tbaa !21
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !27

._crit_edge:                                      ; preds = %._crit_edge.loopexit87.unr-lcssa, %.epil.preheader, %._crit_edge.loopexit.unr-lcssa, %.epil.preheader88, %.lr.ph, %62
  tail call void @free_matrix(ptr noundef %37) #3
  tail call void @free_matrix(ptr noundef %65) #3
  tail call void @free_matrix(ptr noundef %31) #3
  tail call void @free_matrix(ptr noundef %30) #3
  %indvars.iv.next78 = add nuw nsw i64 %indvars.iv77, 1
  %150 = load ptr, ptr %0, align 8, !tbaa !13
  %151 = load i32, ptr %150, align 8, !tbaa !10
  %152 = sext i32 %151 to i64
  %153 = icmp slt i64 %indvars.iv.next78, %152
  br i1 %153, label %27, label %._crit_edge68, !llvm.loop !28

._crit_edge68:                                    ; preds = %._crit_edge, %22
  ret void
}

declare ptr @allocate_matrix(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare ptr @get_row(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @free_matrix(ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare ptr @softmax(ptr noundef) local_unnamed_addr #1

declare void @matrix_sub(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { noreturn 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 #3 = { nounwind }
attributes #4 = { noreturn 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, !7, i64 16}
!6 = !{!"cross_entropy_loss", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"matrix", !12, i64 0, !12, i64 4, !12, i64 8, !8, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!11, !12, i64 4}
!15 = !{!11, !12, i64 8}
!16 = !{!8, !8, i64 0}
!17 = !{!6, !7, i64 8}
!18 = !{!12, !12, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"float", !8, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"double", !8, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.unroll.disable"}
!27 = distinct !{!27, !26}
!28 = distinct !{!28, !24}


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