#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 RAND_MAX;
int /*<<< orphan*/ putchar(char);
int rand();
void wave(unsigned length, unsigned jitter, unsigned noise, char c) {
  unsigned jit = rand() / (RAND_MAX / (2 * jitter + 1)) - 1;
  for (unsigned i = 0; i < length + jit; i++) {
    unsigned n = rand() / (RAND_MAX / 100);
    if (n < noise) {
      unsigned val = rand() / (RAND_MAX / 6);
      putchar('1' + val);
    } else {
      putchar(c);
    }
  }
}


x86 assembly (clang, -O0):
<wave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x24(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
xor    %edx,%edx
div    %ecx
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jae    1204 <wave+0xe4>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11e8 <wave+0xc8>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x31,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11f1 <wave+0xd1>
movsbl -0xd(%rbp),%edi
call   1030 <putchar@plt>
jmp    11f6 <wave+0xd6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116c <wave+0x4c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wave>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %esi,%ebx
mov    %edi,%r15d
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ecx
mov    0x2ea2(%rip),%r12
mov    (%r12),%eax
lea    (%rbx,%rbx,1),%esi
add    $0x1,%esi
xor    %edx,%edx
div    %esi
mov    %eax,%esi
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%ebx
add    %r15d,%ebx
add    $0xffffffff,%ebx
je     11d1 <wave+0xb1>
xor    %ebp,%ebp
jmp    117f <wave+0x5f>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
je     11d1 <wave+0xb1>
xor    %eax,%eax
call   1040 <rand@plt>
movslq (%r12),%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    %r14d,%eax
cmp    %r13d,%ecx
jae    1170 <wave+0x50>
xor    %eax,%eax
call   1040 <rand@plt>
movslq (%r12),%rcx
imul   $0x2aaaaaab,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
cltd
idiv   %ecx
add    $0x31,%al
jmp    1170 <wave+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define void @wave(i32 %0, i32 %1, i32 %2, i8 signext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%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 i8 %3, i8* %8
%13 = call i32 (...) @rand()
%14 = load i32, i32* @RAND_MAX
%15 = load i32, i32* %6
%16 = mul i32 2, %15
%17 = add i32 %16, 1
%18 = udiv i32 %14, %17
%19 = udiv i32 %13, %18
%20 = sub i32 %19, 1
store i32 %20, i32* %9
store i32 0, i32* %10
br label %21
21: ; preds = %48, %4
%22 = load i32, i32* %10
%23 = load i32, i32* %5
%24 = load i32, i32* %9
%25 = add i32 %23, %24
%26 = icmp ult i32 %22, %25
br i1 %26, label %27, label %51
27: ; preds = %21
%28 = call i32 (...) @rand()
%29 = load i32, i32* @RAND_MAX
%30 = sdiv i32 %29, 100
%31 = sdiv i32 %28, %30
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = load i32, i32* %7
%34 = icmp ult i32 %32, %33
br i1 %34, label %35, label %44
35: ; preds = %27
%36 = call i32 (...) @rand()
%37 = load i32, i32* @RAND_MAX
%38 = sdiv i32 %37, 6
%39 = sdiv i32 %36, %38
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = add i32 49, %40
%42 = trunc i32 %41 to i8
%43 = call i32 @putchar(i8 signext %42)
br label %47
44: ; preds = %27
%45 = load i8, i8* %8
%46 = call i32 @putchar(i8 signext %45)
br label %47
47: ; preds = %44, %35
br label %48
48: ; preds = %47
%49 = load i32, i32* %10
%50 = add i32 %49, 1
store i32 %50, i32* %10
br label %21
51: ; preds = %21
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define void @wave(i32 %0, i32 %1, i32 %2, i8 signext %3) {
%5 = tail call i32 (...) @rand()
%6 = load i32, i32* @RAND_MAX
%7 = shl i32 %1, 1
%8 = or i32 %7, 1
%9 = udiv i32 %6, %8
%10 = udiv i32 %5, %9
%11 = add i32 %0, -1
%12 = add i32 %11, %10
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %29, %4
ret void
15: ; preds = %4, %29
%16 = phi i32 [ %32, %29 ], [ 0, %4 ]
%17 = tail call i32 (...) @rand()
%18 = load i32, i32* @RAND_MAX
%19 = sdiv i32 %18, 100
%20 = sdiv i32 %17, %19
%21 = icmp ult i32 %20, %2
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = tail call i32 (...) @rand()
%24 = load i32, i32* @RAND_MAX
%25 = sdiv i32 %24, 6
%26 = sdiv i32 %23, %25
%27 = trunc i32 %26 to i8
%28 = add i8 %27, 49
br label %29
29: ; preds = %15, %22
%30 = phi i8 [ %28, %22 ], [ %3, %15 ]
%31 = tail call i32 @putchar(i8 signext %30)
%32 = add nuw i32 %16, 1
%33 = icmp eq i32 %32, %12
br i1 %33, label %14, label %15
}