#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 _ada_use_solcon(int, int *, int *, double *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
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[2], i;
  double *c, err, rco, res;
  char ans;
  fail = _ada_use_solcon(10, a, b, c);
  printf("\n");
  fail = _ada_use_solcon(11, a, b, c);
  printf("\nShould the file be scanned for a banner ? (y/n) ");
  scanf("%c", &ans);
  if (ans == 'y')
    fail = _ada_use_solcon(12, a, b, c);
  fail = _ada_use_solcon(13, &len, &dim, c);
  printf("#solutions : %d  dimension : %d\n", len, dim);
  fail = _ada_use_solcon(14, &len, &dim, c);
  c = (double *)calloc(2 * dim + 5, sizeof(double));
  k = 0;
  for (i = 0; i < len; i++) {
    fail = _ada_use_solcon(15, &dim, &m[0], 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[0], c + 2, err, rco, res);
    m[1] = m[0];
    m[0] = dim;
    fail = _ada_use_solcon(16, &k, m, c);
    printf("number of solutions written to file : %d\n", k);
  }
  fail = _ada_use_solcon(17, a, b, c);
  fail = _ada_use_solcon(18, a, b, c);
}


x86 assembly (clang, -O0):
<test_incremental_read_and_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0xa,%edi
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0xb,%edi
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
lea    -0x51(%rbp),%rsi
call   1060 <scanf@plt>
movsbl -0x51(%rbp),%eax
cmp    $0x79,%eax
jne    11dc <test_incremental_read_and_write+0x8c>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0xc,%edi
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
mov    -0x38(%rbp),%rcx
mov    $0xd,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rcx
mov    $0xe,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%edi
shl    $0x1,%edi
add    $0x5,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1345 <test_incremental_read_and_write+0x1f5>
lea    -0x2c(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0xf,%edi
lea    -0x20(%rbp),%rsi
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%esi
add    $0x1,%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <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    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdx
add    $0x10,%rdx
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm4
call   1070 <write_solution@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x10,%edi
lea    -0x24(%rbp),%rsi
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1247 <test_incremental_read_and_write+0xf7>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x11,%edi
call   1040 <_ada_use_solcon@plt>
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x12,%edi
call   1040 <_ada_use_solcon@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
mov    $0xa,%edi
call   1050 <_ada_use_solcon@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xb,%edi
call   1050 <_ada_use_solcon@plt>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
lea    0x3(%rsp),%rsi
call   1070 <scanf@plt>
cmpb   $0x79,0x3(%rsp)
jne    11bc <test_incremental_read_and_write+0x5c>
mov    $0xc,%edi
call   1050 <_ada_use_solcon@plt>
lea    0x8(%rsp),%rbx
lea    0x4(%rsp),%rbp
mov    $0xd,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <_ada_use_solcon@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xe,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <_ada_use_solcon@plt>
mov    0x4(%rsp),%eax
lea    (%rax,%rax,1),%edi
add    $0x5,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    12ef <test_incremental_read_and_write+0x18f>
mov    %rbx,%r14
add    $0x10,%r14
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%rbp
lea    0xe27(%rip),%r15
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xf,%edi
lea    0x4(%rsp),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <_ada_use_solcon@plt>
add    $0x1,%r13d
lea    0xde6(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0x4(%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   1080 <write_solution@plt>
mov    0x10(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    $0x10,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <_ada_use_solcon@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x8(%rsp),%r13d
jl     1250 <test_incremental_read_and_write+0xf0>
mov    $0x11,%edi
mov    %rbx,%rcx
call   1050 <_ada_use_solcon@plt>
mov    $0x12,%edi
mov    %rbx,%rcx
call   1050 <_ada_use_solcon@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 [2 x i32]
%8 = alloca i32
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i8
%14 = load i32*, i32** %2
%15 = load i32*, i32** %3
%16 = load double*, double** %9
%17 = call i32 @_ada_use_solcon(i32 10, i32* %14, i32* %15, double* %16)
store i32 %17, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %2
%20 = load i32*, i32** %3
%21 = load double*, double** %9
%22 = call i32 @_ada_use_solcon(i32 11, i32* %19, i32* %20, double* %21)
store i32 %22, i32* %1
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%25 = load i8, i8* %13
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 121
br i1 %27, label %28, label %33
28: ; preds = %0
%29 = load i32*, i32** %2
%30 = load i32*, i32** %3
%31 = load double*, double** %9
%32 = call i32 @_ada_use_solcon(i32 12, i32* %29, i32* %30, double* %31)
store i32 %32, i32* %1
br label %33
33: ; preds = %28, %0
%34 = load double*, double** %9
%35 = call i32 @_ada_use_solcon(i32 13, i32* %4, i32* %5, double* %34)
store i32 %35, i32* %1
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37)
%39 = load double*, double** %9
%40 = call i32 @_ada_use_solcon(i32 14, i32* %4, i32* %5, double* %39)
store i32 %40, i32* %1
%41 = load i32, i32* %5
%42 = mul nsw i32 2, %41
%43 = add nsw i32 %42, 5
%44 = call i64 @calloc(i32 %43, i32 8)
%45 = inttoptr i64 %44 to double*
store double* %45, double** %9
store i32 0, i32* %6
store i32 0, i32* %8
br label %46
46: ; preds = %103, %33
%47 = load i32, i32* %8
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %106
50: ; preds = %46
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%52 = load double*, double** %9
%53 = call i32 @_ada_use_solcon(i32 15, i32* %5, i32* %51, double* %52)
store i32 %53, i32* %1
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = load double*, double** %9
%58 = load i32, i32* %5
%59 = mul nsw i32 2, %58
%60 = add nsw i32 %59, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %57, i64 %61
%63 = load double, double* %62
store double %63, double* %10
%64 = load double*, double** %9
%65 = load i32, i32* %5
%66 = mul nsw i32 2, %65
%67 = add nsw i32 %66, 3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %64, i64 %68
%70 = load double, double* %69
store double %70, double* %11
%71 = load double*, double** %9
%72 = load i32, i32* %5
%73 = mul nsw i32 2, %72
%74 = add nsw i32 %73, 4
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %71, i64 %75
%77 = load double, double* %76
store double %77, double* %12
%78 = load i32, i32* %5
%79 = load double*, double** %9
%80 = getelementptr inbounds double, double* %79, i64 0
%81 = load double, double* %80
%82 = load double*, double** %9
%83 = getelementptr inbounds double, double* %82, i64 1
%84 = load double, double* %83
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%86 = load i32, i32* %85
%87 = load double*, double** %9
%88 = getelementptr inbounds double, double* %87, i64 2
%89 = load double, double* %10
%90 = load double, double* %11
%91 = load double, double* %12
%92 = call i32 @write_solution(i32 %78, double %81, double %84, i32 %86, double* %88, double %89, double %90, double %91)
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%94 = load i32, i32* %93
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %94, i32* %95
%96 = load i32, i32* %5
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %96, i32* %97
%98 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%99 = load double*, double** %9
%100 = call i32 @_ada_use_solcon(i32 16, i32* %6, i32* %98, double* %99)
store i32 %100, i32* %1
%101 = load i32, i32* %6
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %101)
br label %103
103: ; preds = %50
%104 = load i32, i32* %8
%105 = add nsw i32 %104, 1
store i32 %105, i32* %8
br label %46
106: ; preds = %46
%107 = load i32*, i32** %2
%108 = load i32*, i32** %3
%109 = load double*, double** %9
%110 = call i32 @_ada_use_solcon(i32 17, i32* %107, i32* %108, double* %109)
store i32 %110, i32* %1
%111 = load i32*, i32** %2
%112 = load i32*, i32** %3
%113 = load double*, double** %9
%114 = call i32 @_ada_use_solcon(i32 18, i32* %111, i32* %112, double* %113)
store i32 %114, 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 [2 x i32]
%5 = alloca i8
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = tail call i32 @_ada_use_solcon(i32 10, i32* undef, i32* undef, double* undef)
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @_ada_use_solcon(i32 11, i32* undef, i32* undef, double* undef)
%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 @_ada_use_solcon(i32 12, i32* undef, i32* undef, double* undef)
br label %19
19: ; preds = %17, %0
%20 = call i32 @_ada_use_solcon(i32 13, i32* %1, i32* %2, double* undef)
%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 = call i32 @_ada_use_solcon(i32 14, i32* %1, i32* %2, double* undef)
%25 = load i32, i32* %2
%26 = shl nsw i32 %25, 1
%27 = add nsw i32 %26, 5
%28 = call i64 @calloc(i32 %27, i32 8)
%29 = inttoptr i64 %28 to double*
store i32 0, i32* %3
%30 = load i32, i32* %1
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %67
32: ; preds = %19
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%34 = getelementptr inbounds double, double* %29, i64 1
%35 = getelementptr inbounds double, double* %29, i64 2
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
br label %37
37: ; preds = %32, %37
%38 = phi i32 [ 0, %32 ], [ %40, %37 ]
%39 = call i32 @_ada_use_solcon(i32 15, i32* %2, i32* %33, double* %29)
%40 = add nuw nsw i32 %38, 1
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %2
%43 = shl nsw i32 %42, 1
%44 = add nsw i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %29, i64 %45
%47 = load double, double* %46
%48 = add nsw i32 %43, 3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %29, i64 %49
%51 = load double, double* %50
%52 = add nsw i32 %43, 4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %29, i64 %53
%55 = load double, double* %54
%56 = load double, double* %29
%57 = load double, double* %34
%58 = load i32, i32* %33
%59 = call i32 @write_solution(i32 %42, double %56, double %57, i32 %58, double* %35, double %47, double %51, double %55)
%60 = load i32, i32* %33
store i32 %60, i32* %36
%61 = load i32, i32* %2
store i32 %61, i32* %33
%62 = call i32 @_ada_use_solcon(i32 16, i32* %3, i32* %33, double* %29)
%63 = load i32, i32* %3
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %1
%66 = icmp slt i32 %40, %65
br i1 %66, label %37, label %67
67: ; preds = %37, %19
%68 = call i32 @_ada_use_solcon(i32 17, i32* undef, i32* undef, double* %29)
%69 = call i32 @_ada_use_solcon(i32 18, i32* undef, i32* undef, double* %29)
ret void
}