#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*/ first_iteration(double *, double *, int, double);
int /*<<< orphan*/ initial_condition(double *, int, double);
double *malloc(int);
int /*<<< orphan*/ print_u(double *, int, double);
int /*<<< orphan*/ update_u(double *, double *, double *, int, double);
int main() {
  double x_f = 1.0;
  int n_x = 1000;
  double delta_x = 0.001;
  double delta_t = 5E-4;
  int n_t = 350.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));
  double *u_future = malloc(n_x * sizeof(double));
  initial_condition(u_past, n_x, delta_x);
  u_past[0] = 0.0;
  u_past[n_x - 1] = 0.0;
  u_present[0] = 0.0;
  u_present[n_x - 1] = 0.0;
  first_iteration(u_present, u_past, n_x, r);
  copy(u_present, u_past, n_x);
  int i;
  for (i = 0; i < n_t; i++) {
    update_u(u_future, u_present, u_past, n_x, r);
    copy(u_present, u_past, n_x);
    copy(u_future, u_present, n_x);
  }
  print_u(u_present, n_x, delta_x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x15e,-0x2c(%rbp)
movsd  0xe54(%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   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
call   1080 <initial_condition@plt>
mov    -0x48(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
call   1060 <first_iteration@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <copy@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12ce <main+0x16e>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x14(%rbp),%ecx
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    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <copy@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    127b <main+0x11b>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
call   1030 <print_u@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1f40,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x1f40,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x1f40,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
movsd  0xe6a(%rip),%xmm0
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1080 <initial_condition@plt>
movq   $0x0,(%r14)
movq   $0x0,0x1f38(%r14)
movq   $0x0,(%rbx)
movq   $0x0,0x1f38(%rbx)
movsd  0xe39(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1060 <first_iteration@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1040 <copy@plt>
mov    $0x15e,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    $0x3e8,%ecx
movsd  0xdf2(%rip),%xmm0
call   1050 <update_u@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1040 <copy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1040 <copy@plt>
add    $0xffffffff,%ebp
jne    1200 <main+0xa0>
movsd  0xdb8(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <print_u@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 double*
%12 = alloca i32
store i32 0, i32* %1
store double 1.000000e+00, double* %2
store i32 1000, i32* %3
store double 1.000000e-03, double* %4
store double 5.000000e-04, double* %5
store i32 350, i32* %6
store double 1.000000e+00, double* %7
%13 = load double, double* %7
%14 = load double, double* %5
%15 = fmul double %13, %14
%16 = load double, double* %4
%17 = fdiv double %15, %16
store double %17, double* %8
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call double* @malloc(i32 %21)
store double* %22, double** %9
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call double* @malloc(i32 %26)
store double* %27, double** %10
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call double* @malloc(i32 %31)
store double* %32, double** %11
%33 = load double*, double** %9
%34 = load i32, i32* %3
%35 = load double, double* %4
%36 = call i32 @initial_condition(double* %33, i32 %34, double %35)
%37 = load double*, double** %9
%38 = getelementptr inbounds double, double* %37, i64 0
store double 0.000000e+00, double* %38
%39 = load double*, double** %9
%40 = load i32, i32* %3
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %39, i64 %42
store double 0.000000e+00, double* %43
%44 = load double*, double** %10
%45 = getelementptr inbounds double, double* %44, i64 0
store double 0.000000e+00, double* %45
%46 = load double*, double** %10
%47 = load i32, i32* %3
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %46, i64 %49
store double 0.000000e+00, double* %50
%51 = load double*, double** %10
%52 = load double*, double** %9
%53 = load i32, i32* %3
%54 = load double, double* %8
%55 = call i32 @first_iteration(double* %51, double* %52, i32 %53, double %54)
%56 = load double*, double** %10
%57 = load double*, double** %9
%58 = load i32, i32* %3
%59 = call i32 @copy(double* %56, double* %57, i32 %58)
store i32 0, i32* %12
br label %60
60: ; preds = %79, %0
%61 = load i32, i32* %12
%62 = load i32, i32* %6
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %82
64: ; preds = %60
%65 = load double*, double** %11
%66 = load double*, double** %10
%67 = load double*, double** %9
%68 = load i32, i32* %3
%69 = load double, double* %8
%70 = call i32 @update_u(double* %65, double* %66, double* %67, i32 %68, double %69)
%71 = load double*, double** %10
%72 = load double*, double** %9
%73 = load i32, i32* %3
%74 = call i32 @copy(double* %71, double* %72, i32 %73)
%75 = load double*, double** %11
%76 = load double*, double** %10
%77 = load i32, i32* %3
%78 = call i32 @copy(double* %75, double* %76, i32 %77)
br label %79
79: ; preds = %64
%80 = load i32, i32* %12
%81 = add nsw i32 %80, 1
store i32 %81, i32* %12
br label %60
82: ; preds = %60
%83 = load double*, double** %10
%84 = load i32, i32* %3
%85 = load double, double* %4
%86 = call i32 @print_u(double* %83, i32 %84, double %85)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call double* @malloc(i32 8000)
%2 = tail call double* @malloc(i32 8000)
%3 = tail call double* @malloc(i32 8000)
%4 = tail call i32 @initial_condition(double* %1, i32 1000, double 1.000000e-03)
store double 0.000000e+00, double* %1
%5 = getelementptr inbounds double, double* %1, i64 999
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %2
%6 = getelementptr inbounds double, double* %2, i64 999
store double 0.000000e+00, double* %6
%7 = tail call i32 @first_iteration(double* %2, double* %1, i32 1000, double 5.000000e-01)
%8 = tail call i32 @copy(double* %2, double* %1, i32 1000)
br label %9
9: ; preds = %0, %9
%10 = phi i32 [ 0, %0 ], [ %14, %9 ]
%11 = tail call i32 @update_u(double* %3, double* %2, double* %1, i32 1000, double 5.000000e-01)
%12 = tail call i32 @copy(double* %2, double* %1, i32 1000)
%13 = tail call i32 @copy(double* %3, double* %2, i32 1000)
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, 350
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = tail call i32 @print_u(double* %2, i32 1000, double 1.000000e-03)
ret i32 0
}