#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
void saveSBAStructureDataAsPLY(char *fname, double *motstruct, int ncams,
                               int n3Dpts, int cnp, int pnp, int withrgb) {
  register int i;
  FILE *fp;
  if (pnp != 3) {
    fprintf(stderr,
            "saveSBAStructureDataAsPLY: .ply file output is only meaningful "
            "for 3-dimensional points (got %dD)\n",
            pnp);
    exit(1);
  }
  if ((fp = fopen(fname, "w")) == NULL) {
    fprintf(stderr,
            "saveSBAStructureDataAsPLY: error opening file %s for writing\n",
            fname);
    exit(1);
  }
  fprintf(fp, "ply\nformat ascii 1.0\n");
  fprintf(fp, "element vertex %d\n", n3Dpts);
  fprintf(fp, "property float x\nproperty float y\nproperty float z\n");
  if (withrgb)
    fprintf(fp, "property uchar diffuse_red\nproperty uchar "
                "diffuse_green\nproperty uchar diffuse_blue\n");
  fprintf(fp, "comment format of each line is xyz RGB\n");
  fprintf(fp, "end_header\n");
  motstruct += ncams * cnp;
  for (i = 0; i < n3Dpts; ++i) {
    if (withrgb)
      fprintf(fp, "%.6f %.6f %.6f 0 0 0\n", motstruct[i], motstruct[i + 1],
              motstruct[i + 2]);
    else
      fprintf(fp, "%.6f %.6f %.6f\n", motstruct[i], motstruct[i + 1],
              motstruct[i + 2]);
    motstruct += pnp;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<saveSBAStructureDataAsPLY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
je     1190 <saveSBAStructureDataAsPLY+0x50>
mov    0x2e6e(%rip),%rax
movslq (%rax),%rdi
mov    -0x20(%rbp),%edx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d4 <saveSBAStructureDataAsPLY+0x94>
mov    0x2e2b(%rip),%rax
movslq (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rdi
lea    0xec4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xec5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpl   $0x0,0x10(%rbp)
je     1229 <saveSBAStructureDataAsPLY+0xe9>
mov    -0x30(%rbp),%rdi
lea    0xede(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xf21(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xf37(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1331 <saveSBAStructureDataAsPLY+0x1f1>
cmpl   $0x0,0x10(%rbp)
je     12cb <saveSBAStructureDataAsPLY+0x18b>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
lea    0xeca(%rip),%rsi
mov    $0x3,%al
call   1040 <fprintf@plt>
jmp    130e <saveSBAStructureDataAsPLY+0x1ce>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
lea    0xe98(%rip),%rsi
mov    $0x3,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    126d <saveSBAStructureDataAsPLY+0x12d>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveSBAStructureDataAsPLY>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
cmp    $0x3,%r9d
jne    129e <saveSBAStructureDataAsPLY+0x14e>
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %rdi,%rbp
mov    0x40(%rsp),%r14d
lea    0xee3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     12c3 <saveSBAStructureDataAsPLY+0x173>
mov    %rax,%r12
lea    0xf0b(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
lea    0xf08(%rip),%rsi
mov    %r12,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xf07(%rip),%rdi
mov    $0x33,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
test   %r14d,%r14d
je     11f5 <saveSBAStructureDataAsPLY+0xa5>
lea    0xf1d(%rip),%rdi
mov    $0x54,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
lea    0xf59(%rip),%rdi
mov    $0x27,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
lea    0xf68(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
test   %r13d,%r13d
jle    1288 <saveSBAStructureDataAsPLY+0x138>
imul   %ebx,%r15d
test   %r14d,%r14d
movslq %r15d,%rax
lea    0xf62(%rip),%rcx
lea    0xf45(%rip),%r14
cmove  %rcx,%r14
mov    %r13d,%r15d
mov    (%rsp),%rcx
lea    (%rcx,%rax,8),%rbp
add    $0x10,%rbp
shl    $0x5,%r15
xor    %ebx,%ebx
nopl   (%rax)
movsd  -0x10(%rbp,%rbx,1),%xmm0
movsd  -0x8(%rbp,%rbx,1),%xmm1
movsd  0x0(%rbp,%rbx,1),%xmm2
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%al
call   1040 <fprintf@plt>
add    $0x20,%rbx
cmp    %rbx,%r15
jne    1260 <saveSBAStructureDataAsPLY+0x110>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2d3b(%rip),%rax
movslq (%rax),%rdi
lea    0xd51(%rip),%rsi
mov    %r9d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2d16(%rip),%rax
movslq (%rax),%rdi
lea    0xd91(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [99 x i8] c"saveSBAStructureDataAsPLY: .ply file output is only meaningful for 3-dimensional points (got %dD)\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [62 x i8] c"saveSBAStructureDataAsPLY: error opening file %s for writing\0A\00"
@.str.3 = [22 x i8] c"ply\0Aformat ascii 1.0\0A\00"
@.str.4 = [19 x i8] c"element vertex %d\0A\00"
@.str.5 = [52 x i8] c"property float x\0Aproperty float y\0Aproperty float z\0A\00"
@.str.6 = [85 x i8] c"property uchar diffuse_red\0Aproperty uchar diffuse_green\0Aproperty uchar diffuse_blue\0A\00"
@.str.7 = [40 x i8] c"comment format of each line is xyz RGB\0A\00"
@.str.8 = [12 x i8] c"end_header\0A\00"
@.str.9 = [22 x i8] c"%.6f %.6f %.6f 0 0 0\0A\00"
@.str.10 = [16 x i8] c"%.6f %.6f %.6f\0A\00"
define void @saveSBAStructureDataAsPLY(i8* %0, double* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
store i8* %0, i8** %8
store double* %1, double** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%17 = load i32, i32* %13
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %26
19: ; preds = %7
%20 = load i32, i32* @stderr
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i32*
%23 = load i32, i32* %13
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %7
%27 = load i8*, i8** %8
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %16
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = sext i32 %31 to i64
%33 = inttoptr i64 %32 to i32*
%34 = load i8*, i8** %8
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
%38 = load i32*, i32** %16
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32*, i32** %16
%41 = load i32, i32* %11
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %16
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
%45 = load i32, i32* %14
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %37
%48 = load i32*, i32** %16
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %47, %37
%51 = load i32*, i32** %16
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
%53 = load i32*, i32** %16
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%55 = load i32, i32* %10
%56 = load i32, i32* %12
%57 = mul nsw i32 %55, %56
%58 = load double*, double** %9
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds double, double* %58, i64 %59
store double* %60, double** %9
store i32 0, i32* %15
br label %61
61: ; preds = %113, %50
%62 = load i32, i32* %15
%63 = load i32, i32* %11
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %116
65: ; preds = %61
%66 = load i32, i32* %14
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %88
68: ; preds = %65
%69 = load i32*, i32** %16
%70 = load double*, double** %9
%71 = load i32, i32* %15
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load double*, double** %9
%76 = load i32, i32* %15
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %75, i64 %78
%80 = load double, double* %79
%81 = load double*, double** %9
%82 = load i32, i32* %15
%83 = add nsw i32 %82, 2
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %81, i64 %84
%86 = load double, double* %85
%87 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), double %74, double %80, double %86)
br label %108
88: ; preds = %65
%89 = load i32*, i32** %16
%90 = load double*, double** %9
%91 = load i32, i32* %15
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double*, double** %9
%96 = load i32, i32* %15
%97 = add nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %95, i64 %98
%100 = load double, double* %99
%101 = load double*, double** %9
%102 = load i32, i32* %15
%103 = add nsw i32 %102, 2
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %101, i64 %104
%106 = load double, double* %105
%107 = call i32 (i32*, i8*, ...) @fprintf(i32* %89, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), double %94, double %100, double %106)
br label %108
108: ; preds = %88, %68
%109 = load i32, i32* %13
%110 = load double*, double** %9
%111 = sext i32 %109 to i64
%112 = getelementptr inbounds double, double* %110, i64 %111
store double* %112, double** %9
br label %113
113: ; preds = %108
%114 = load i32, i32* %15
%115 = add nsw i32 %114, 1
store i32 %115, i32* %15
br label %61
116: ; preds = %61
%117 = load i32*, i32** %16
%118 = call i32 @fclose(i32* %117)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [99 x i8] c"saveSBAStructureDataAsPLY: .ply file output is only meaningful for 3-dimensional points (got %dD)\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [62 x i8] c"saveSBAStructureDataAsPLY: error opening file %s for writing\0A\00"
@.str.3 = [22 x i8] c"ply\0Aformat ascii 1.0\0A\00"
@.str.4 = [19 x i8] c"element vertex %d\0A\00"
@.str.5 = [52 x i8] c"property float x\0Aproperty float y\0Aproperty float z\0A\00"
@.str.6 = [85 x i8] c"property uchar diffuse_red\0Aproperty uchar diffuse_green\0Aproperty uchar diffuse_blue\0A\00"
@.str.7 = [40 x i8] c"comment format of each line is xyz RGB\0A\00"
@.str.8 = [12 x i8] c"end_header\0A\00"
@.str.9 = [22 x i8] c"%.6f %.6f %.6f 0 0 0\0A\00"
@.str.10 = [16 x i8] c"%.6f %.6f %.6f\0A\00"
define void @saveSBAStructureDataAsPLY(i8* %0, double* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = icmp eq i32 %5, 3
br i1 %8, label %15, label %9
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0), i32 %5)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i32*
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 21, i64 1, i32* %16)
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %3)
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i64 51, i64 1, i32* %16)
%28 = icmp eq i32 %6, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.6, i64 0, i64 0), i64 84, i64 1, i32* %16)
br label %31
31: ; preds = %29, %24
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i64 39, i64 1, i32* %16)
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i64 11, i64 1, i32* %16)
%34 = icmp sgt i32 %3, 0
br i1 %34, label %35, label %55
35: ; preds = %31
%36 = mul nsw i32 %4, %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %1, i64 %37
%39 = zext i32 %3 to i64
%40 = select i1 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0)
br label %41
41: ; preds = %35, %41
%42 = phi i64 [ 0, %35 ], [ %46, %41 ]
%43 = phi double* [ %38, %35 ], [ %53, %41 ]
%44 = getelementptr inbounds double, double* %43, i64 %42
%45 = load double, double* %44
%46 = add nuw nsw i64 %42, 1
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = load double, double* %47
%49 = add nuw nsw i64 %42, 2
%50 = getelementptr inbounds double, double* %43, i64 %49
%51 = load double, double* %50
%52 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* %40, double %45, double %48, double %51)
%53 = getelementptr inbounds double, double* %43, i64 3
%54 = icmp eq i64 %46, %39
br i1 %54, label %55, label %41
55: ; preds = %41, %31
%56 = tail call i32 @fclose(i32* %16)
ret void
}