#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ compute_estimate(int, int, double *, double *, double *,
                                    double, double, int, int, int);
int /*<<< orphan*/ copy_block(int, int, int, int, double *, double *, int);
void sweep(int nx, int ny, double dx, double dy, double *f_, int itold,
           int itnew, double *u_, double *unew_, int block_size) {
  int it;
  int block_x, block_y;
  if (block_size == 0)
    block_size = nx;
  int max_blocks_x = (nx / block_size);
  int max_blocks_y = (ny / block_size);
#pragma omp parallel shared(u_, unew_, f_, max_blocks_x, max_blocks_y, nx, ny, \
                            dx, dy, itold, itnew,                              \
                            block_size) private(it, block_x, block_y)
  {
#pragma omp single
    {
      for (it = itold + 1; it <= itnew; it++) {
        for (block_x = 0; block_x < max_blocks_x; block_x++) {
          for (block_y = 0; block_y < max_blocks_y; block_y++) {
#pragma omp task shared(u_, unew_, nx, ny, block_size)                         \
    firstprivate(block_x, block_y)
            copy_block(nx, ny, block_x, block_y, u_, unew_, block_size);
          }
        }
#pragma omp taskwait
        for (block_x = 0; block_x < max_blocks_x; block_x++) {
          for (block_y = 0; block_y < max_blocks_y; block_y++) {
#pragma omp task default(none)                                                 \
    shared(u_, unew_, f_, dx, dy, nx, ny, block_size)                          \
        firstprivate(block_x, block_y)
            compute_estimate(block_x, block_y, u_, unew_, f_, dx, dy, nx, ny,
                             block_size);
          }
        }
#pragma omp taskwait
      }
    }
  }
}


x86 assembly (clang, -O0):
<sweep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpl   $0x0,0x18(%rbp)
jne    115e <sweep+0x3e>
mov    -0x4(%rbp),%eax
mov    %eax,0x18(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  0x18(%rbp)
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  0x18(%rbp)
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     127b <sweep+0x15b>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    11ed <sweep+0xcd>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11da <sweep+0xba>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r9
mov    0x18(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <copy_block@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a1 <sweep+0x81>
jmp    11df <sweep+0xbf>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118e <sweep+0x6e>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1268 <sweep+0x148>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1255 <sweep+0x135>
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x4(%rbp),%r9d
mov    -0x8(%rbp),%r10d
mov    0x18(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <compute_estimate@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1207 <sweep+0xe7>
jmp    125a <sweep+0x13a>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11f4 <sweep+0xd4>
jmp    126d <sweep+0x14d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117b <sweep+0x5b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sweep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x20(%rsp)
mov    %rdx,%r9
mov    %edi,%eax
mov    0x88(%rsp),%r10d
test   %r10d,%r10d
cmove  %edi,%r10d
mov    %edi,0xc(%rsp)
cltd
idiv   %r10d
mov    %eax,0x8(%rsp)
mov    %rsi,0x18(%rsp)
mov    %esi,%eax
cltd
idiv   %r10d
mov    %r8d,0x10(%rsp)
cmp    %r8d,%ecx
jge    12a5 <sweep+0x185>
mov    %eax,%r15d
mov    0x80(%rsp),%rax
mov    %r10,0x30(%rsp)
mov    %r9,0x28(%rsp)
movsd  %xmm1,0x40(%rsp)
movsd  %xmm0,0x38(%rsp)
jmp    119e <sweep+0x7e>
nop
mov    0x14(%rsp),%ecx
cmp    0x10(%rsp),%ecx
je     12a5 <sweep+0x185>
add    $0x1,%ecx
mov    %ecx,0x14(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    1190 <sweep+0x70>
xor    %ebp,%ebp
mov    0x20(%rsp),%r12
mov    0x18(%rsp),%r14
mov    0xc(%rsp),%r13d
jmp    11c9 <sweep+0xa9>
nop
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
je     1210 <sweep+0xf0>
test   %r15d,%r15d
jle    11c0 <sweep+0xa0>
xor    %ebx,%ebx
sub    $0x8,%rsp
mov    %r13d,%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r12,%r8
mov    0x88(%rsp),%r9
push   %r10
call   1040 <copy_block@plt>
mov    0x90(%rsp),%rax
mov    0x40(%rsp),%r10
add    $0x10,%rsp
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    11d0 <sweep+0xb0>
jmp    11c0 <sweep+0xa0>
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,0x8(%rsp)
mov    0x28(%rsp),%r9
jle    1190 <sweep+0x70>
xor    %r12d,%r12d
jmp    123f <sweep+0x11f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r12d
cmp    0x8(%rsp),%r12d
je     1190 <sweep+0x70>
test   %r15d,%r15d
mov    0x20(%rsp),%r13
mov    0x18(%rsp),%rbx
mov    0xc(%rsp),%r14d
jle    1230 <sweep+0x110>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
mov    %ebp,%esi
mov    %r13,%rdx
mov    %rax,%rcx
mov    %r9,%r8
movsd  0x38(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
mov    %r14d,%r9d
push   %r10
push   %rbx
call   1030 <compute_estimate@plt>
mov    0x90(%rsp),%rax
mov    0x40(%rsp),%r10
mov    0x38(%rsp),%r9
add    $0x10,%rsp
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1260 <sweep+0x140>
jmp    1230 <sweep+0x110>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sweep(i32 %0, i32 %1, double %2, double %3, double* %4, i32 %5, i32 %6, double* %7, double* %8, i32 %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca double*
%19 = alloca double*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store double %2, double* %13
store double %3, double* %14
store double* %4, double** %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store double* %7, double** %18
store double* %8, double** %19
store i32 %9, i32* %20
%26 = load i32, i32* %20
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %10
%29 = load i32, i32* %11
store i32 %29, i32* %20
br label %30
30: ; preds = %28, %10
%31 = load i32, i32* %11
%32 = load i32, i32* %20
%33 = sdiv i32 %31, %32
store i32 %33, i32* %24
%34 = load i32, i32* %12
%35 = load i32, i32* %20
%36 = sdiv i32 %34, %35
store i32 %36, i32* %25
%37 = load i32, i32* %16
%38 = add nsw i32 %37, 1
store i32 %38, i32* %21
br label %39
39: ; preds = %99, %30
%40 = load i32, i32* %21
%41 = load i32, i32* %17
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %102
43: ; preds = %39
store i32 0, i32* %22
br label %44
44: ; preds = %66, %43
%45 = load i32, i32* %22
%46 = load i32, i32* %24
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %69
48: ; preds = %44
store i32 0, i32* %23
br label %49
49: ; preds = %62, %48
%50 = load i32, i32* %23
%51 = load i32, i32* %25
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = load i32, i32* %11
%55 = load i32, i32* %12
%56 = load i32, i32* %22
%57 = load i32, i32* %23
%58 = load double*, double** %18
%59 = load double*, double** %19
%60 = load i32, i32* %20
%61 = call i32 @copy_block(i32 %54, i32 %55, i32 %56, i32 %57, double* %58, double* %59, i32 %60)
br label %62
62: ; preds = %53
%63 = load i32, i32* %23
%64 = add nsw i32 %63, 1
store i32 %64, i32* %23
br label %49
65: ; preds = %49
br label %66
66: ; preds = %65
%67 = load i32, i32* %22
%68 = add nsw i32 %67, 1
store i32 %68, i32* %22
br label %44
69: ; preds = %44
store i32 0, i32* %22
br label %70
70: ; preds = %95, %69
%71 = load i32, i32* %22
%72 = load i32, i32* %24
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %98
74: ; preds = %70
store i32 0, i32* %23
br label %75
75: ; preds = %91, %74
%76 = load i32, i32* %23
%77 = load i32, i32* %25
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %94
79: ; preds = %75
%80 = load i32, i32* %22
%81 = load i32, i32* %23
%82 = load double*, double** %18
%83 = load double*, double** %19
%84 = load double*, double** %15
%85 = load double, double* %13
%86 = load double, double* %14
%87 = load i32, i32* %11
%88 = load i32, i32* %12
%89 = load i32, i32* %20
%90 = call i32 @compute_estimate(i32 %80, i32 %81, double* %82, double* %83, double* %84, double %85, double %86, i32 %87, i32 %88, i32 %89)
br label %91
91: ; preds = %79
%92 = load i32, i32* %23
%93 = add nsw i32 %92, 1
store i32 %93, i32* %23
br label %75
94: ; preds = %75
br label %95
95: ; preds = %94
%96 = load i32, i32* %22
%97 = add nsw i32 %96, 1
store i32 %97, i32* %22
br label %70
98: ; preds = %70
br label %99
99: ; preds = %98
%100 = load i32, i32* %21
%101 = add nsw i32 %100, 1
store i32 %101, i32* %21
br label %39
102: ; preds = %39
ret void
}

LLVM IR (-O2):
define void @sweep(i32 %0, i32 %1, double %2, double %3, double* %4, i32 %5, i32 %6, double* %7, double* %8, i32 %9) {
%11 = icmp eq i32 %9, 0
%12 = select i1 %11, i32 %0, i32 %9
%13 = sdiv i32 %0, %12
%14 = sdiv i32 %1, %12
%15 = icmp slt i32 %5, %6
br i1 %15, label %16, label %45
16: ; preds = %10
%17 = icmp sgt i32 %13, 0
%18 = icmp sgt i32 %14, 0
br label %21
19: ; preds = %42, %21, %24
%20 = icmp eq i32 %23, %6
br i1 %20, label %45, label %21
21: ; preds = %16, %19
%22 = phi i32 [ %5, %16 ], [ %23, %19 ]
%23 = add i32 %22, 1
br i1 %17, label %25, label %19
24: ; preds = %32
br i1 %17, label %35, label %19
25: ; preds = %21, %32
%26 = phi i32 [ %33, %32 ], [ 0, %21 ]
br i1 %18, label %27, label %32
27: ; preds = %25, %27
%28 = phi i32 [ %30, %27 ], [ 0, %25 ]
%29 = tail call i32 @copy_block(i32 %0, i32 %1, i32 %26, i32 %28, double* %7, double* %8, i32 %12)
%30 = add nuw nsw i32 %28, 1
%31 = icmp eq i32 %30, %14
br i1 %31, label %32, label %27
32: ; preds = %27, %25
%33 = add nuw nsw i32 %26, 1
%34 = icmp eq i32 %33, %13
br i1 %34, label %24, label %25
35: ; preds = %24, %42
%36 = phi i32 [ %43, %42 ], [ 0, %24 ]
br i1 %18, label %37, label %42
37: ; preds = %35, %37
%38 = phi i32 [ %40, %37 ], [ 0, %35 ]
%39 = tail call i32 @compute_estimate(i32 %36, i32 %38, double* %7, double* %8, double* %4, double %2, double %3, i32 %0, i32 %1, i32 %12)
%40 = add nuw nsw i32 %38, 1
%41 = icmp eq i32 %40, %14
br i1 %41, label %42, label %37
42: ; preds = %37, %35
%43 = add nuw nsw i32 %36, 1
%44 = icmp eq i32 %43, %13
br i1 %44, label %19, label %35
45: ; preds = %19, %10
ret void
}