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


x86 assembly (clang, -O0):
<run_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xf4240,-0x14(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jle    1166 <run_c+0x46>
movl   $0xf4240,-0xc(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    11a1 <run_c+0x81>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <run_sum_c@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <run_c+0x4d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_c>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
cmp    $0xf4241,%esi
jl     1150 <run_c+0x30>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xf4240,%r15d
xor    %ebx,%ebx
mov    $0x3e8,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <run_sum_c@plt>
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1160 <run_c+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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