#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*/ ShowErrorMessage(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void AppendSolutionsMatrix(int iRun, int puno, int R[], char savename[],
                           int iOutputType, int iIncludeHeaders) {
  FILE *fp;
  int i, iStatus;
  char sDelimiter[20];
  fp = fopen(savename, "a");
  if (!fp)
    ShowErrorMessage("Cannot save output to %s \n", savename);
  if (iOutputType > 1)
    strcpy(sDelimiter, ",");
  else
    strcpy(sDelimiter, "\t");
  if (iIncludeHeaders == 1) {
    fprintf(fp, "S%i%s", iRun, sDelimiter);
  }
  for (i = (puno - 1); i > (-1); i--) {
    if (i < (puno - 1))
      fprintf(fp, "%s", sDelimiter);
    iStatus = R[i];
    if (R[i] == 3)
      iStatus = 0;
    if (R[i] == 2)
      iStatus = 1;
    fprintf(fp, "%i", iStatus);
  }
  fprintf(fp, "\n");
  fclose(fp);
}


x86 assembly (clang, -O0):
<AppendSolutionsMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <AppendSolutionsMatrix+0x4d>
mov    -0x18(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1070 <ShowErrorMessage@plt>
cmpl   $0x1,-0x1c(%rbp)
jle    11bc <AppendSolutionsMatrix+0x6c>
lea    -0x50(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11cc <AppendSolutionsMatrix+0x7c>
lea    -0x50(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x1,-0x20(%rbp)
jne    11ef <AppendSolutionsMatrix+0x9f>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    -0x50(%rbp),%rcx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jle    128c <AppendSolutionsMatrix+0x13c>
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1229 <AppendSolutionsMatrix+0xd9>
mov    -0x28(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x3,(%rax,%rcx,4)
jne    1250 <AppendSolutionsMatrix+0x100>
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x2,(%rax,%rcx,4)
jne    1269 <AppendSolutionsMatrix+0x119>
movl   $0x1,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f8 <AppendSolutionsMatrix+0xa8>
mov    -0x28(%rbp),%rdi
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AppendSolutionsMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%ebp
mov    %r8d,%r13d
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,0xc(%rsp)
lea    0xe68(%rip),%rsi
mov    %rcx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b7 <AppendSolutionsMatrix+0x47>
lea    0xe53(%rip),%rdi
mov    %r15,%rsi
call   1090 <ShowErrorMessage@plt>
cmp    $0x2,%r13d
lea    0xe5b(%rip),%rax
lea    0xe56(%rip),%rsi
cmovge %rax,%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
cmp    $0x1,%ebp
jne    11f6 <AppendSolutionsMatrix+0x86>
lea    0xe3e(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r12d,%r12d
jle    129f <AppendSolutionsMatrix+0x12f>
add    $0xffffffff,%r12d
mov    %r12d,%ebp
mov    (%r14,%rbp,4),%eax
xor    %ecx,%ecx
cmp    $0x3,%eax
mov    %eax,%edx
cmove  %ecx,%edx
cmp    $0x2,%eax
mov    $0x1,%eax
cmove  %eax,%edx
lea    0xe01(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r12d,%r12d
je     129f <AppendSolutionsMatrix+0x12f>
lea    0xdeb(%rip),%r12
mov    %rbp,%r13
jmp    1287 <AppendSolutionsMatrix+0x117>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    -0x4(%r14,%r13,4),%eax
cmp    $0x3,%eax
mov    %eax,%edx
mov    $0x0,%ecx
cmove  %ecx,%edx
cmp    $0x2,%eax
mov    $0x1,%eax
cmove  %eax,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x1(%r15),%rax
mov    %r15,%r13
cmp    $0x1,%rax
jle    129f <AppendSolutionsMatrix+0x12f>
lea    -0x1(%r13),%r15
cmp    %rbp,%r13
jg     1250 <AppendSolutionsMatrix+0xe0>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
jmp    1250 <AppendSolutionsMatrix+0xe0>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [27 x i8] c"Cannot save output to %s \0A\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [6 x i8] c"S%i%s\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [3 x i8] c"%i\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @AppendSolutionsMatrix(i32 %0, i32 %1, i32* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [20 x i8]
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%17 = load i8*, i8** %10
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %13
%19 = load i32*, i32** %13
%20 = icmp ne i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %6
%22 = load i8*, i8** %10
%23 = call i32 @ShowErrorMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %6
%25 = load i32, i32* %11
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %33
30: ; preds = %24
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %12
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32*, i32** %13
%38 = load i32, i32* %7
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %38, i8* %39)
br label %41
41: ; preds = %36, %33
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %14
br label %44
44: ; preds = %81, %41
%45 = load i32, i32* %14
%46 = icmp sgt i32 %45, -1
br i1 %46, label %47, label %84
47: ; preds = %44
%48 = load i32, i32* %14
%49 = load i32, i32* %8
%50 = sub nsw i32 %49, 1
%51 = icmp slt i32 %48, %50
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32*, i32** %13
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %52, %47
%57 = load i32*, i32** %9
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
store i32 %61, i32* %15
%62 = load i32*, i32** %9
%63 = load i32, i32* %14
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = icmp eq i32 %66, 3
br i1 %67, label %68, label %69
68: ; preds = %56
store i32 0, i32* %15
br label %69
69: ; preds = %68, %56
%70 = load i32*, i32** %9
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = icmp eq i32 %74, 2
br i1 %75, label %76, label %77
76: ; preds = %69
store i32 1, i32* %15
br label %77
77: ; preds = %76, %69
%78 = load i32*, i32** %13
%79 = load i32, i32* %15
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %77
%82 = load i32, i32* %14
%83 = add nsw i32 %82, -1
store i32 %83, i32* %14
br label %44
84: ; preds = %44
%85 = load i32*, i32** %13
%86 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%87 = load i32*, i32** %13
%88 = call i32 @fclose(i32* %87)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [27 x i8] c"Cannot save output to %s \0A\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [6 x i8] c"S%i%s\00"
@.str.6 = [3 x i8] c"%i\00"
define void @AppendSolutionsMatrix(i32 %0, i32 %1, i32* nocapture %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @ShowErrorMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %13
13: ; preds = %11, %6
%14 = icmp sgt i32 %4, 1
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%16 = call i32 @strcpy(i8* %8, i8* %15)
%17 = icmp eq i32 %5, 1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %0, i8* %8)
br label %20
20: ; preds = %18, %13
%21 = add i32 %1, -1
%22 = icmp sgt i32 %1, 0
br i1 %22, label %23, label %49
23: ; preds = %20
%24 = zext i32 %21 to i64
%25 = zext i32 %21 to i64
%26 = getelementptr inbounds i32, i32* %2, i64 %24
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 3
%29 = select i1 %28, i32 0, i32 %27
%30 = icmp eq i32 %27, 2
%31 = select i1 %30, i32 1, i32 %29
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = icmp eq i32 %21, 0
br i1 %33, label %49, label %34
34: ; preds = %23, %40
%35 = phi i64 [ %36, %40 ], [ %24, %23 ]
%36 = add nsw i64 %35, -1
%37 = icmp sgt i64 %35, %25
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = call i32 @fputs(i8* %8, i32* %9)
br label %40
40: ; preds = %38, %34
%41 = getelementptr inbounds i32, i32* %2, i64 %36
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 3
%44 = select i1 %43, i32 0, i32 %42
%45 = icmp eq i32 %42, 2
%46 = select i1 %45, i32 1, i32 %44
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %46)
%48 = icmp sgt i64 %35, 1
br i1 %48, label %34, label %49
49: ; preds = %23, %40, %20
%50 = call i32 @fputc(i32 10, i32* %9)
%51 = call i32 @fclose(i32* %9)
ret void
}