#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 */
typedef int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ clear();
int /*<<< orphan*/ mvprintw(int, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ refresh();
int wcslen(int /*<<< orphan*/ *);
void displayRipple(float *a, wchar_t *shades, int rows, int cols) {
  int x, y, slen = wcslen(shades);
  clear();
  for (y = 0; y < rows; ++y) {
    for (x = 0; x < cols; ++x) {
      int offset = (int)(a[y * cols + x]);
      if (offset < 0)
        offset = 0;
      mvprintw(y, x, "%lc", shades[offset % slen]);
    }
  }
  refresh();
}


x86 assembly (clang, -O0):
<displayRipple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <clear@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1205 <displayRipple+0xc5>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f2 <displayRipple+0xb2>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
cvttss2si (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11b9 <displayRipple+0x79>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe21(%rip),%rdx
call   1060 <mvprintw@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <displayRipple+0x43>
jmp    11f7 <displayRipple+0xb7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <displayRipple+0x30>
mov    $0x0,%al
call   1040 <refresh@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displayRipple>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,(%rsp)
mov    %edx,%ebp
mov    %rdi,%rbx
mov    %rsi,0x18(%rsp)
mov    %rsi,%rdi
call   1030 <wcslen@plt>
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   1050 <clear@plt>
test   %ebp,%ebp
jle    1219 <displayRipple+0xd9>
movslq (%rsp),%rax
mov    %ebp,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%ecx
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
lea    0xe6d(%rip),%rbp
xor    %r15d,%r15d
mov    0x18(%rsp),%r12
mov    0x4(%rsp),%r13d
jmp    11c0 <displayRipple+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15
add    0x10(%rsp),%rbx
cmp    0x8(%rsp),%r15
je     1219 <displayRipple+0xd9>
cmpl   $0x0,(%rsp)
mov    $0x0,%edx
jle    11b0 <displayRipple+0x70>
xor    %r14d,%r14d
mov    %rbx,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cvttss2si (%rbx,%r14,4),%eax
test   %eax,%eax
cmovs  %edx,%eax
cltd
idiv   %r13d
mov    %rcx,%rbx
mov    (%r12,%rdx,4),%ecx
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1060 <mvprintw@plt>
xor    %edx,%edx
mov    %rbx,%rcx
mov    0x20(%rsp),%rbx
add    $0x1,%r14
cmp    %r14,%rcx
jne    11e0 <displayRipple+0xa0>
jmp    11b0 <displayRipple+0x70>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <refresh@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%lc\00"
define void @displayRipple(float* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca float*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store float* %0, float** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32*, i32** %6
%14 = call i32 @wcslen(i32* %13)
store i32 %14, i32* %11
%15 = call i32 (...) @clear()
store i32 0, i32* %10
br label %16
16: ; preds = %54, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %57
20: ; preds = %16
store i32 0, i32* %9
br label %21
21: ; preds = %50, %20
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %53
25: ; preds = %21
%26 = load float*, float** %5
%27 = load i32, i32* %10
%28 = load i32, i32* %8
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %9
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %26, i64 %32
%34 = load float, float* %33
%35 = fptosi float %34 to i32
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %25
store i32 0, i32* %12
br label %39
39: ; preds = %38, %25
%40 = load i32, i32* %10
%41 = load i32, i32* %9
%42 = load i32*, i32** %6
%43 = load i32, i32* %12
%44 = load i32, i32* %11
%45 = srem i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %42, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @mvprintw(i32 %40, i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %39
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %21
53: ; preds = %21
br label %54
54: ; preds = %53
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %16
57: ; preds = %16
%58 = call i32 (...) @refresh()
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lc\00"
define void @displayRipple(float* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @wcslen(i32* %1)
%6 = tail call i32 (...) @clear()
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %37
8: ; preds = %4
%9 = icmp sgt i32 %3, 0
%10 = sext i32 %3 to i64
%11 = zext i32 %2 to i64
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %8, %34
%14 = phi i64 [ 0, %8 ], [ %35, %34 ]
br i1 %9, label %15, label %34
15: ; preds = %13
%16 = mul nsw i64 %14, %10
%17 = trunc i64 %14 to i32
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 0, %15 ], [ %32, %18 ]
%20 = add nsw i64 %19, %16
%21 = getelementptr inbounds float, float* %0, i64 %20
%22 = load float, float* %21
%23 = fptosi float %22 to i32
%24 = icmp sgt i32 %23, 0
%25 = select i1 %24, i32 %23, i32 0
%26 = srem i32 %25, %5
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %1, i64 %27
%29 = load i32, i32* %28
%30 = trunc i64 %19 to i32
%31 = tail call i32 @mvprintw(i32 %17, i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
%32 = add nuw nsw i64 %19, 1
%33 = icmp eq i64 %32, %12
br i1 %33, label %34, label %18
34: ; preds = %18, %13
%35 = add nuw nsw i64 %14, 1
%36 = icmp eq i64 %35, %11
br i1 %36, label %37, label %13
37: ; preds = %34, %4
%38 = tail call i32 (...) @refresh()
ret void
}