#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*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ cleanup_window(int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ mvaddstr(int, int, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ usleep(int);
void animate_waves(WINDOW *titlescr, int y_mid, int wave_x) {
  int pid;
  if ((pid = fork()) < 0) {
    perror("fork");
    cleanup_window(titlescr);
  }
  if (pid == 0) {
    int i = 0;
    while (true) {
      mvaddstr(y_mid + 1, wave_x + (5 * ((i + 0) % 5)), "~._.~");
      mvaddstr(y_mid + 1, wave_x + (5 * ((i + 1) % 5)), "._.~.");
      mvaddstr(y_mid + 1, wave_x + (5 * ((i + 2) % 5)), "_.~._");
      mvaddstr(y_mid + 1, wave_x + (5 * ((i + 3) % 5)), ".~._.");
      mvaddstr(y_mid + 1, wave_x + (5 * ((i + 4) % 5)), "~._.~");
      refresh();
      usleep(75000);
      ++i;
    }
  }
  getchar();
  kill(pid, SIGKILL);
  return;
}


x86 assembly (clang, -O0):
<animate_waves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ba <animate_waves+0x3a>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
mov    -0x8(%rbp),%rdi
call   1050 <cleanup_window@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12e2 <animate_waves+0x162>
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x58(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0x54(%rbp)
mov    $0x5,%ecx
cltd
idiv   %ecx
imul   $0x5,%edx,%eax
add    %eax,%esi
mov    %esi,-0x50(%rbp)
lea    0xe0e(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x4c(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    $0x5,%ecx
cltd
idiv   %ecx
imul   $0x5,%edx,%eax
add    %eax,%esi
mov    %esi,-0x44(%rbp)
lea    0xde3(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x40(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x5,%ecx
cltd
idiv   %ecx
imul   $0x5,%edx,%eax
add    %eax,%esi
mov    %esi,-0x38(%rbp)
lea    0xdb8(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x34(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x30(%rbp)
mov    $0x5,%ecx
cltd
idiv   %ecx
imul   $0x5,%edx,%eax
add    %eax,%esi
mov    %esi,-0x2c(%rbp)
lea    0xd8d(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x28(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    $0x5,%ecx
cltd
idiv   %ecx
imul   $0x5,%edx,%eax
add    %eax,%esi
mov    %esi,-0x20(%rbp)
lea    0xd4a(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x124f8,%edi
call   10a0 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x18(%rbp)
jmp    11cb <animate_waves+0x4b>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    -0x14(%rbp),%edi
mov    0x2ced(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<animate_waves>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r15
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%r14d
test   %eax,%eax
js     136e <animate_waves+0x1ee>
je     11d0 <animate_waves+0x50>
xor    %eax,%eax
call   1030 <getchar@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <kill@plt>
add    $0x1,%ebx
mov    %ebx,0x10(%rsp)
lea    0x14(%r12),%ebx
lea    0xf(%r12),%r8d
lea    0xa(%r12),%r14d
lea    0x5(%r12),%r9d
mov    $0x4,%edi
mov    $0x3,%r10d
mov    $0x2,%ebp
mov    $0x1,%ecx
movl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%r15d
nopl   (%rax)
mov    %ecx,0x18(%rsp)
mov    %ebp,0x1c(%rsp)
mov    %r10d,0x20(%rsp)
mov    %edi,0x24(%rsp)
mov    %r9d,0x28(%rsp)
mov    %r8d,0x2c(%rsp)
mov    %ebx,0xc(%rsp)
mov    %r12,0x30(%rsp)
mov    0x8(%rsp),%ebx
mov    %ebx,%eax
mov    $0xcccccccd,%edx
imul   %rdx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%eax
mov    %r12d,%esi
sub    %eax,%esi
mov    %edi,%eax
imul   %rdx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%eax
mov    0xc(%rsp),%edi
sub    %eax,%edi
mov    %edi,0x14(%rsp)
mov    %r10d,%eax
imul   %rdx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%eax
mov    %r8d,%r12d
sub    %eax,%r12d
mov    %ebp,%eax
imul   %rdx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%eax
mov    %r14d,%ebp
mov    %r14d,%r13d
sub    %eax,%r13d
mov    %ecx,%eax
imul   %rdx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%eax
mov    %r9d,%r14d
sub    %eax,%r14d
mov    %r15d,%edi
lea    0xd49(%rip),%rdx
call   1080 <mvaddstr@plt>
add    $0x1,%ebx
mov    %ebx,0x8(%rsp)
mov    %r15d,%edi
mov    %r14d,%esi
lea    0xd36(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    %r15d,%edi
mov    %r13d,%esi
mov    %ebp,%r14d
lea    0xd27(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    0x30(%rsp),%r12
lea    0xd16(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    %r15d,%edi
mov    0x14(%rsp),%esi
mov    0xc(%rsp),%ebx
lea    0xced(%rip),%rdx
call   1080 <mvaddstr@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
mov    $0x124f8,%edi
call   10a0 <usleep@plt>
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%ebp
mov    0x20(%rsp),%r10d
mov    0x24(%rsp),%edi
mov    0x28(%rsp),%r9d
mov    0x2c(%rsp),%r8d
add    $0x5,%r12d
add    $0x5,%ebx
add    $0x1,%edi
add    $0x5,%r8d
add    $0x1,%r10d
add    $0x5,%r14d
add    $0x1,%ebp
add    $0x5,%r9d
add    $0x1,%ecx
jmp    1210 <animate_waves+0x90>
lea    0xc8b(%rip),%rdi
call   1070 <perror@plt>
mov    %r15,%rdi
call   1050 <cleanup_window@plt>
jmp    11aa <animate_waves+0x2a>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"~._.~\00"
@.str.2 = [6 x i8] c"._.~.\00"
@.str.3 = [6 x i8] c"_.~._\00"
@.str.4 = [6 x i8] c".~._.\00"
@SIGKILL = global i32 0
define void @animate_waves(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i32 (...) @fork()
store i32 %9, i32* %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = load i32*, i32** %4
%14 = call i32 @cleanup_window(i32* %13)
br label %15
15: ; preds = %11, %3
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %69
18: ; preds = %15
store i32 0, i32* %8
br label %19
19: ; preds = %18, %19
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
%22 = load i32, i32* %6
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 0
%25 = srem i32 %24, 5
%26 = mul nsw i32 5, %25
%27 = add nsw i32 %22, %26
%28 = call i32 @mvaddstr(i32 %21, i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %6
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
%34 = srem i32 %33, 5
%35 = mul nsw i32 5, %34
%36 = add nsw i32 %31, %35
%37 = call i32 @mvaddstr(i32 %30, i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 2
%43 = srem i32 %42, 5
%44 = mul nsw i32 5, %43
%45 = add nsw i32 %40, %44
%46 = call i32 @mvaddstr(i32 %39, i32 %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
%49 = load i32, i32* %6
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 3
%52 = srem i32 %51, 5
%53 = mul nsw i32 5, %52
%54 = add nsw i32 %49, %53
%55 = call i32 @mvaddstr(i32 %48, i32 %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
%58 = load i32, i32* %6
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 4
%61 = srem i32 %60, 5
%62 = mul nsw i32 5, %61
%63 = add nsw i32 %58, %62
%64 = call i32 @mvaddstr(i32 %57, i32 %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%65 = call i32 (...) @refresh()
%66 = call i32 @usleep(i32 75000)
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %19
69: ; preds = %15
%70 = call i32 (...) @getchar()
%71 = load i32, i32* %7
%72 = load i32, i32* @SIGKILL
%73 = call i32 @kill(i32 %71, i32 %72)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"~._.~\00"
@.str.2 = [6 x i8] c"._.~.\00"
@.str.3 = [6 x i8] c"_.~._\00"
@.str.4 = [6 x i8] c".~._.\00"
@SIGKILL = global i32 0
define void @animate_waves(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @cleanup_window(i32* %0)
br label %41
9: ; preds = %3
%10 = icmp eq i32 %4, 0
br i1 %10, label %11, label %41
11: ; preds = %9
%12 = add nsw i32 %1, 1
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ %19, %13 ], [ 0, %11 ]
%15 = urem i32 %14, 5
%16 = mul nuw nsw i32 %15, 5
%17 = add nsw i32 %16, %2
%18 = tail call i32 @mvaddstr(i32 %12, i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = add nuw nsw i32 %14, 1
%20 = urem i32 %19, 5
%21 = mul nuw nsw i32 %20, 5
%22 = add nsw i32 %21, %2
%23 = tail call i32 @mvaddstr(i32 %12, i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%24 = add nuw nsw i32 %14, 2
%25 = urem i32 %24, 5
%26 = mul nuw nsw i32 %25, 5
%27 = add nsw i32 %26, %2
%28 = tail call i32 @mvaddstr(i32 %12, i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%29 = add nuw nsw i32 %14, 3
%30 = urem i32 %29, 5
%31 = mul nuw nsw i32 %30, 5
%32 = add nsw i32 %31, %2
%33 = tail call i32 @mvaddstr(i32 %12, i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%34 = add nuw nsw i32 %14, 4
%35 = urem i32 %34, 5
%36 = mul nuw nsw i32 %35, 5
%37 = add nsw i32 %36, %2
%38 = tail call i32 @mvaddstr(i32 %12, i32 %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 (...) @refresh()
%40 = tail call i32 @usleep(i32 75000)
br label %13
41: ; preds = %6, %9
%42 = tail call i32 (...) @getchar()
%43 = load i32, i32* @SIGKILL
%44 = tail call i32 @kill(i32 %4, i32 %43)
ret void
}