#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*/ copy(double *, double *, int);
int /*<<< orphan*/ initial_condition(double *, int, double);
double *malloc(int);
int /*<<< orphan*/ print_u(double *, int, double);
int /*<<< orphan*/ update_u(double *, double *, int, double);
int main() {
  double x_f = 2.0;
  int n_x = 1000;
  double delta_x = x_f / n_x;
  double delta_t = 1E-3;
  int n_t = 800.0;
  double c = 1.0;
  double r = c * delta_t / delta_x;
  double *u_past = malloc(n_x * sizeof(double));
  double *u_present = malloc(n_x * sizeof(double));
  initial_condition(u_past, n_x, delta_x);
  int i;
  for (i = 0; i < n_t; i++) {
    update_u(u_present, u_past, n_x, r);
    copy(u_present, u_past, n_x);
  }
  print_u(u_present, n_x, delta_x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe7a(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x320,-0x2c(%rbp)
movsd  0xe5e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
call   1070 <initial_condition@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1238 <main+0xe8>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
call   1050 <update_u@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <copy@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f9 <main+0xa9>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
call   1030 <print_u@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1f40,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x1f40,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movsd  0xe8a(%rip),%xmm0
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1070 <initial_condition@plt>
mov    $0x320,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3e8,%edx
movsd  0xe65(%rip),%xmm0
call   1050 <update_u@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1040 <copy@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x40>
movsd  0xe3b(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <print_u@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
store i32 0, i32* %1
store double 2.000000e+00, double* %2
store i32 1000, i32* %3
%12 = load double, double* %2
%13 = load i32, i32* %3
%14 = sitofp i32 %13 to double
%15 = fdiv double %12, %14
store double %15, double* %4
store double 1.000000e-03, double* %5
store i32 800, i32* %6
store double 1.000000e+00, double* %7
%16 = load double, double* %7
%17 = load double, double* %5
%18 = fmul double %16, %17
%19 = load double, double* %4
%20 = fdiv double %18, %19
store double %20, double* %8
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call double* @malloc(i32 %24)
store double* %25, double** %9
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 8
%29 = trunc i64 %28 to i32
%30 = call double* @malloc(i32 %29)
store double* %30, double** %10
%31 = load double*, double** %9
%32 = load i32, i32* %3
%33 = load double, double* %4
%34 = call i32 @initial_condition(double* %31, i32 %32, double %33)
store i32 0, i32* %11
br label %35
35: ; preds = %49, %0
%36 = load i32, i32* %11
%37 = load i32, i32* %6
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %52
39: ; preds = %35
%40 = load double*, double** %10
%41 = load double*, double** %9
%42 = load i32, i32* %3
%43 = load double, double* %8
%44 = call i32 @update_u(double* %40, double* %41, i32 %42, double %43)
%45 = load double*, double** %10
%46 = load double*, double** %9
%47 = load i32, i32* %3
%48 = call i32 @copy(double* %45, double* %46, i32 %47)
br label %49
49: ; preds = %39
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %35
52: ; preds = %35
%53 = load double*, double** %10
%54 = load i32, i32* %3
%55 = load double, double* %4
%56 = call i32 @print_u(double* %53, i32 %54, double %55)
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call double* @malloc(i32 8000)
%2 = tail call double* @malloc(i32 8000)
%3 = tail call i32 @initial_condition(double* %1, i32 1000, double 2.000000e-03)
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %8, %4 ]
%6 = tail call i32 @update_u(double* %2, double* %1, i32 1000, double 5.000000e-01)
%7 = tail call i32 @copy(double* %2, double* %1, i32 1000)
%8 = add nuw nsw i32 %5, 1
%9 = icmp eq i32 %8, 800
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = tail call i32 @print_u(double* %2, i32 1000, double 2.000000e-03)
ret i32 0
}