#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int solcon_close_solution_input_file(int /*<<< orphan*/);
int solcon_close_solution_output_file();
int solcon_create_solution_output_file();
int solcon_open_solution_input_file();
int solcon_read_next_solution(int, int *, double *);
int solcon_read_solution_dimensions(int *, int *);
int solcon_scan_solution_banner();
int solcon_write_next_solution(int *, int, int, double *);
int solcon_write_solution_dimensions(int, int);
int /*<<< orphan*/ write_solution(int, double, double, int, double *, double,
                                  double, double);
void test_incremental_read_and_write(void) {
  int fail, *a, *b, len, dim, k, m, i;
  double *c, err, rco, res;
  char ans;
  fail = solcon_open_solution_input_file();
  printf("\n");
  fail = solcon_create_solution_output_file();
  printf("\nShould the file be scanned for a banner ? (y/n) ");
  scanf("%c", &ans);
  if (ans == 'y')
    fail = solcon_scan_solution_banner();
  fail = solcon_read_solution_dimensions(&len, &dim);
  printf("#solutions : %d  dimension : %d\n", len, dim);
  fail = solcon_write_solution_dimensions(len, dim);
  c = (double *)calloc(2 * dim + 5, sizeof(double));
  k = 0;
  for (i = 0; i < len; i++) {
    fail = solcon_read_next_solution(dim, &m, c);
    printf("Solution %d :\n", i + 1);
    err = c[2 * dim + 2];
    rco = c[2 * dim + 3];
    res = c[2 * dim + 4];
    write_solution(dim, c[0], c[1], m, c + 2, err, rco, res);
    fail = solcon_write_next_solution(&k, dim, m, c);
    printf("number of solutions written to file : %d\n", k);
  }
  fail = solcon_close_solution_input_file(0);
  fail = solcon_close_solution_output_file();
}


x86 assembly (clang, -O0):
<test_incremental_read_and_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x0,%al
call   10b0 <solcon_open_solution_input_file@plt>
mov    %eax,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10f0 <solcon_create_solution_output_file@plt>
mov    %eax,-0x4(%rbp)
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
lea    -0x51(%rbp),%rsi
call   10d0 <scanf@plt>
movsbl -0x51(%rbp),%eax
cmp    $0x79,%eax
jne    122f <test_incremental_read_and_write+0x5f>
mov    $0x0,%al
call   1070 <solcon_scan_solution_banner@plt>
mov    %eax,-0x4(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <solcon_read_solution_dimensions@plt>
mov    %eax,-0x4(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1080 <solcon_write_solution_dimensions@plt>
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%edi
shl    $0x1,%edi
add    $0x5,%edi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    136f <test_incremental_read_and_write+0x19f>
mov    -0x20(%rbp),%edi
mov    -0x38(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1040 <solcon_read_next_solution@plt>
mov    %eax,-0x4(%rbp)
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x28(%rbp),%esi
mov    -0x38(%rbp),%rdx
add    $0x10,%rdx
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm4
call   10e0 <write_solution@plt>
mov    -0x20(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x38(%rbp),%rcx
lea    -0x24(%rbp),%rdi
call   1090 <solcon_write_next_solution@plt>
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1286 <test_incremental_read_and_write+0xb6>
xor    %edi,%edi
call   1030 <solcon_close_solution_input_file@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   10c0 <solcon_close_solution_output_file@plt>
mov    %eax,-0x4(%rbp)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_incremental_read_and_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   10c0 <solcon_open_solution_input_file@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1100 <solcon_create_solution_output_file@plt>
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe17(%rip),%rdi
lea    0x7(%rsp),%rsi
call   10e0 <scanf@plt>
cmpb   $0x79,0x7(%rsp)
jne    1233 <test_incremental_read_and_write+0x53>
xor    %eax,%eax
call   1080 <solcon_scan_solution_banner@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <solcon_read_solution_dimensions@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1090 <solcon_write_solution_dimensions@plt>
mov    0x8(%rsp),%eax
lea    (%rax,%rax,1),%edi
add    $0x5,%edi
mov    $0x8,%esi
call   10b0 <calloc@plt>
movl   $0x0,0x14(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    1337 <test_incremental_read_and_write+0x157>
mov    %rax,%rbx
mov    %rax,%r14
add    $0x10,%r14
lea    0xdb9(%rip),%r12
lea    0x14(%rsp),%r13
lea    0xdbc(%rip),%rbp
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <solcon_read_next_solution@plt>
add    $0x1,%r15d
mov    %r12,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movslq 0x8(%rsp),%rdi
lea    (%rdi,%rdi,1),%rax
mov    %rdi,%rcx
shl    $0x4,%rcx
movsd  0x10(%rcx,%rbx,1),%xmm2
cltq
movsd  0x18(%rbx,%rax,8),%xmm3
movsd  0x20(%rbx,%rax,8),%xmm4
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
mov    0x10(%rsp),%esi
mov    %r14,%rdx
call   10f0 <write_solution@plt>
mov    0x8(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %r13,%rdi
mov    %rbx,%rcx
call   10a0 <solcon_write_next_solution@plt>
mov    0x14(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    0xc(%rsp),%r15d
jl     12b0 <test_incremental_read_and_write+0xd0>
xor    %edi,%edi
call   1040 <solcon_close_solution_input_file@plt>
xor    %eax,%eax
call   10d0 <solcon_close_solution_output_file@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [50 x i8] c"\0AShould the file be scanned for a banner ? (y/n) \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [33 x i8] c"#solutions : %d dimension : %d\0A\00"
@.str.4 = [15 x i8] c"Solution %d :\0A\00"
@.str.5 = [42 x i8] c"number of solutions written to file : %d\0A\00"
define void @test_incremental_read_and_write() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i8
%14 = call i32 (...) @solcon_open_solution_input_file()
store i32 %14, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @solcon_create_solution_output_file()
store i32 %16, i32* %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%19 = load i8, i8* %13
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 121
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 (...) @solcon_scan_solution_banner()
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %0
%25 = call i32 @solcon_read_solution_dimensions(i32* %4, i32* %5)
store i32 %25, i32* %1
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 @solcon_write_solution_dimensions(i32 %29, i32 %30)
store i32 %31, i32* %1
%32 = load i32, i32* %5
%33 = mul nsw i32 2, %32
%34 = add nsw i32 %33, 5
%35 = call i64 @calloc(i32 %34, i32 8)
%36 = inttoptr i64 %35 to double*
store double* %36, double** %9
store i32 0, i32* %6
store i32 0, i32* %8
br label %37
37: ; preds = %89, %24
%38 = load i32, i32* %8
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %92
41: ; preds = %37
%42 = load i32, i32* %5
%43 = load double*, double** %9
%44 = call i32 @solcon_read_next_solution(i32 %42, i32* %7, double* %43)
store i32 %44, i32* %1
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load double*, double** %9
%49 = load i32, i32* %5
%50 = mul nsw i32 2, %49
%51 = add nsw i32 %50, 2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %48, i64 %52
%54 = load double, double* %53
store double %54, double* %10
%55 = load double*, double** %9
%56 = load i32, i32* %5
%57 = mul nsw i32 2, %56
%58 = add nsw i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %55, i64 %59
%61 = load double, double* %60
store double %61, double* %11
%62 = load double*, double** %9
%63 = load i32, i32* %5
%64 = mul nsw i32 2, %63
%65 = add nsw i32 %64, 4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %62, i64 %66
%68 = load double, double* %67
store double %68, double* %12
%69 = load i32, i32* %5
%70 = load double*, double** %9
%71 = getelementptr inbounds double, double* %70, i64 0
%72 = load double, double* %71
%73 = load double*, double** %9
%74 = getelementptr inbounds double, double* %73, i64 1
%75 = load double, double* %74
%76 = load i32, i32* %7
%77 = load double*, double** %9
%78 = getelementptr inbounds double, double* %77, i64 2
%79 = load double, double* %10
%80 = load double, double* %11
%81 = load double, double* %12
%82 = call i32 @write_solution(i32 %69, double %72, double %75, i32 %76, double* %78, double %79, double %80, double %81)
%83 = load i32, i32* %5
%84 = load i32, i32* %7
%85 = load double*, double** %9
%86 = call i32 @solcon_write_next_solution(i32* %6, i32 %83, i32 %84, double* %85)
store i32 %86, i32* %1
%87 = load i32, i32* %6
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %41
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %37
92: ; preds = %37
%93 = call i32 @solcon_close_solution_input_file(i32 0)
store i32 %93, i32* %1
%94 = call i32 (...) @solcon_close_solution_output_file()
store i32 %94, i32* %1
ret void
}

LLVM IR (-O2):
@.str.1 = [50 x i8] c"\0AShould the file be scanned for a banner ? (y/n) \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [33 x i8] c"#solutions : %d dimension : %d\0A\00"
@.str.4 = [15 x i8] c"Solution %d :\0A\00"
@.str.5 = [42 x i8] c"number of solutions written to file : %d\0A\00"
define void @test_incremental_read_and_write() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = tail call i32 (...) @solcon_open_solution_input_file()
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 (...) @solcon_create_solution_output_file()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%15 = load i8, i8* %5
%16 = icmp eq i8 %15, 121
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (...) @solcon_scan_solution_banner()
br label %19
19: ; preds = %17, %0
%20 = call i32 @solcon_read_solution_dimensions(i32* %1, i32* %2)
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %1
%25 = load i32, i32* %2
%26 = call i32 @solcon_write_solution_dimensions(i32 %24, i32 %25)
%27 = load i32, i32* %2
%28 = shl nsw i32 %27, 1
%29 = add nsw i32 %28, 5
%30 = call i64 @calloc(i32 %29, i32 8)
%31 = inttoptr i64 %30 to double*
store i32 0, i32* %3
%32 = load i32, i32* %1
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %68
34: ; preds = %19
%35 = getelementptr inbounds double, double* %31, i64 1
%36 = getelementptr inbounds double, double* %31, i64 2
br label %37
37: ; preds = %34, %37
%38 = phi i32 [ 0, %34 ], [ %41, %37 ]
%39 = load i32, i32* %2
%40 = call i32 @solcon_read_next_solution(i32 %39, i32* %4, double* %31)
%41 = add nuw nsw i32 %38, 1
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %2
%44 = shl nsw i32 %43, 1
%45 = add nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %31, i64 %46
%48 = load double, double* %47
%49 = add nsw i32 %44, 3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %31, i64 %50
%52 = load double, double* %51
%53 = add nsw i32 %44, 4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %31, i64 %54
%56 = load double, double* %55
%57 = load double, double* %31
%58 = load double, double* %35
%59 = load i32, i32* %4
%60 = call i32 @write_solution(i32 %43, double %57, double %58, i32 %59, double* %36, double %48, double %52, double %56)
%61 = load i32, i32* %2
%62 = load i32, i32* %4
%63 = call i32 @solcon_write_next_solution(i32* %3, i32 %61, i32 %62, double* %31)
%64 = load i32, i32* %3
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %1
%67 = icmp slt i32 %41, %66
br i1 %67, label %37, label %68
68: ; preds = %37, %19
%69 = call i32 @solcon_close_solution_input_file(i32 0)
%70 = call i32 (...) @solcon_close_solution_output_file()
ret void
}