#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*/ close_output_file();
char getchar();
int /*<<< orphan*/ prepare_for_next_level_down(int);
int /*<<< orphan*/ printf(char *, ...);
int reporting_path_tracker(int, int *, double *, int *, int *, int *, int *);
int /*<<< orphan*/ solcon_close_solution_input_file(int /*<<< orphan*/);
int solcon_read_next_solution(int, int *, double *);
int solcon_read_solution_dimensions(int *, int *);
int solcon_write_solution_banner_to_defined_output_file();
int solcon_write_solution_dimensions_to_defined_output_file(int, int);
int write_next_solution_with_diagnostics(int *, int, int, double *, int, int,
                                         int, int);
int run_cascade(int monitor) {
  int fail, len, dim, m, i, nbstep, nbfail, nbiter, nbsyst, cnt, ind;
  char ans = 'y';
  double *sol;
  while (ans == 'y') {
    fail = solcon_read_solution_dimensions(&len, &dim);
    fail = solcon_write_solution_banner_to_defined_output_file();
    fail = solcon_write_solution_dimensions_to_defined_output_file(len, dim);
    sol = (double *)calloc(2 * dim + 5, sizeof(double));
    cnt = 0;
    for (i = 1; i <= len; i++) {
      fail = solcon_read_next_solution(dim, &m, sol);
      if (fail == 0) {
        fail = reporting_path_tracker(dim, &m, sol, &nbstep, &nbfail, &nbiter,
                                      &nbsyst);
        if (monitor == 1)
          printf("%d : #step : %3d #fail : %3d #iter : %3d #syst : %3d\n", i,
                 nbstep, nbfail, nbiter, nbsyst);
        ind = i;
        fail = write_next_solution_with_diagnostics(&ind, dim, m, sol, nbstep,
                                                    nbfail, nbiter, nbsyst);
        cnt++;
      } else {
        if (monitor == 1)
          printf("%d : no path\n", i);
        break;
      }
    }
    printf("Wrote %d solutions to file.\n", cnt);
    close_output_file();
    solcon_close_solution_input_file(0);
    printf("\ncontinue ? (y/n) ");
    ans = getchar();
    if (ans == 'y')
      prepare_for_next_level_down(dim);
  }
  return fail;
}


x86 assembly (clang, -O0):
<run_cascade>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x79,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x79,%eax
jne    1367 <run_cascade+0x1a7>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <solcon_read_solution_dimensions@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <solcon_write_solution_banner_to_defined_output_file@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <solcon_write_solution_dimensions_to_defined_output_file@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%edi
shl    $0x1,%edi
add    $0x5,%edi
mov    $0x8,%esi
call   10c0 <calloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1316 <run_cascade+0x156>
mov    -0x10(%rbp),%edi
mov    -0x40(%rbp),%rdx
lea    -0x14(%rbp),%rsi
call   1070 <solcon_read_next_solution@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12e3 <run_cascade+0x123>
mov    -0x10(%rbp),%edi
mov    -0x40(%rbp),%rdx
lea    -0x14(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
lea    -0x24(%rbp),%r9
lea    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <reporting_path_tracker@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    12a2 <run_cascade+0xe2>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x24(%rbp),%r10d
mov    -0x28(%rbp),%eax
lea    -0x30(%rbp),%rdi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   10b0 <write_next_solution_with_diagnostics@plt>
mov    %eax,-0x8(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1303 <run_cascade+0x143>
cmpl   $0x1,-0x4(%rbp)
jne    12fe <run_cascade+0x13e>
mov    -0x18(%rbp),%esi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1316 <run_cascade+0x156>
jmp    1308 <run_cascade+0x148>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1229 <run_cascade+0x69>
mov    -0x2c(%rbp),%esi
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x0,%al
call   10e0 <close_output_file@plt>
xor    %edi,%edi
call   1050 <solcon_close_solution_input_file@plt>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x0,%al
call   10d0 <getchar@plt>
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x79,%eax
jne    1362 <run_cascade+0x1a2>
mov    -0x10(%rbp),%edi
call   1080 <prepare_for_next_level_down@plt>
jmp    11cf <run_cascade+0xf>
mov    -0x8(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_cascade>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,0xc(%rsp)
lea    0x24(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   10a0 <solcon_read_solution_dimensions@plt>
xor    %eax,%eax
call   1060 <solcon_write_solution_banner_to_defined_output_file@plt>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <solcon_write_solution_dimensions_to_defined_output_file@plt>
mov    %eax,%r12d
mov    0x4(%rsp),%eax
lea    (%rax,%rax,1),%edi
add    $0x5,%edi
mov    $0x8,%esi
call   10c0 <calloc@plt>
cmpl   $0x0,0x8(%rsp)
jle    12f0 <run_cascade+0x130>
mov    %rax,%r15
xor    %r13d,%r13d
jmp    1270 <run_cascade+0xb0>
nopl   (%rax)
mov    %r14d,0x20(%rsp)
mov    0x4(%rsp),%esi
mov    0x24(%rsp),%edx
mov    0x1c(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%ebx
lea    0x20(%rsp),%rdi
mov    %r15,%rcx
push   %rbx
push   %rax
call   10b0 <write_next_solution_with_diagnostics@plt>
add    $0x10,%rsp
mov    %r14d,%r13d
cmp    0x8(%rsp),%r14d
jge    1320 <run_cascade+0x160>
lea    0x1(%r13),%r14d
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1070 <solcon_read_next_solution@plt>
test   %eax,%eax
jne    1300 <run_cascade+0x140>
mov    0x4(%rsp),%edi
sub    $0x8,%rsp
mov    %rbp,%rsi
mov    %r15,%rdx
lea    0x24(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x18(%rsp),%rax
push   %rax
call   1030 <reporting_path_tracker@plt>
add    $0x10,%rsp
cmpl   $0x1,0xc(%rsp)
jne    1230 <run_cascade+0x70>
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x10(%rsp),%r9d
lea    0xd29(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1230 <run_cascade+0x70>
cs nopw 0x0(%rax,%rax,1)
xor    %r14d,%r14d
jmp    1323 <run_cascade+0x163>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%r12d
cmpl   $0x1,0xc(%rsp)
jne    131b <run_cascade+0x15b>
lea    0xd25(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13d,%r14d
jmp    1323 <run_cascade+0x163>
mov    %eax,%r12d
lea    0xd1a(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
call   10e0 <close_output_file@plt>
xor    %edi,%edi
call   1050 <solcon_close_solution_input_file@plt>
lea    0xd18(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
call   10d0 <getchar@plt>
cmp    $0x79,%al
jne    1369 <run_cascade+0x1a9>
mov    0x4(%rsp),%edi
call   1080 <prepare_for_next_level_down@plt>
jmp    11e0 <run_cascade+0x20>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"%d : #step : %3d #fail : %3d #iter : %3d #syst : %3d\0A\00"
@.str.1 = [14 x i8] c"%d : no path\0A\00"
@.str.2 = [29 x i8] c"Wrote %d solutions to file.\0A\00"
@.str.3 = [19 x i8] c"\0Acontinue ? (y/n) \00"
define i32 @run_cascade(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca double*
store i32 %0, i32* %2
store i8 121, i8* %14
br label %16
16: ; preds = %90, %1
%17 = load i8, i8* %14
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 121
br i1 %19, label %20, label %91
20: ; preds = %16
%21 = call i32 @solcon_read_solution_dimensions(i32* %4, i32* %5)
store i32 %21, i32* %3
%22 = call i32 (...) @solcon_write_solution_banner_to_defined_output_file()
store i32 %22, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = call i32 @solcon_write_solution_dimensions_to_defined_output_file(i32 %23, i32 %24)
store i32 %25, i32* %3
%26 = load i32, i32* %5
%27 = mul nsw i32 2, %26
%28 = add nsw i32 %27, 5
%29 = call i64 @calloc(i32 %28, i32 8)
%30 = inttoptr i64 %29 to double*
store double* %30, double** %15
store i32 0, i32* %12
store i32 1, i32* %7
br label %31
31: ; preds = %74, %20
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %77
35: ; preds = %31
%36 = load i32, i32* %5
%37 = load double*, double** %15
%38 = call i32 @solcon_read_next_solution(i32 %36, i32* %6, double* %37)
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %66
41: ; preds = %35
%42 = load i32, i32* %5
%43 = load double*, double** %15
%44 = call i32 @reporting_path_tracker(i32 %42, i32* %6, double* %43, i32* %8, i32* %9, i32* %10, i32* %11)
store i32 %44, i32* %3
%45 = load i32, i32* %2
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %54
47: ; preds = %41
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %48, i32 %49, i32 %50, i32 %51, i32 %52)
br label %54
54: ; preds = %47, %41
%55 = load i32, i32* %7
store i32 %55, i32* %13
%56 = load i32, i32* %5
%57 = load i32, i32* %6
%58 = load double*, double** %15
%59 = load i32, i32* %8
%60 = load i32, i32* %9
%61 = load i32, i32* %10
%62 = load i32, i32* %11
%63 = call i32 @write_next_solution_with_diagnostics(i32* %13, i32 %56, i32 %57, double* %58, i32 %59, i32 %60, i32 %61, i32 %62)
store i32 %63, i32* %3
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %73
66: ; preds = %35
%67 = load i32, i32* %2
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32, i32* %7
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %69, %66
br label %77
73: ; preds = %54
br label %74
74: ; preds = %73
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
br label %31
77: ; preds = %72, %31
%78 = load i32, i32* %12
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %78)
%80 = call i32 (...) @close_output_file()
%81 = call i32 @solcon_close_solution_input_file(i32 0)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%83 = call signext i8 (...) @getchar()
store i8 %83, i8* %14
%84 = load i8, i8* %14
%85 = sext i8 %84 to i32
%86 = icmp eq i32 %85, 121
br i1 %86, label %87, label %90
87: ; preds = %77
%88 = load i32, i32* %5
%89 = call i32 @prepare_for_next_level_down(i32 %88)
br label %90
90: ; preds = %87, %77
br label %16
91: ; preds = %16
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@.str = [54 x i8] c"%d : #step : %3d #fail : %3d #iter : %3d #syst : %3d\0A\00"
@.str.1 = [14 x i8] c"%d : no path\0A\00"
@.str.2 = [29 x i8] c"Wrote %d solutions to file.\0A\00"
@.str.3 = [19 x i8] c"\0Acontinue ? (y/n) \00"
define i32 @run_cascade(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = bitcast i32* %7 to i8*
%16 = bitcast i32* %8 to i8*
%17 = bitcast i32* %9 to i8*
%18 = icmp eq i32 %0, 1
br label %19
19: ; preds = %71, %1
%20 = call i32 @solcon_read_solution_dimensions(i32* %2, i32* %3)
%21 = call i32 (...) @solcon_write_solution_banner_to_defined_output_file()
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = call i32 @solcon_write_solution_dimensions_to_defined_output_file(i32 %22, i32 %23)
%25 = load i32, i32* %3
%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*
%30 = load i32, i32* %2
%31 = icmp slt i32 %30, 1
br i1 %31, label %62, label %32
32: ; preds = %19, %47
%33 = phi i32 [ %55, %47 ], [ 0, %19 ]
%34 = phi i32 [ %56, %47 ], [ 1, %19 ]
%35 = load i32, i32* %3
%36 = call i32 @solcon_read_next_solution(i32 %35, i32* %4, double* %29)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %59
38: ; preds = %32
%39 = load i32, i32* %3
%40 = call i32 @reporting_path_tracker(i32 %39, i32* %4, double* %29, i32* %5, i32* %6, i32* %7, i32* %8)
br i1 %18, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %42, i32 %43, i32 %44, i32 %45)
br label %47
47: ; preds = %41, %38
store i32 %34, i32* %9
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = load i32, i32* %5
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = call i32 @write_next_solution_with_diagnostics(i32* %9, i32 %48, i32 %49, double* %29, i32 %50, i32 %51, i32 %52, i32 %53)
%55 = add nuw nsw i32 %33, 1
%56 = add nuw nsw i32 %34, 1
%57 = load i32, i32* %2
%58 = icmp slt i32 %34, %57
br i1 %58, label %32, label %62
59: ; preds = %32
br i1 %18, label %60, label %62
60: ; preds = %59
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %62
62: ; preds = %47, %19, %59, %60
%63 = phi i32 [ %33, %60 ], [ %33, %59 ], [ 0, %19 ], [ %55, %47 ]
%64 = phi i32 [ %36, %60 ], [ %36, %59 ], [ %24, %19 ], [ %54, %47 ]
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %63)
%66 = call i32 (...) @close_output_file()
%67 = call i32 @solcon_close_solution_input_file(i32 0)
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%69 = call signext i8 (...) @getchar()
%70 = icmp eq i8 %69, 121
br i1 %70, label %71, label %74
71: ; preds = %62
%72 = load i32, i32* %3
%73 = call i32 @prepare_for_next_level_down(i32 %72)
br label %19
74: ; preds = %62
ret i32 %64
}