#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 */
scalar_t__ floor(int);
void wave_len_validate(int sigInLen, int waveLength, int *lev, int *val) {
  int n;
  int m;
  *val = 0;
  if (sigInLen < 2 * waveLength) {
    *lev = 0;
    *val = 0;
    return;
  } else {
    *val = 1;
    *lev = 0;
    n = sigInLen;
    do {
      m = (int)floor((n + waveLength - 1) / 2);
      *lev += 1;
      n = m;
    } while (m >= 2 * waveLength);
    return;
  }
}


x86 assembly (clang, -O0):
<wave_len_validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    115a <wave_len_validate+0x4a>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11b6 <wave_len_validate+0xa6>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <floor@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    1174 <wave_len_validate+0x64>
jmp    11b6 <wave_len_validate+0xa6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wave_len_validate>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebx
lea    (%rbx,%rbx,1),%ebp
cmp    %edi,%ebp
jle    112f <wave_len_validate+0x1f>
movl   $0x0,(%r14)
movl   $0x0,(%rcx)
jmp    1168 <wave_len_validate+0x58>
mov    %edi,%eax
movl   $0x1,(%rcx)
movl   $0x0,(%r14)
add    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1030 <floor@plt>
addl   $0x1,(%r14)
cmp    %eax,%ebp
jle    1150 <wave_len_validate+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @wave_len_validate(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
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i32*, i32** %8
store i32 0, i32* %11
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = mul nsw i32 2, %13
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i32*, i32** %7
store i32 0, i32* %17
%18 = load i32*, i32** %8
store i32 0, i32* %18
br label %41
19: ; preds = %4
%20 = load i32*, i32** %8
store i32 1, i32* %20
%21 = load i32*, i32** %7
store i32 0, i32* %21
%22 = load i32, i32* %5
store i32 %22, i32* %9
br label %23
23: ; preds = %35, %19
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = add nsw i32 %24, %25
%27 = sub nsw i32 %26, 1
%28 = sdiv i32 %27, 2
%29 = call i64 @floor(i32 %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %10
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1
store i32 %33, i32* %31
%34 = load i32, i32* %10
store i32 %34, i32* %9
br label %35
35: ; preds = %23
%36 = load i32, i32* %10
%37 = load i32, i32* %6
%38 = mul nsw i32 2, %37
%39 = icmp sge i32 %36, %38
br i1 %39, label %23, label %40
40: ; preds = %35
br label %41
41: ; preds = %40, %16
ret void
}

LLVM IR (-O2):
define void @wave_len_validate(i32 %0, i32 %1, i32* nocapture %2, i32* nocapture writeonly %3) {
%5 = shl nsw i32 %1, 1
%6 = icmp sgt i32 %5, %0
br i1 %6, label %7, label %8
7: ; preds = %4
store i32 0, i32* %2
store i32 0, i32* %3
br label %19
8: ; preds = %4
store i32 1, i32* %3
store i32 0, i32* %2
%9 = add i32 %1, -1
br label %10
10: ; preds = %10, %8
%11 = phi i32 [ %0, %8 ], [ %15, %10 ]
%12 = add i32 %9, %11
%13 = sdiv i32 %12, 2
%14 = tail call i64 @floor(i32 %13)
%15 = trunc i64 %14 to i32
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
%18 = icmp sgt i32 %5, %15
br i1 %18, label %19, label %10
19: ; preds = %10, %7
ret void
}