#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 */
double get_ivar(int);
double log(double);
double ndrand48();
int /*<<< orphan*/ perror(char *);
void one_gill_step(int meth, int nrxn, int *rxn, double *v) {
  double rate = 0, test;
  double r[1000];
  int i;
  switch (meth) {
  case 0:
    for (i = 0; i < nrxn; i++) {
      v[i + 1] = 0.0;
      r[i] = get_ivar(rxn[i]);
      rate += r[i];
    }
    if (rate <= 0.0)
      return;
    v[0] = -log(ndrand48()) / rate;
    test = rate * ndrand48();
    rate = r[0];
    for (i = 0; i < nrxn; i++) {
      if (test < rate) {
        v[i + 1] = 1.0;
        break;
      }
      rate += r[i + 1];
    }
    break;
  case 1:
    perror("Tau stepping method not implemented yet.");
    break;
  }
}


x86 assembly (clang, -O0):
<one_gill_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1f78(%rbp)
test   %eax,%eax
je     118b <one_gill_step+0x4b>
jmp    1177 <one_gill_step+0x37>
mov    -0x1f78(%rbp),%eax
sub    $0x1,%eax
je     130b <one_gill_step+0x1cb>
jmp    1317 <one_gill_step+0x1d7>
movl   $0x0,-0x1f74(%rbp)
mov    -0x1f74(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120d <one_gill_step+0xcd>
mov    -0x18(%rbp),%rax
mov    -0x1f74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x1f74(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <get_ivar@plt>
movslq -0x1f74(%rbp),%rax
movsd  %xmm0,-0x1f70(%rbp,%rax,8)
ff ff
movslq -0x1f74(%rbp),%rax
movsd  -0x1f70(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x1f74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f74(%rbp)
jmp    1195 <one_gill_step+0x55>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1220 <one_gill_step+0xe0>
jmp    1317 <one_gill_step+0x1d7>
mov    $0x0,%al
call   1030 <ndrand48@plt>
call   1040 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x1f80(%rbp)
ff
mov    $0x0,%al
call   1030 <ndrand48@plt>
movaps %xmm0,%xmm1
movsd  -0x1f80(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x1f70(%rbp),%xmm0
ff
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x1f74(%rbp)
mov    -0x1f74(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1306 <one_gill_step+0x1c6>
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12d4 <one_gill_step+0x194>
mov    -0x18(%rbp),%rax
mov    -0x1f74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xd36(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1306 <one_gill_step+0x1c6>
mov    -0x1f74(%rbp),%eax
add    $0x1,%eax
cltq
movsd  -0x1f70(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x1f74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f74(%rbp)
jmp    128f <one_gill_step+0x14f>
jmp    1317 <one_gill_step+0x1d7>
lea    0xcf6(%rip),%rdi
call   1050 <perror@plt>
add    $0x1f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<one_gill_step>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
test   %edi,%edi
je     117b <one_gill_step+0x3b>
cmp    $0x1,%edi
jne    1256 <one_gill_step+0x116>
lea    0xeab(%rip),%rdi
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <perror@plt>
mov    %esi,%r14d
test   %esi,%esi
jle    1256 <one_gill_step+0x116>
mov    %rcx,%r15
mov    %rdx,%r13
mov    %r14d,%r12d
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm1,0x8(%rsp)
lea    0x1(%rbx),%rbp
movq   $0x0,0x8(%r15,%rbx,8)
mov    0x0(%r13,%rbx,4),%edi
call   1060 <get_ivar@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x10(%rsp,%rbx,8)
addsd  %xmm0,%xmm1
mov    %rbp,%rbx
cmp    %rbp,%r12
jne    11a0 <one_gill_step+0x60>
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1256 <one_gill_step+0x116>
xor    %eax,%eax
movsd  %xmm1,0x8(%rsp)
call   1030 <ndrand48@plt>
call   1040 <log@plt>
xorpd  0xe07(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15)
xor    %eax,%eax
call   1030 <ndrand48@plt>
movsd  0x8(%rsp),%xmm1
test   %r14d,%r14d
jle    1256 <one_gill_step+0x116>
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
ucomisd %xmm1,%xmm0
ja     1247 <one_gill_step+0x107>
addsd  0x18(%rsp,%rax,8),%xmm0
add    $0x1,%rax
cmp    %rax,%r12
jne    1230 <one_gill_step+0xf0>
jmp    1256 <one_gill_step+0x116>
movabs $0x3ff0000000000000,%rcx
mov    %rcx,0x8(%r15,%rax,8)
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Tau stepping method not implemented yet.\00"
define void @one_gill_step(i32 %0, i32 %1, i32* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca [1000 x double]
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store double* %3, double** %8
store double 0.000000e+00, double* %9
%13 = load i32, i32* %5
switch i32 %13, label %88 [
i32 0, label %14
i32 1, label %86
]
14: ; preds = %4
store i32 0, i32* %12
br label %15
15: ; preds = %40, %14
%16 = load i32, i32* %12
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %43
19: ; preds = %15
%20 = load double*, double** %8
%21 = load i32, i32* %12
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %20, i64 %23
store double 0.000000e+00, double* %24
%25 = load i32*, i32** %7
%26 = load i32, i32* %12
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = call double @get_ivar(i32 %29)
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1000 x double], [1000 x double]* %11, i64 0, i64 %32
store double %30, double* %33
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1000 x double], [1000 x double]* %11, i64 0, i64 %35
%37 = load double, double* %36
%38 = load double, double* %9
%39 = fadd double %38, %37
store double %39, double* %9
br label %40
40: ; preds = %19
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 1
store i32 %42, i32* %12
br label %15
43: ; preds = %15
%44 = load double, double* %9
%45 = fcmp ole double %44, 0.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %43
br label %88
47: ; preds = %43
%48 = call double (...) @ndrand48()
%49 = call double @log(double %48)
%50 = fneg double %49
%51 = load double, double* %9
%52 = fdiv double %50, %51
%53 = load double*, double** %8
%54 = getelementptr inbounds double, double* %53, i64 0
store double %52, double* %54
%55 = load double, double* %9
%56 = call double (...) @ndrand48()
%57 = fmul double %55, %56
store double %57, double* %10
%58 = getelementptr inbounds [1000 x double], [1000 x double]* %11, i64 0, i64 0
%59 = load double, double* %58
store double %59, double* %9
store i32 0, i32* %12
br label %60
60: ; preds = %82, %47
%61 = load i32, i32* %12
%62 = load i32, i32* %6
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %85
64: ; preds = %60
%65 = load double, double* %10
%66 = load double, double* %9
%67 = fcmp olt double %65, %66
br i1 %67, label %68, label %74
68: ; preds = %64
%69 = load double*, double** %8
%70 = load i32, i32* %12
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %69, i64 %72
store double 1.000000e+00, double* %73
br label %85
74: ; preds = %64
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1000 x double], [1000 x double]* %11, i64 0, i64 %77
%79 = load double, double* %78
%80 = load double, double* %9
%81 = fadd double %80, %79
store double %81, double* %9
br label %82
82: ; preds = %74
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 1
store i32 %84, i32* %12
br label %60
85: ; preds = %68, %60
br label %88
86: ; preds = %4
%87 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %88
88: ; preds = %46, %4, %86, %85
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Tau stepping method not implemented yet.\00"
define void @one_gill_step(i32 %0, i32 %1, i32* nocapture %2, double* nocapture writeonly %3) {
%5 = alloca [1000 x double]
%6 = bitcast [1000 x double]* %5 to i8*
switch i32 %0, label %50 [
i32 0, label %7
i32 1, label %48
]
7: ; preds = %4
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %50
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %14, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %20, %11 ]
%14 = add nuw nsw i64 %12, 1
%15 = getelementptr inbounds double, double* %3, i64 %14
store double 0.000000e+00, double* %15
%16 = getelementptr inbounds i32, i32* %2, i64 %12
%17 = load i32, i32* %16
%18 = tail call double @get_ivar(i32 %17)
%19 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %12
store double %18, double* %19
%20 = fadd double %13, %18
%21 = icmp eq i64 %14, %10
br i1 %21, label %22, label %11
22: ; preds = %11
%23 = fcmp ugt double %20, 0.000000e+00
br i1 %23, label %24, label %50
24: ; preds = %22
%25 = tail call double (...) @ndrand48()
%26 = tail call double @log(double %25)
%27 = fneg double %26
%28 = fdiv double %27, %20
store double %28, double* %3
%29 = tail call double (...) @ndrand48()
%30 = fmul double %20, %29
br i1 %8, label %31, label %50
31: ; preds = %24
%32 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 0
%33 = load double, double* %32
%34 = zext i32 %1 to i64
br label %35
35: ; preds = %31, %43
%36 = phi i64 [ 0, %31 ], [ %39, %43 ]
%37 = phi double [ %33, %31 ], [ %46, %43 ]
%38 = fcmp olt double %30, %37
%39 = add nuw i64 %36, 1
br i1 %38, label %40, label %43
40: ; preds = %35
%41 = and i64 %39, 4294967295
%42 = getelementptr inbounds double, double* %3, i64 %41
store double 1.000000e+00, double* %42
br label %50
43: ; preds = %35
%44 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %39
%45 = load double, double* %44
%46 = fadd double %37, %45
%47 = icmp eq i64 %39, %34
br i1 %47, label %50, label %35
48: ; preds = %4
%49 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %43, %7, %24, %48, %4, %40, %22
ret void
}