PROGRAM ATCODER

implicit none
integer :: w,h,n,i,b_w,b_h
integer :: b_l=0, b_r=0, b_u=0, b_d=0 !それぞれ、黒色になる左、右、上、下側の長さ
integer,allocatable :: x(:),y(:),a(:)

read(*,*) w,h,n
allocate(x(n),y(n),a(n))

do i = 1, n
  read(*,*) x(i),y(i),a(i)
  if(a(i) == 1)then
    call chmax(b_l,x(i))
  else if(a(i) == 2)then
    call chmax(b_r,w-x(i))
  else if(a(i) == 3)then
    call chmax(b_u,y(i))
  else if(a(i) == 4)then
    call chmax(b_d,h-y(i))
  end if
end do

b_w = b_l+b_r ; b_h = b_u+b_d

if(b_w >= w .or. b_h >= h)then
  write(*,'(i0)') 0
  stop
end if

write(*,'(i0)') (w-b_w)*(h-b_h)

contains
!!!!!! サブルーチンは↓
subroutine chmax(dp,x)
implicit none
integer :: dp, x

if (dp < x) then
	dp = x
	return
end if

end subroutine
!!!!!!

END PROGRAM ATCODER
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEb_d = internal unnamed_addr global i32 0
@_QFEb_l = internal unnamed_addr global i32 0
@_QFEb_r = internal unnamed_addr global i32 0
@_QFEb_u = internal unnamed_addr global i32 0
@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEy.0 = internal unnamed_addr global ptr null
@_QQcl.627f5a2b697a391e9075d0d9db5f2c67 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7766/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.627f5a2b697a391e9075d0d9db5f2c67, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %1, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %9 = load i32, ptr %2, align 4, !tbaa !3
  %10 = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = call ptr @malloc(i64 %12)
  store ptr %13, ptr @_QFEx.0, align 8, !tbaa !7
  %14 = call ptr @malloc(i64 %12)
  store ptr %14, ptr @_QFEy.0, align 8, !tbaa !7
  %15 = call ptr @malloc(i64 %12)
  store ptr %15, ptr @_QFEa.0, align 8, !tbaa !7
  %16 = icmp sgt i32 %9, 0
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %17 = zext i32 %9 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %_QFPchmax.exit
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %_QFPchmax.exit ]
  %18 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.627f5a2b697a391e9075d0d9db5f2c67, i32 12)
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %19 = add nsw i64 %indvars.iv, -1
  %20 = getelementptr i32, ptr %.unpack, i64 %19
  %21 = call i1 @_FortranAioInputInteger(ptr %18, ptr %20, i32 4)
  %.unpack364 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %22 = add nsw i64 %indvars.iv, -1
  %23 = getelementptr i32, ptr %.unpack364, i64 %22
  %24 = call i1 @_FortranAioInputInteger(ptr %18, ptr %23, i32 4)
  %.unpack376 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %25 = add nsw i64 %indvars.iv, -1
  %26 = getelementptr i32, ptr %.unpack376, i64 %25
  %27 = call i1 @_FortranAioInputInteger(ptr %18, ptr %26, i32 4)
  %28 = call i32 @_FortranAioEndIoStatement(ptr %18)
  %.unpack388 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %29 = add nsw i64 %indvars.iv, -1
  %30 = getelementptr i32, ptr %.unpack388, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !3
  switch i32 %31, label %_QFPchmax.exit [
    i32 1, label %32
    i32 2, label %39
    i32 3, label %48
    i32 4, label %55
  ]

32:                                               ; preds = %.lr.ph
  %.unpack436 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %33 = add nsw i64 %indvars.iv, -1
  %34 = getelementptr i32, ptr %.unpack436, i64 %33
  %35 = load i32, ptr @_QFEb_l, align 4, !tbaa !3
  %36 = load i32, ptr %34, align 4, !tbaa !3
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %_QFPchmax.exit

38:                                               ; preds = %32
  store i32 %36, ptr @_QFEb_l, align 4, !tbaa !3
  br label %_QFPchmax.exit

39:                                               ; preds = %.lr.ph
  %40 = load i32, ptr %3, align 4, !tbaa !3
  %.unpack424 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %41 = add nsw i64 %indvars.iv, -1
  %42 = getelementptr i32, ptr %.unpack424, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !3
  %44 = sub i32 %40, %43
  %45 = load i32, ptr @_QFEb_r, align 4, !tbaa !3
  %46 = icmp slt i32 %45, %44
  br i1 %46, label %47, label %_QFPchmax.exit

47:                                               ; preds = %39
  store i32 %44, ptr @_QFEb_r, align 4, !tbaa !3
  br label %_QFPchmax.exit

48:                                               ; preds = %.lr.ph
  %.unpack412 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %49 = add nsw i64 %indvars.iv, -1
  %50 = getelementptr i32, ptr %.unpack412, i64 %49
  %51 = load i32, ptr @_QFEb_u, align 4, !tbaa !3
  %52 = load i32, ptr %50, align 4, !tbaa !3
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %_QFPchmax.exit

54:                                               ; preds = %48
  store i32 %52, ptr @_QFEb_u, align 4, !tbaa !3
  br label %_QFPchmax.exit

55:                                               ; preds = %.lr.ph
  %56 = load i32, ptr %1, align 4, !tbaa !3
  %.unpack400 = load ptr, ptr @_QFEy.0, align 8, !tbaa !7
  %57 = add nsw i64 %indvars.iv, -1
  %58 = getelementptr i32, ptr %.unpack400, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !3
  %60 = sub i32 %56, %59
  %61 = load i32, ptr @_QFEb_d, align 4, !tbaa !3
  %62 = icmp slt i32 %61, %60
  br i1 %62, label %63, label %_QFPchmax.exit

63:                                               ; preds = %55
  store i32 %60, ptr @_QFEb_d, align 4, !tbaa !3
  br label %_QFPchmax.exit

_QFPchmax.exit:                                   ; preds = %63, %55, %54, %48, %47, %39, %38, %32, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %17
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %_QFPchmax.exit, %0
  %64 = load i32, ptr @_QFEb_l, align 4, !tbaa !3
  %65 = load i32, ptr @_QFEb_r, align 4, !tbaa !3
  %66 = add i32 %65, %64
  %67 = load i32, ptr @_QFEb_u, align 4, !tbaa !3
  %68 = load i32, ptr @_QFEb_d, align 4, !tbaa !3
  %69 = add i32 %68, %67
  %70 = load i32, ptr %3, align 4, !tbaa !3
  %71 = icmp sge i32 %66, %70
  %72 = load i32, ptr %1, align 4, !tbaa !3
  %73 = icmp sge i32 %69, %72
  %74 = or i1 %71, %73
  br i1 %74, label %75, label %80

75:                                               ; preds = %._crit_edge
  %76 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.627f5a2b697a391e9075d0d9db5f2c67, i32 27)
  %77 = call i1 @_FortranAioOutputInteger32(ptr %76, i32 0)
  %78 = call i32 @_FortranAioEndIoStatement(ptr %76)
  %79 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

80:                                               ; preds = %._crit_edge
  %81 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.627f5a2b697a391e9075d0d9db5f2c67, i32 31)
  %82 = load i32, ptr %3, align 4, !tbaa !3
  %83 = sub i32 %82, %66
  %84 = load i32, ptr %1, align 4, !tbaa !3
  %85 = sub i32 %84, %69
  %86 = mul i32 %85, %83
  %87 = call i1 @_FortranAioOutputInteger32(ptr %81, i32 %86)
  %88 = call i32 @_FortranAioEndIoStatement(ptr %81)
  ret void
}

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
define void @_QFPchmax(ptr nocapture %0, ptr nocapture readonly %1) local_unnamed_addr #1 {
  %3 = load i32, ptr %0, align 4, !tbaa !3
  %4 = load i32, ptr %1, align 4, !tbaa !3
  %5 = icmp slt i32 %3, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  store i32 %4, ptr %0, align 4, !tbaa !3
  br label %7

7:                                                ; preds = %6, %2
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
