#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double parse_double(char *);
int /*<<< orphan*/ simulate(int /*<<< orphan*/, int /*<<< orphan*/, double *,
                            int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: simulate iterations weight0 weight1 ...\n");
    exit(1);
  }
  int simulations = atoi(argv[1]);
  int groups = argc - 2;
  double group_weights[groups];
  for (int i = 0; i < groups; ++i) {
    group_weights[i] = parse_double(argv[i + 2]);
  }
  simulate(stdin, stdout, group_weights, groups, simulations);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    118f <main+0x3f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0xfffffffe,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1213 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <parse_double@plt>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d6 <main+0x86>
mov    -0x38(%rbp),%rdx
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1030 <simulate@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jle    11db <main+0x8b>
mov    %rsi,%r12
mov    %edi,%r15d
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
add    $0xfffffffe,%r15d
mov    %rsp,%r13
lea    0xf(,%r15,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
xor    %ebx,%ebx
mov    0x10(%r12,%rbx,8),%rdi
call   1050 <parse_double@plt>
movsd  %xmm0,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <main+0x40>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <simulate@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"Usage: simulate iterations weight0 weight1 ...\0A\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 2
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %8
%27 = alloca double, i64 %25
store i64 %25, i64* %9
store i32 0, i32* %10
br label %28
28: ; preds = %43, %17
%29 = load i32, i32* %10
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %46
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call double @parse_double(i8* %38)
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %27, i64 %41
store double %39, double* %42
br label %43
43: ; preds = %32
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %28
46: ; preds = %28
%47 = load i32, i32* @stdin
%48 = load i32, i32* @stdout
%49 = load i32, i32* %7
%50 = load i32, i32* %6
%51 = call i32 @simulate(i32 %47, i32 %48, double* %27, i32 %49, i32 %50)
store i32 0, i32* %3
%52 = load i8*, i8** %8
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"Usage: simulate iterations weight0 weight1 ...\0A\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = add nsw i32 %0, -2
%13 = zext i32 %12 to i64
%14 = alloca double, i64 %13
br label %19
15: ; preds = %19
%16 = load i32, i32* @stdin
%17 = load i32, i32* @stdout
%18 = call i32 @simulate(i32 %16, i32 %17, double* %14, i32 %12, i32 %11)
ret i32 0
19: ; preds = %8, %19
%20 = phi i64 [ 0, %8 ], [ %26, %19 ]
%21 = add nuw nsw i64 %20, 2
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call double @parse_double(i8* %23)
%25 = getelementptr inbounds double, double* %14, i64 %20
store double %24, double* %25
%26 = add nuw nsw i64 %20, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %15, label %19
}