#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_vector_mul(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_vector_mul(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   1040 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    1199 <run_wasm+0x79>
mov    -0x4(%rbp),%edi
call   1030 <wm_1_vector_mul@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   1040 <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
call   1030 <wm_1_vector_mul@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 = %22, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %2
%17 = call i64 @wm_1_vector_mul(i32 %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
br label %22
22: ; preds = %15
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %12
25: ; preds = %12
%26 = load i32, i32* %3
ret i32 %26
}

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_vector_mul(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
}