#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*/ printf(char *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ wsentry1(int *, int);
void wsmain() {
  int counter = 5;
  while (counter > 0) {
    int arr[5] = {counter, counter + 1, counter + 2, counter + 3, counter + 4};
    usleep(1000 * 1000);
    printf("Calling entry point with array.\n");
    wsentry1(arr, 5);
    counter--;
  }
  printf("Done calling into WS, exiting\n");
}


x86 assembly (clang, -O0):
<wsmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x5,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11a5 <wsmain+0x75>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    $0xf4240,%edi
call   1050 <usleep@plt>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1040 <wsentry1@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    113f <wsmain+0xf>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wsmain>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x9,0x10(%rsp)
mov    $0xf4240,%edi
call   1050 <usleep@plt>
lea    0xf13(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <wsentry1@plt>
movaps 0xe96(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x8,0x10(%rsp)
mov    $0xf4240,%edi
call   1050 <usleep@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <wsentry1@plt>
movaps 0xe74(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x7,0x10(%rsp)
mov    $0xf4240,%edi
call   1050 <usleep@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <wsentry1@plt>
movaps 0xe52(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x6,0x10(%rsp)
mov    $0xf4240,%edi
call   1050 <usleep@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <wsentry1@plt>
movaps 0xe30(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x5,0x10(%rsp)
mov    $0xf4240,%edi
call   1050 <usleep@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <wsentry1@plt>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Calling entry point with array.\0A\00"
@.str.1 = [31 x i8] c"Done calling into WS, exiting\0A\00"
define void @wsmain() {
%1 = alloca i32
%2 = alloca [5 x i32]
store i32 5, i32* %1
br label %3
3: ; preds = %6, %0
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %27
6: ; preds = %3
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%8 = load i32, i32* %1
store i32 %8, i32* %7
%9 = getelementptr inbounds i32, i32* %7, i64 1
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %9
%12 = getelementptr inbounds i32, i32* %9, i64 1
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 2
store i32 %14, i32* %12
%15 = getelementptr inbounds i32, i32* %12, i64 1
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 3
store i32 %17, i32* %15
%18 = getelementptr inbounds i32, i32* %15, i64 1
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 4
store i32 %20, i32* %18
%21 = call i32 @usleep(i32 1000000)
%22 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%23 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%24 = call i32 @wsentry1(i32* %23, i32 5)
%25 = load i32, i32* %1
%26 = add nsw i32 %25, -1
store i32 %26, i32* %1
br label %3
27: ; preds = %3
%28 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@str = [30 x i8] c"Done calling into WS, exiting\00"
@str.2 = [32 x i8] c"Calling entry point with array.\00"
define void @wsmain() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%5 = bitcast [5 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, <4 x i32>* %5
store i32 9, i32* %4
%6 = call i32 @usleep(i32 1000000)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
%8 = call i32 @wsentry1(i32* %3, i32 5)
%9 = bitcast [5 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %9
store i32 8, i32* %4
%10 = call i32 @usleep(i32 1000000)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
%12 = call i32 @wsentry1(i32* %3, i32 5)
%13 = bitcast [5 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 3, i32 4, i32 5, i32 6>, <4 x i32>* %13
store i32 7, i32* %4
%14 = call i32 @usleep(i32 1000000)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
%16 = call i32 @wsentry1(i32* %3, i32 5)
%17 = bitcast [5 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 2, i32 3, i32 4, i32 5>, <4 x i32>* %17
store i32 6, i32* %4
%18 = call i32 @usleep(i32 1000000)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
%20 = call i32 @wsentry1(i32* %3, i32 5)
%21 = bitcast [5 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32>* %21
store i32 5, i32* %4
%22 = call i32 @usleep(i32 1000000)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
%24 = call i32 @wsentry1(i32* %3, i32 5)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
ret void
}