#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ wm_1_daxpy(int, int);
int run_wasm(int n) {
  int result = 0;
  const int max = 1000000;
  int i;
  if (n > max) {
    n = max;
    fprintf(stderr, "Asking for too much, vector.wast only allows 1M elements, "
                    "setting to 1M\n");
  }
  for (i = 0; i < 1000; i++) {
    result += wm_1_daxpy(n, n);
  }
  return result;
}


x86 assembly (clang, -O0):
<run_wasm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0xf4240,-0xc(%rbp)
cmpl   $0xf4240,-0x4(%rbp)
jle    1162 <run_wasm+0x42>
movl   $0xf4240,-0x4(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    119c <run_wasm+0x7c>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <wm_1_daxpy@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <run_wasm+0x49>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_wasm>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
cmp    $0xf4241,%edi
jl     114a <run_wasm+0x2a>
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
lea    0xec1(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xf4240,%r14d
xor    %ebp,%ebp
mov    $0x3e8,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r14d,%esi
call   1040 <wm_1_daxpy@plt>
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1160 <run_wasm+0x40>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [73 x i8] c"Asking for too much, vector.wast only allows 1M elements, setting to 1M\0A\00"
define i32 @run_wasm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1000000, i32* %4
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 1000000
br i1 %7, label %8, label %11
8: ; preds = %1
store i32 1000000, i32* %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %1
store i32 0, i32* %5
br label %12
12: ; preds = %23, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* %2
%17 = load i32, i32* %2
%18 = call i64 @wm_1_daxpy(i32 %16, i32 %17)
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %3
br label %23
23: ; preds = %15
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %12
26: ; preds = %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [73 x i8] c"Asking for too much, vector.wast only allows 1M elements, setting to 1M\0A\00"
define i32 @run_wasm(i32 %0) {
%2 = icmp sgt i32 %0, 1000000
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %3, %1
%7 = phi i32 [ 1000000, %3 ], [ %0, %1 ]
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 0, %6 ], [ %14, %8 ]
%10 = phi i32 [ 0, %6 ], [ %13, %8 ]
%11 = tail call i64 @wm_1_daxpy(i32 %7, i32 %7)
%12 = trunc i64 %11 to i32
%13 = add i32 %10, %12
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, 1000
br i1 %15, label %16, label %8
16: ; preds = %8
ret i32 %13
}