#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];
  if (iOutputType > 1)
    strcpy(sDelimiter, ",");
  else
    strcpy(sDelimiter, "\t");
  {
    fp = fopen(savename, "a");
    if (!fp)
      ShowErrorMessage("Cannot save output to %s \n", savename);
    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)
cmpl   $0x1,-0x1c(%rbp)
jle    118d <AppendSolutionsMatrix+0x3d>
lea    -0x50(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    119d <AppendSolutionsMatrix+0x4d>
lea    -0x50(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cc <AppendSolutionsMatrix+0x7c>
mov    -0x18(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1070 <ShowErrorMessage@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    0xd88(%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    $0x18,%rsp
mov    %r9d,%ebp
mov    %rcx,%r13
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%r15d
cmp    $0x2,%r8d
lea    0xe68(%rip),%rax
lea    0xe63(%rip),%rsi
cmovge %rax,%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0xe52(%rip),%rsi
mov    %r13,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d1 <AppendSolutionsMatrix+0x61>
cmp    $0x1,%ebp
je     11e5 <AppendSolutionsMatrix+0x75>
test   %r12d,%r12d
jg     1205 <AppendSolutionsMatrix+0x95>
jmp    129d <AppendSolutionsMatrix+0x12d>
lea    0xe2e(%rip),%rdi
mov    %r13,%rsi
call   1090 <ShowErrorMessage@plt>
cmp    $0x1,%ebp
jne    11c7 <AppendSolutionsMatrix+0x57>
lea    0xe35(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r12d,%r12d
jle    129d <AppendSolutionsMatrix+0x12d>
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    0xdfb(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r12d,%r12d
je     129d <AppendSolutionsMatrix+0x12d>
lea    0xde5(%rip),%r12
mov    %rbp,%r13
jmp    1287 <AppendSolutionsMatrix+0x117>
nopw   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    129d <AppendSolutionsMatrix+0x12d>
lea    -0x1(%r13),%r15
cmp    %rbp,%r13
jg     1250 <AppendSolutionsMatrix+0xe0>
mov    %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    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] c"\09\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [27 x i8] c"Cannot save output to %s \0A\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 i32, i32* %11
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %6
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
22: ; preds = %6
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %19
%26 = load i8*, i8** %10
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %13
%28 = load i32*, i32** %13
%29 = icmp ne i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %25
%31 = load i8*, i8** %10
%32 = call i32 @ShowErrorMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %25
%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",\00"
@.str.1 = [2 x i8] c"\09\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [27 x i8] c"Cannot save output to %s \0A\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 = icmp sgt i32 %4, 1
%10 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%11 = call i32 @strcpy(i8* %8, i8* %10)
%12 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 @ShowErrorMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %16
16: ; preds = %14, %6
%17 = icmp eq i32 %5, 1
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, 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, %16
%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* %12, 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* %12)
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* %12, 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* %12)
%51 = call i32 @fclose(i32* %12)
ret void
}