#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
float delta_n_step(float, float, float);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, float, float);
void single_decay(float N0, float lambda, float dt) {
  float t_total = 5.0 / lambda;
  int n_points = (int)t_total / dt;
  int i;
  float t = 0.0;
  float n = N0;
  FILE *out = fopen("data_rand.txt", "w+");
  fprintf(out, "%f %f\n", t, n);
  for (i = 0; i < n_points; i++) {
    t += dt;
    float delta_n = delta_n_step(n, lambda, dt);
    n += delta_n;
    fprintf(out, "%f %f\n", t, n);
  }
}


x86 assembly (clang, -O0):
<single_decay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xea8(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
cvttss2si -0x10(%rbp),%eax
cvtsi2ss %eax,%xmm0
divss  -0xc(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
lea    0xe75(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
lea    0xe61(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122f <single_decay+0xff>
movss  -0xc(%rbp),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
call   1040 <delta_n_step@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
lea    0xdfd(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c4 <single_decay+0x94>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<single_decay>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,(%rsp)
movss  0xebb(%rip),%xmm0
movss  %xmm1,0x8(%rsp)
divss  %xmm1,%xmm0
cvttps2dq %xmm0,%xmm0
cvtdq2ps %xmm0,%xmm0
movss  %xmm2,0xc(%rsp)
divss  %xmm2,%xmm0
cvttss2si %xmm0,%ebp
lea    0xe99(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xe94(%rip),%rsi
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
xorps  %xmm0,%xmm0
mov    %rax,%rdi
movss  (%rsp),%xmm1
call   1030 <fprintf@plt>
test   %ebp,%ebp
jle    11fa <single_decay+0xca>
lea    0xe70(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movss  0xc(%rsp),%xmm2
movss  0x4(%rsp),%xmm0
addss  %xmm2,%xmm0
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm0
movss  0x8(%rsp),%xmm1
call   1040 <delta_n_step@plt>
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
mov    %rbx,%rdi
mov    %r14,%rsi
movss  0x4(%rsp),%xmm0
movss  %xmm1,(%rsp)
call   1030 <fprintf@plt>
add    $0xffffffff,%ebp
jne    11b0 <single_decay+0x80>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"data_rand.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [7 x i8] c"%f %f\0A\00"
define void @single_decay(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca i32*
%13 = alloca float
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%14 = load float, float* %5
%15 = fpext float %14 to double
%16 = fdiv double 5.000000e+00, %15
%17 = fptrunc double %16 to float
store float %17, float* %7
%18 = load float, float* %7
%19 = fptosi float %18 to i32
%20 = sitofp i32 %19 to float
%21 = load float, float* %6
%22 = fdiv float %20, %21
%23 = fptosi float %22 to i32
store i32 %23, i32* %8
store float 0.000000e+00, float* %10
%24 = load float, float* %4
store float %24, float* %11
%25 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %12
%26 = load i32*, i32** %12
%27 = load float, float* %10
%28 = load float, float* %11
%29 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float %27, float %28)
store i32 0, i32* %9
br label %30
30: ; preds = %49, %3
%31 = load i32, i32* %9
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load float, float* %6
%36 = load float, float* %10
%37 = fadd float %36, %35
store float %37, float* %10
%38 = load float, float* %11
%39 = load float, float* %5
%40 = load float, float* %6
%41 = call float @delta_n_step(float %38, float %39, float %40)
store float %41, float* %13
%42 = load float, float* %13
%43 = load float, float* %11
%44 = fadd float %43, %42
store float %44, float* %11
%45 = load i32*, i32** %12
%46 = load float, float* %10
%47 = load float, float* %11
%48 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float %46, float %47)
br label %49
49: ; preds = %34
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %30
52: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"data_rand.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [7 x i8] c"%f %f\0A\00"
define void @single_decay(float %0, float %1, float %2) {
%4 = fdiv float 5.000000e+00, %1
%5 = fptosi float %4 to i32
%6 = sitofp i32 %5 to float
%7 = fdiv float %6, %2
%8 = fptosi float %7 to i32
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float 0.000000e+00, float %0)
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %22
12: ; preds = %3, %12
%13 = phi i32 [ %20, %12 ], [ 0, %3 ]
%14 = phi float [ %16, %12 ], [ 0.000000e+00, %3 ]
%15 = phi float [ %18, %12 ], [ %0, %3 ]
%16 = fadd float %14, %2
%17 = tail call float @delta_n_step(float %15, float %1, float %2)
%18 = fadd float %15, %17
%19 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float %16, float %18)
%20 = add nuw nsw i32 %13, 1
%21 = icmp eq i32 %20, %8
br i1 %21, label %22, label %12
22: ; preds = %12, %3
ret void
}