#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 */
double F(double);
double V(double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, ...);
double rho(double);
int main(void) {
  int Nr = 10001;
  double rmax = 3. * 3.157;
  double dr = rmax / (double)Nr;
  int Nrho = 10001;
  double rhomax = rho(0.);
  double drho = rhomax / (double)Nrho;
  int atomic_number = 1;
  double mass = 183.84;
  double lattice_constant = 3.157;
  char lattice_type[] = "BCC";
  int i;
  char LAMMPSFilename[] = "W_Zhou.eam";
  FILE *LAMMPSFile = fopen(LAMMPSFilename, "w");
  if (!LAMMPSFile)
    exit(-1);
  fprintf(LAMMPSFile,
          "#-> LAMMPS Potential File in DYNAMO 86 setfl Format <-#\n"
          "# Zhou W Acta mater(2001)49:4005\n"
          "# Implemented by G. Ziegenhain (2007)\n"
          "%d W\n"
          "%d %20.20f %d %20.20f %20.20f\n"
          "%d %20.20f %20.20f %s\n",
          atomic_number, Nrho, drho, Nr, dr, rmax, atomic_number, mass,
          lattice_constant, lattice_type);
  for (i = 0; i < Nrho; i++)
    fprintf(LAMMPSFile, "%20.20f\n", F((double)i * drho));
  for (i = 0; i < Nr; i++)
    fprintf(LAMMPSFile, "%20.20f\n", rho((double)i * dr));
  for (i = 0; i < Nr; i++)
    fprintf(LAMMPSFile, "%20.20f\n", V((double)i * dr) * (double)i * dr);
  fclose(LAMMPSFile);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2711,-0x8(%rbp)
movsd  0xe7f(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x2711,-0x1c(%rbp)
xorps  %xmm0,%xmm0
call   1070 <rho@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movsd  0xe29(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe14(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0xe21(%rip),%eax
mov    %eax,-0x4c(%rbp)
mov    0xe1b(%rip),%rax
mov    %rax,-0x5b(%rbp)
mov    0xe18(%rip),%ax
mov    %ax,-0x53(%rbp)
mov    0xe10(%rip),%al
mov    %al,-0x51(%rbp)
lea    -0x5b(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1242 <main+0xd2>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x68(%rbp),%rdi
cvtsi2sdl -0x34(%rbp),%xmm0
mov    -0x1c(%rbp),%edx
movsd  -0x30(%rbp),%xmm1
mov    -0x8(%rbp),%ecx
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm3
mov    -0x34(%rbp),%r8d
movsd  -0x40(%rbp),%xmm4
movsd  -0x48(%rbp),%xmm5
lea    -0x4c(%rbp),%r9
lea    0xdb0(%rip),%rsi
mov    $0x6,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ca <main+0x15a>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
cvtsi2sdl -0x50(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1030 <F@plt>
mov    -0x70(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1287 <main+0x117>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1314 <main+0x1a4>
mov    -0x68(%rbp),%rax
mov    %rax,-0x78(%rbp)
cvtsi2sdl -0x50(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1070 <rho@plt>
mov    -0x78(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    12d1 <main+0x161>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    136c <main+0x1fc>
mov    -0x68(%rbp),%rax
mov    %rax,-0x80(%rbp)
cvtsi2sdl -0x50(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1040 <V@plt>
mov    -0x80(%rbp),%rdi
cvtsi2sdl -0x50(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
lea    0xd8b(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    131b <main+0x1ab>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
call   1070 <rho@plt>
movsd  %xmm0,0x10(%rsp)
movl   $0x434342,0x1c(%rsp)
movabs $0x652e756f685a5f57,%rax
75 2e 65
mov    %rax,0x20(%rsp)
movl   $0x6d6165,0x27(%rsp)
lea    0xe8f(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     133e <main+0x1ce>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm1
divsd  0xe30(%rip),%xmm1
lea    0xe66(%rip),%rsi
movsd  0xe29(%rip),%xmm0
mov    $0x2711,%ebp
movsd  0xe24(%rip),%xmm2
movsd  0xe24(%rip),%xmm3
movsd  0xe24(%rip),%xmm4
movsd  0xe24(%rip),%xmm5
lea    0x1c(%rsp),%r9
mov    %rax,%rdi
mov    $0x2711,%edx
movsd  %xmm1,0x10(%rsp)
mov    $0x2711,%ecx
mov    $0x1,%r8d
mov    $0x6,%al
call   1060 <fprintf@plt>
lea    0xec6(%rip),%r14
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <F@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm1
addsd  0xd98(%rip),%xmm1
add    $0xffffffff,%ebp
jne    1240 <main+0xd0>
xorpd  %xmm2,%xmm2
mov    $0x2711,%ebp
lea    0xe71(%rip),%r14
movsd  0xd83(%rip),%xmm1
nopl   (%rax)
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm1,%xmm0
call   1070 <rho@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm2
movsd  0xd52(%rip),%xmm1
addsd  0xd42(%rip),%xmm2
add    $0xffffffff,%ebp
jne    1290 <main+0x120>
xorpd  %xmm0,%xmm0
mov    $0x2711,%ebp
lea    0xe1b(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <V@plt>
mulsd  0x8(%rsp),%xmm0
mulsd  0xd0d(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xcf2(%rip),%xmm1
addsd  0xce2(%rip),%xmm0
add    $0xffffffff,%ebp
jne    12e0 <main+0x170>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.lattice_type = [4 x i8] c"BCC\00"
@__const.main.LAMMPSFilename = [11 x i8] c"W_Zhou.eam\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [185 x i8] c"#-> LAMMPS Potential File in DYNAMO 86 setfl Format <-#\0A# Zhou W Acta mater(2001)49:4005\0A# Implemented by G. Ziegenhain (2007)\0A%d W\0A%d %20.20f %d %20.20f %20.20f\0A%d %20.20f %20.20f %s\0A\00"
@.str.2 = [9 x i8] c"%20.20f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca [4 x i8]
%12 = alloca i32
%13 = alloca [11 x i8]
%14 = alloca i32*
store i32 0, i32* %1
store i32 10001, i32* %2
store double 9.471000e+00, double* %3
%15 = load double, double* %3
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to double
%18 = fdiv double %15, %17
store double %18, double* %4
store i32 10001, i32* %5
%19 = call double @rho(double 0.000000e+00)
store double %19, double* %6
%20 = load double, double* %6
%21 = load i32, i32* %5
%22 = sitofp i32 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %7
store i32 1, i32* %8
store double 1.838400e+02, double* %9
store double 3.157000e+00, double* %10
%24 = bitcast [4 x i8]* %11 to i8*
%25 = bitcast [11 x i8]* %13 to i8*
%26 = getelementptr inbounds [11 x i8], [11 x i8]* %13, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %14
%28 = load i32*, i32** %14
%29 = icmp ne i32* %28, null
br i1 %29, label %32, label %30
30: ; preds = %0
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %0
%33 = load i32*, i32** %14
%34 = load i32, i32* %8
%35 = sitofp i32 %34 to double
%36 = load i32, i32* %5
%37 = load double, double* %7
%38 = load i32, i32* %2
%39 = load double, double* %4
%40 = load double, double* %3
%41 = load i32, i32* %8
%42 = load double, double* %9
%43 = load double, double* %10
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%45 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([185 x i8], [185 x i8]* @.str.1, i64 0, i64 0), double %35, i32 %36, double %37, i32 %38, double %39, double %40, i32 %41, double %42, double %43, i8* %44)
store i32 0, i32* %12
br label %46
46: ; preds = %58, %32
%47 = load i32, i32* %12
%48 = load i32, i32* %5
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %61
50: ; preds = %46
%51 = load i32*, i32** %14
%52 = load i32, i32* %12
%53 = sitofp i32 %52 to double
%54 = load double, double* %7
%55 = fmul double %53, %54
%56 = call double @F(double %55)
%57 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %56)
br label %58
58: ; preds = %50
%59 = load i32, i32* %12
%60 = add nsw i32 %59, 1
store i32 %60, i32* %12
br label %46
61: ; preds = %46
store i32 0, i32* %12
br label %62
62: ; preds = %74, %61
%63 = load i32, i32* %12
%64 = load i32, i32* %2
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %77
66: ; preds = %62
%67 = load i32*, i32** %14
%68 = load i32, i32* %12
%69 = sitofp i32 %68 to double
%70 = load double, double* %4
%71 = fmul double %69, %70
%72 = call double @rho(double %71)
%73 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %72)
br label %74
74: ; preds = %66
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %62
77: ; preds = %62
store i32 0, i32* %12
br label %78
78: ; preds = %95, %77
%79 = load i32, i32* %12
%80 = load i32, i32* %2
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %98
82: ; preds = %78
%83 = load i32*, i32** %14
%84 = load i32, i32* %12
%85 = sitofp i32 %84 to double
%86 = load double, double* %4
%87 = fmul double %85, %86
%88 = call double @V(double %87)
%89 = load i32, i32* %12
%90 = sitofp i32 %89 to double
%91 = fmul double %88, %90
%92 = load double, double* %4
%93 = fmul double %91, %92
%94 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %93)
br label %95
95: ; preds = %82
%96 = load i32, i32* %12
%97 = add nsw i32 %96, 1
store i32 %97, i32* %12
br label %78
98: ; preds = %78
%99 = load i32*, i32** %14
%100 = call i32 @fclose(i32* %99)
ret i32 0
}

LLVM IR (-O2):
@__const.main.LAMMPSFilename = [11 x i8] c"W_Zhou.eam\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [185 x i8] c"#-> LAMMPS Potential File in DYNAMO 86 setfl Format <-#\0A# Zhou W Acta mater(2001)49:4005\0A# Implemented by G. Ziegenhain (2007)\0A%d W\0A%d %20.20f %d %20.20f %20.20f\0A%d %20.20f %20.20f %s\0A\00"
@.str.2 = [9 x i8] c"%20.20f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = tail call double @rho(double 0.000000e+00)
%4 = fdiv double %3, 1.000100e+04
%5 = bitcast i32* %1 to i8*
store i32 4408130, i32* %1
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([185 x i8], [185 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+00, i32 10001, double %4, i32 10001, double 0x3F4F080E652A99BA, double 9.471000e+00, i32 1, double 1.838400e+02, double 3.157000e+00, i32* %1)
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ 0, %11 ], [ %19, %13 ]
%15 = sitofp i32 %14 to double
%16 = fmul double %4, %15
%17 = call double @F(double %16)
%18 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = add nuw nsw i32 %14, 1
%20 = icmp eq i32 %19, 10001
br i1 %20, label %21, label %13
21: ; preds = %13, %21
%22 = phi i32 [ %27, %21 ], [ 0, %13 ]
%23 = sitofp i32 %22 to double
%24 = fmul double %23, 0x3F4F080E652A99BA
%25 = call double @rho(double %24)
%26 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %25)
%27 = add nuw nsw i32 %22, 1
%28 = icmp eq i32 %27, 10001
br i1 %28, label %29, label %21
29: ; preds = %21, %29
%30 = phi i32 [ %37, %29 ], [ 0, %21 ]
%31 = sitofp i32 %30 to double
%32 = fmul double %31, 0x3F4F080E652A99BA
%33 = call double @V(double %32)
%34 = fmul double %33, %31
%35 = fmul double %34, 0x3F4F080E652A99BA
%36 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %35)
%37 = add nuw nsw i32 %30, 1
%38 = icmp eq i32 %37, 10001
br i1 %38, label %39, label %29
39: ; preds = %29
%40 = call i32 @fclose(i32* %7)
ret i32 0
}