#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fitfun(double *, int, double *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int rank, size;
  int i;
  double lval = 0, gval;
  double TP[2];
  for (i = 0; i < argc; i++) {
    printf("simcode: arg %d argv %s\n", i, argv[i]);
    fflush(0);
  }
  FILE *fp = fopen("params.dat", "r");
  fscanf(fp, "%lf", &TP[0]);
  fscanf(fp, "%lf", &TP[1]);
  fclose(fp);
  fitfun(TP, 2, &gval);
  char fname[256];
  FILE *fd;
  strcpy(fname, "fitness");
  fd = fopen(fname, "w");
  if (fd == NULL)
    printf("error with fopen\n");
  fflush(0);
  fprintf(fd, "%.16lf\n", gval);
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e6 <main+0x66>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <main+0x28>
lea    0xe2c(%rip),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rdx
add    $0x8,%rdx
lea    0xe02(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x40(%rbp),%rdi
mov    $0x2,%esi
lea    -0x30(%rbp),%rdx
call   1070 <fitfun@plt>
lea    -0x150(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x150(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    128d <main+0x10d>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    -0x158(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xd9f(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x158(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x128,%rsp
test   %edi,%edi
jle    11e0 <main+0x50>
mov    %rsi,%r15
mov    %edi,%r12d
lea    0xe51(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <fflush@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <main+0x30>
lea    0xe32(%rip),%rdi
lea    0xe36(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe29(%rip),%r14
lea    0x10(%rsp),%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <fscanf@plt>
lea    0x18(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fscanf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    $0x2,%esi
call   1080 <fitfun@plt>
lea    0xde9(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1271 <main+0xe1>
lea    0xdd0(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <fflush@plt>
movsd  0x8(%rsp),%xmm0
lea    0xdaf(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"simcode: arg %d argv %s\0A\00"
@.str.1 = [11 x i8] c"params.dat\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [8 x i8] c"fitness\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [18 x i8] c"error with fopen\0A\00"
@.str.7 = [8 x i8] c"%.16lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca [2 x double]
%12 = alloca i32*
%13 = alloca [256 x i8]
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %9
store i32 0, i32* %8
br label %15
15: ; preds = %28, %2
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %8
%21 = load i8**, i8*** %5
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %25)
%27 = call i32 @fflush(i32 0)
br label %28
28: ; preds = %19
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %15
31: ; preds = %15
%32 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %12
%33 = load i32*, i32** %12
%34 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
%35 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %34)
%36 = load i32*, i32** %12
%37 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 1
%38 = call i32 @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %37)
%39 = load i32*, i32** %12
%40 = call i32 @fclose(i32* %39)
%41 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
%42 = call i32 @fitfun(double* %41, i32 2, double* %10)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %46, i32** %14
%47 = load i32*, i32** %14
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %51
49: ; preds = %31
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %49, %31
%52 = call i32 @fflush(i32 0)
%53 = load i32*, i32** %14
%54 = load double, double* %10
%55 = call i32 @fprintf(i32* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), double %54)
%56 = load i32*, i32** %14
%57 = call i32 @fclose(i32* %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"simcode: arg %d argv %s\0A\00"
@.str.1 = [11 x i8] c"params.dat\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [8 x i8] c"fitness\00"
@.str.5 = [2 x i8] c"w\00"
@.str.7 = [8 x i8] c"%.16lf\0A\00"
@str = [17 x i8] c"error with fopen\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca [2 x double]
%5 = alloca [256 x i8]
%6 = bitcast double* %3 to i8*
%7 = bitcast [2 x double]* %4 to i8*
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %18, %11 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = trunc i64 %12 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %14)
%17 = tail call i32 @fflush(i32 0)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %11
20: ; preds = %11, %2
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %22)
%24 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%25 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %24)
%26 = call i32 @fclose(i32* %21)
%27 = call i32 @fitfun(double* %22, i32 2, double* %3)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %20
%35 = call i32 @fflush(i32 0)
%36 = load double, double* %3
%37 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), double %36)
%38 = call i32 @fclose(i32* %30)
ret i32 0
}