#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*/ filter_wavelet_square(int *, int, int, int, int);
int /*<<< orphan*/ wavelet_level(int *, int, int, int);
void wavelet(int *buf, int width, int height, int level) {
  int l, s;
  int *top;
  int *end;
  for (l = 0; l < level; l++) {
    top = buf;
    end = buf + height * width;
    s = width << l;
    while (top < end) {
      wavelet_level(top, width, l, 1);
      top += s;
    }
    top = buf;
    end = buf + width;
    s = 1 << l;
    while (top < end) {
      wavelet_level(top, height, l, width);
      top += s;
    }
    filter_wavelet_square(buf, width, height, level, l);
  }
}


x86 assembly (clang, -O0):
<wavelet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1236 <wavelet+0x116>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11b0 <wavelet+0x90>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    $0x1,%ecx
call   1030 <wavelet_level@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1174 <wavelet+0x54>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1212 <wavelet+0xf2>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1030 <wavelet_level@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    11d8 <wavelet+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <filter_wavelet_square@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <wavelet+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wavelet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x8(%rsp)
mov    %ecx,0x14(%rsp)
test   %ecx,%ecx
jle    121e <wavelet+0xfe>
mov    %edx,%r12d
mov    %esi,%r13d
mov    %edx,%eax
imul   %esi,%eax
mov    %eax,0x10(%rsp)
cltq
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rax
mov    %rax,0x20(%rsp)
movslq %esi,%rax
lea    (%rcx,%rax,4),%rax
mov    %rax,0x18(%rsp)
xor    %r14d,%r14d
mov    0x18(%rsp),%r15
jmp    11a2 <wavelet+0x82>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    0x14(%rsp),%ebx
mov    %ebx,%ecx
mov    %r14d,%r8d
call   1040 <filter_wavelet_square@plt>
add    $0x1,%r14d
cmp    %ebx,%r14d
je     121e <wavelet+0xfe>
mov    %r12d,%ebp
cmpl   $0x0,0x10(%rsp)
jle    11dd <wavelet+0xbd>
mov    %r13d,%eax
mov    %r14d,%ecx
shl    %cl,%eax
movslq %eax,%r12
shl    $0x2,%r12
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    $0x1,%ecx
call   1030 <wavelet_level@plt>
add    %r12,%rbx
cmp    0x20(%rsp),%rbx
jb     11c0 <wavelet+0xa0>
test   %r13d,%r13d
mov    %ebp,%r12d
jle    1180 <wavelet+0x60>
mov    $0x1,%eax
mov    %r14d,%ecx
shl    %cl,%eax
movslq %eax,%rbp
shl    $0x2,%rbp
mov    0x8(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %r13d,%ecx
call   1030 <wavelet_level@plt>
add    %rbp,%rbx
cmp    %r15,%rbx
jb     1200 <wavelet+0xe0>
jmp    1180 <wavelet+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @wavelet(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %13
13: ; preds = %70, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %73
17: ; preds = %13
%18 = load i32*, i32** %5
store i32* %18, i32** %11
%19 = load i32*, i32** %5
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = mul nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %19, i64 %23
store i32* %24, i32** %12
%25 = load i32, i32* %6
%26 = load i32, i32* %9
%27 = shl i32 %25, %26
store i32 %27, i32* %10
br label %28
28: ; preds = %32, %17
%29 = load i32*, i32** %11
%30 = load i32*, i32** %12
%31 = icmp ult i32* %29, %30
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32*, i32** %11
%34 = load i32, i32* %6
%35 = load i32, i32* %9
%36 = call i32 @wavelet_level(i32* %33, i32 %34, i32 %35, i32 1)
%37 = load i32, i32* %10
%38 = load i32*, i32** %11
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i32, i32* %38, i64 %39
store i32* %40, i32** %11
br label %28
41: ; preds = %28
%42 = load i32*, i32** %5
store i32* %42, i32** %11
%43 = load i32*, i32** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32* %46, i32** %12
%47 = load i32, i32* %9
%48 = shl i32 1, %47
store i32 %48, i32* %10
br label %49
49: ; preds = %53, %41
%50 = load i32*, i32** %11
%51 = load i32*, i32** %12
%52 = icmp ult i32* %50, %51
br i1 %52, label %53, label %63
53: ; preds = %49
%54 = load i32*, i32** %11
%55 = load i32, i32* %7
%56 = load i32, i32* %9
%57 = load i32, i32* %6
%58 = call i32 @wavelet_level(i32* %54, i32 %55, i32 %56, i32 %57)
%59 = load i32, i32* %10
%60 = load i32*, i32** %11
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i32, i32* %60, i64 %61
store i32* %62, i32** %11
br label %49
63: ; preds = %49
%64 = load i32*, i32** %5
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = load i32, i32* %8
%68 = load i32, i32* %9
%69 = call i32 @filter_wavelet_square(i32* %64, i32 %65, i32 %66, i32 %67, i32 %68)
br label %70
70: ; preds = %63
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
br label %13
73: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @wavelet(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %37
6: ; preds = %4
%7 = mul nsw i32 %2, %1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = icmp sgt i32 %7, 0
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = icmp sgt i32 %1, 0
br label %14
14: ; preds = %6, %33
%15 = phi i32 [ 0, %6 ], [ %35, %33 ]
br i1 %10, label %16, label %24
16: ; preds = %14
%17 = shl i32 %1, %15
%18 = sext i32 %17 to i64
br label %19
19: ; preds = %16, %19
%20 = phi i32* [ %0, %16 ], [ %22, %19 ]
%21 = tail call i32 @wavelet_level(i32* %20, i32 %1, i32 %15, i32 1)
%22 = getelementptr inbounds i32, i32* %20, i64 %18
%23 = icmp ult i32* %22, %9
br i1 %23, label %19, label %24
24: ; preds = %19, %14
br i1 %13, label %25, label %33
25: ; preds = %24
%26 = shl nuw i32 1, %15
%27 = sext i32 %26 to i64
br label %28
28: ; preds = %25, %28
%29 = phi i32* [ %0, %25 ], [ %31, %28 ]
%30 = tail call i32 @wavelet_level(i32* %29, i32 %2, i32 %15, i32 %1)
%31 = getelementptr inbounds i32, i32* %29, i64 %27
%32 = icmp ult i32* %31, %12
br i1 %32, label %28, label %33
33: ; preds = %28, %24
%34 = tail call i32 @filter_wavelet_square(i32* %0, i32 %1, i32 %2, i32 %3, i32 %15)
%35 = add nuw nsw i32 %15, 1
%36 = icmp eq i32 %35, %3
br i1 %36, label %37, label %14
37: ; preds = %33, %4
ret void
}