; LLVM IR from Dynmi/AlexNet :: src (convolution_layer)

; 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.conv_op = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16 }
%struct.conv_args = type { ptr, i16, i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local void @conv_op_forward(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.conv_op, ptr %8, i32 0, i32 20
  %10 = load i16, ptr %9, align 4, !tbaa !9
  %11 = sext i16 %10 to i32
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.conv_op, ptr %12, i32 0, i32 9
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.conv_op, ptr %15, i32 0, i32 11
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = mul nsw i32 %14, %17
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.conv_op, ptr %19, i32 0, i32 11
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = mul nsw i32 %18, %21
  %23 = mul nsw i32 %11, %22
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.conv_op, ptr %24, i32 0, i32 16
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.conv_op, ptr %27, i32 0, i32 17
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = mul nsw i32 %26, %29
  %31 = mul nsw i32 %23, %30
  %32 = sext i32 %31 to i64
  %33 = call noalias ptr @calloc(i64 noundef %32, i64 noundef 4) #6
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.conv_op, ptr %34, i32 0, i32 8
  store ptr %33, ptr %35, align 8, !tbaa !17
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.conv_op, ptr %36, i32 0, i32 20
  %38 = load i16, ptr %37, align 4, !tbaa !9
  %39 = sext i16 %38 to i32
  %40 = add nsw i32 %39, 1
  %41 = zext i32 %40 to i64
  %42 = call ptr @llvm.stacksave.p0()
  store ptr %42, ptr %3, align 8
  %43 = alloca %struct.conv_args, i64 %41, align 16
  store i64 %41, ptr %4, align 8
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.conv_op, ptr %44, i32 0, i32 20
  %46 = load i16, ptr %45, align 4, !tbaa !9
  %47 = sext i16 %46 to i32
  %48 = add nsw i32 %47, 1
  %49 = zext i32 %48 to i64
  %50 = alloca i64, i64 %49, align 16
  store i64 %49, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %51

51:                                               ; preds = %78, %1
  %52 = load i32, ptr %6, align 4, !tbaa !18
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.conv_op, ptr %53, i32 0, i32 20
  %55 = load i16, ptr %54, align 4, !tbaa !9
  %56 = sext i16 %55 to i32
  %57 = icmp slt i32 %52, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %81

59:                                               ; preds = %51
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !18
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.conv_args, ptr %43, i64 %62
  %64 = getelementptr inbounds %struct.conv_args, ptr %63, i32 0, i32 0
  store ptr %60, ptr %64, align 16, !tbaa !19
  %65 = load i32, ptr %6, align 4, !tbaa !18
  %66 = trunc i32 %65 to i16
  %67 = load i32, ptr %6, align 4, !tbaa !18
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.conv_args, ptr %43, i64 %68
  %70 = getelementptr inbounds %struct.conv_args, ptr %69, i32 0, i32 1
  store i16 %66, ptr %70, align 8, !tbaa !21
  %71 = load i32, ptr %6, align 4, !tbaa !18
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i64, ptr %50, i64 %72
  %74 = load i32, ptr %6, align 4, !tbaa !18
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds %struct.conv_args, ptr %43, i64 %75
  %77 = call i32 @pthread_create(ptr noundef %73, ptr noundef null, ptr noundef @pthread_conv_op_forward, ptr noundef %76) #7
  br label %78

78:                                               ; preds = %59
  %79 = load i32, ptr %6, align 4, !tbaa !18
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %6, align 4, !tbaa !18
  br label %51, !llvm.loop !22

81:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %82

82:                                               ; preds = %96, %81
  %83 = load i32, ptr %7, align 4, !tbaa !18
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.conv_op, ptr %84, i32 0, i32 20
  %86 = load i16, ptr %85, align 4, !tbaa !9
  %87 = sext i16 %86 to i32
  %88 = icmp slt i32 %83, %87
  br i1 %88, label %90, label %89

89:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %99

90:                                               ; preds = %82
  %91 = load i32, ptr %7, align 4, !tbaa !18
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds i64, ptr %50, i64 %92
  %94 = load i64, ptr %93, align 8, !tbaa !24
  %95 = call i32 @pthread_join(i64 noundef %94, ptr noundef null)
  br label %96

96:                                               ; preds = %90
  %97 = load i32, ptr %7, align 4, !tbaa !18
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %7, align 4, !tbaa !18
  br label %82, !llvm.loop !26

99:                                               ; preds = %89
  %100 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %100)
  ret void
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden ptr @pthread_conv_op_forward(ptr noundef) #0

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

declare i32 @pthread_join(i64 noundef, ptr noundef) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nounwind allocsize(0,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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { "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 #6 = { nounwind allocsize(0,1) }
attributes #7 = { 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, !12, i64 116}
!10 = !{!"conv_op", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !12, i64 116}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !11, i64 72}
!14 = !{!10, !11, i64 80}
!15 = !{!10, !11, i64 100}
!16 = !{!10, !11, i64 104}
!17 = !{!10, !6, i64 64}
!18 = !{!11, !11, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"conv_args", !6, i64 0, !12, i64 8, !12, i64 10, !12, i64 12}
!21 = !{!20, !12, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!25, !25, i64 0}
!25 = !{!"long", !7, i64 0}
!26 = distinct !{!26, !23}


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

; Function Attrs: nounwind uwtable
define dso_local void @conv_op_forward(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 116
  %3 = load i16, ptr %2, align 4, !tbaa !5
  %4 = sext i16 %3 to i32
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 100
  %10 = load i32, ptr %9, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 104
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %13 = mul i32 %6, %4
  %14 = mul i32 %13, %8
  %15 = mul i32 %14, %8
  %16 = mul i32 %15, %10
  %17 = mul i32 %16, %12
  %18 = sext i32 %17 to i64
  %19 = tail call noalias ptr @calloc(i64 noundef %18, i64 noundef 4) #4
  %20 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %19, ptr %20, align 8, !tbaa !16
  %21 = sext i16 %3 to i64
  %22 = add nsw i64 %21, 1
  %23 = and i64 %22, 4294967295
  %24 = alloca %struct.conv_args, i64 %23, align 16
  %25 = alloca i64, i64 %23, align 16
  %26 = icmp sgt i16 %3, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %27 = icmp sgt i16 %33, 0
  br i1 %27, label %.lr.ph25, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %28 = getelementptr inbounds %struct.conv_args, ptr %24, i64 %indvars.iv
  store ptr %0, ptr %28, align 16, !tbaa !17
  %29 = trunc i64 %indvars.iv to i16
  %30 = getelementptr inbounds i8, ptr %28, i64 8
  store i16 %29, ptr %30, align 8, !tbaa !19
  %31 = getelementptr inbounds i64, ptr %25, i64 %indvars.iv
  %32 = call i32 @pthread_create(ptr noundef nonnull %31, ptr noundef null, ptr noundef nonnull @pthread_conv_op_forward, ptr noundef nonnull %28) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load i16, ptr %2, align 4, !tbaa !5
  %34 = sext i16 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next, %34
  br i1 %35, label %.lr.ph, label %.preheader, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph25, %1, %.preheader
  ret void

.lr.ph25:                                         ; preds = %.preheader, %.lr.ph25
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph25 ], [ 0, %.preheader ]
  %36 = getelementptr inbounds i64, ptr %25, i64 %indvars.iv27
  %37 = load i64, ptr %36, align 8, !tbaa !22
  %38 = call i32 @pthread_join(i64 noundef %37, ptr noundef null) #5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %39 = load i16, ptr %2, align 4, !tbaa !5
  %40 = sext i16 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next28, %40
  br i1 %41, label %.lr.ph25, label %._crit_edge, !llvm.loop !24
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden ptr @pthread_conv_op_forward(ptr noundef) #0

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #3

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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 "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 = { "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 allocsize(0,1) }
attributes #5 = { 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, !11, i64 116}
!6 = !{!"conv_op", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !11, i64 116}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !10, i64 72}
!13 = !{!6, !10, i64 80}
!14 = !{!6, !10, i64 100}
!15 = !{!6, !10, i64 104}
!16 = !{!6, !7, i64 64}
!17 = !{!18, !7, i64 0}
!18 = !{!"conv_args", !7, i64 0, !11, i64 8, !11, i64 10, !11, i64 12}
!19 = !{!18, !11, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !23, i64 0}
!23 = !{!"long", !8, i64 0}
!24 = distinct !{!24, !21}


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