#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void stub1(double *, int, double *, int);
void printSBAMotionData(FILE *fp, double *motstruct, int ncams, int cnp,
                        void (*outfilter)(double *pin, int nin, double *pout,
                                          int nout),
                        int outcnp) {
  register int i;
  fputs("Motion parameters:\n", fp);
  if (!outfilter || outcnp <= 0) {
    for (i = 0; i < ncams * cnp; ++i) {
      fprintf(fp, "%.10e ", motstruct[i]);
      if ((i + 1) % cnp == 0)
        fputc('\n', fp);
    }
  } else {
    register int j;
    double *filtered;
    if ((filtered = (double *)malloc(outcnp * sizeof(double))) == NULL) {
      ;
      fprintf(stderr, "memory allocation failed in printSBAMotionData()\n");
      exit(1);
    }
    for (i = 0; i < ncams * cnp; i += cnp) {
      (*outfilter)(motstruct + i, cnp, filtered, outcnp);
      for (j = 0; j < outcnp; ++j)
        fprintf(fp, "%.10e ", filtered[j]);
      fputc('\n', fp);
    }
    free(filtered);
  }
}


x86 assembly (clang, -O0):
<printSBAMotionData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1040 <fputs@plt>
cmpq   $0x0,-0x20(%rbp)
je     11a3 <printSBAMotionData+0x43>
cmpl   $0x0,-0x24(%rbp)
jg     1214 <printSBAMotionData+0xb4>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    120f <printSBAMotionData+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe40(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
jne    11fc <printSBAMotionData+0x9c>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
jmp    1201 <printSBAMotionData+0xa1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11aa <printSBAMotionData+0x4a>
jmp    12f0 <printSBAMotionData+0x190>
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1253 <printSBAMotionData+0xf3>
mov    0x2da8(%rip),%rax
movslq (%rax),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    12e7 <printSBAMotionData+0x187>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rdi
mov    -0x18(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   *%rax
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12cb <printSBAMotionData+0x16b>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd5e(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1292 <printSBAMotionData+0x132>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    125a <printSBAMotionData+0xfa>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printSBAMotionData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r14d
mov    %r8,%rbp
mov    %ecx,%r13d
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe79(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbp,0x30(%rsp)
test   %rbp,%rbp
je     1281 <printSBAMotionData+0x121>
test   %r14d,%r14d
jle    1281 <printSBAMotionData+0x121>
mov    %r12,0x28(%rsp)
mov    %r14,0x10(%rsp)
lea    0x0(,%r14,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     12e4 <printSBAMotionData+0x184>
mov    %rax,%rbp
imul   %r13d,%r15d
test   %r15d,%r15d
jle    126b <printSBAMotionData+0x10b>
movslq %r13d,%rax
mov    %rax,0x20(%rsp)
mov    %r15d,%eax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%r15d
xor    %r14d,%r14d
lea    0xe15(%rip),%r12
mov    %r13d,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x28(%rsp),%rax
lea    (%rax,%r14,8),%rdi
mov    %r13d,%esi
mov    %rbp,%rdx
mov    0x10(%rsp),%rcx
call   *0x30(%rsp)
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
movsd  0x0(%rbp,%r13,8),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    1230 <printSBAMotionData+0xd0>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    0x20(%rsp),%r14
cmp    0x18(%rsp),%r14
mov    0xc(%rsp),%r13d
jl     1210 <printSBAMotionData+0xb0>
mov    %rbp,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
imul   %r13d,%r15d
test   %r15d,%r15d
jle    12d5 <printSBAMotionData+0x175>
mov    %r15d,%r14d
xor    %ebp,%ebp
lea    0xd7e(%rip),%r15
jmp    12a5 <printSBAMotionData+0x145>
nopl   0x0(%rax,%rax,1)
cmp    %rbp,%r14
je     12d5 <printSBAMotionData+0x175>
movsd  (%r12,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbp
mov    %ebp,%eax
cltd
idiv   %r13d
test   %edx,%edx
jne    12a0 <printSBAMotionData+0x140>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    12a0 <printSBAMotionData+0x140>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf5(%rip),%rax
movslq (%rax),%rcx
lea    0xd26(%rip),%rdi
mov    $0x31,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Motion parameters:\0A\00"
@.str.1 = [7 x i8] c"%.10e \00"
@stderr = global i32 0
@.str.2 = [50 x i8] c"memory allocation failed in printSBAMotionData()\0A\00"
define void @printSBAMotionData(i32* %0, double* %1, i32 %2, i32 %3, void (double*, i32, double*, i32)* %4, i32 %5) {
%7 = alloca i32*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca void (double*, i32, double*, i32)*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
store i32* %0, i32** %7
store double* %1, double** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store void (double*, i32, double*, i32)* %4, void (double*, i32, double*, i32)** %11
store i32 %5, i32* %12
%16 = load i32*, i32** %7
%17 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %16)
%18 = load void (double*, i32, double*, i32)*, void (double*, i32, double*, i32)** %11
%19 = icmp ne void (double*, i32, double*, i32)* %18, null
br i1 %19, label %20, label %23
20: ; preds = %6
%21 = load i32, i32* %12
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %51
23: ; preds = %20, %6
store i32 0, i32* %13
br label %24
24: ; preds = %47, %23
%25 = load i32, i32* %13
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = mul nsw i32 %26, %27
%29 = icmp slt i32 %25, %28
br i1 %29, label %30, label %50
30: ; preds = %24
%31 = load i32*, i32** %7
%32 = load double*, double** %8
%33 = load i32, i32* %13
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %36)
%38 = load i32, i32* %13
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %10
%41 = srem i32 %39, %40
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %30
%44 = load i32*, i32** %7
%45 = call i32 @fputc(i8 signext 10, i32* %44)
br label %46
46: ; preds = %43, %30
br label %47
47: ; preds = %46
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %24
50: ; preds = %24
br label %106
51: ; preds = %20
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 8
%55 = trunc i64 %54 to i32
%56 = call i64 @malloc(i32 %55)
%57 = inttoptr i64 %56 to double*
store double* %57, double** %15
%58 = icmp eq double* %57, null
br i1 %58, label %59, label %65
59: ; preds = %51
%60 = load i32, i32* @stderr
%61 = sext i32 %60 to i64
%62 = inttoptr i64 %61 to i32*
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %51
store i32 0, i32* %13
br label %66
66: ; preds = %99, %65
%67 = load i32, i32* %13
%68 = load i32, i32* %9
%69 = load i32, i32* %10
%70 = mul nsw i32 %68, %69
%71 = icmp slt i32 %67, %70
br i1 %71, label %72, label %103
72: ; preds = %66
%73 = load void (double*, i32, double*, i32)*, void (double*, i32, double*, i32)** %11
%74 = load double*, double** %8
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = load i32, i32* %10
%79 = load double*, double** %15
%80 = load i32, i32* %12
store i32 0, i32* %14
br label %81
81: ; preds = %93, %72
%82 = load i32, i32* %14
%83 = load i32, i32* %12
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %96
85: ; preds = %81
%86 = load i32*, i32** %7
%87 = load double*, double** %15
%88 = load i32, i32* %14
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %87, i64 %89
%91 = load double, double* %90
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %91)
br label %93
93: ; preds = %85
%94 = load i32, i32* %14
%95 = add nsw i32 %94, 1
store i32 %95, i32* %14
br label %81
96: ; preds = %81
%97 = load i32*, i32** %7
%98 = call i32 @fputc(i8 signext 10, i32* %97)
br label %99
99: ; preds = %96
%100 = load i32, i32* %10
%101 = load i32, i32* %13
%102 = add nsw i32 %101, %100
store i32 %102, i32* %13
br label %66
103: ; preds = %66
%104 = load double*, double** %15
%105 = call i32 @free(double* %104)
br label %106
106: ; preds = %103, %50
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Motion parameters:\0A\00"
@.str.1 = [7 x i8] c"%.10e \00"
@stderr = global i32 0
@.str.2 = [50 x i8] c"memory allocation failed in printSBAMotionData()\0A\00"
define void @printSBAMotionData(i32* nocapture %0, double* %1, i32 %2, i32 %3, void (double*, i32, double*, i32)* %4, i32 %5) {
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 19, i64 1, i32* %0)
%8 = icmp eq void (double*, i32, double*, i32)* %4, null
%9 = icmp slt i32 %5, 1
%10 = or i1 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = mul i32 %3, %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %63
14: ; preds = %11
%15 = zext i32 %12 to i64
br label %16
16: ; preds = %14, %27
%17 = phi i64 [ 0, %14 ], [ %21, %27 ]
%18 = getelementptr inbounds double, double* %1, i64 %17
%19 = load double, double* %18
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %19)
%21 = add nuw nsw i64 %17, 1
%22 = trunc i64 %21 to i32
%23 = srem i32 %22, %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = tail call i32 @fputc(i8 signext 10, i32* %0)
br label %27
27: ; preds = %16, %25
%28 = icmp eq i64 %21, %15
br i1 %28, label %63, label %16
29: ; preds = %6
%30 = shl i32 %5, 3
%31 = tail call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to double*
%33 = icmp eq i64 %31, 0
br i1 %33, label %41, label %34
34: ; preds = %29
%35 = mul nsw i32 %3, %2
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %61
37: ; preds = %34
%38 = sext i32 %3 to i64
%39 = zext i32 %35 to i64
%40 = zext i32 %5 to i64
br label %47
41: ; preds = %29
%42 = load i32, i32* @stderr
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i32*
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i64 49, i64 1, i32* %44)
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %37, %57
%48 = phi i64 [ 0, %37 ], [ %59, %57 ]
%49 = getelementptr inbounds double, double* %1, i64 %48
tail call void %4(double* %49, i32 %3, double* %32, i32 %5)
br label %50
50: ; preds = %47, %50
%51 = phi i64 [ 0, %47 ], [ %55, %50 ]
%52 = getelementptr inbounds double, double* %32, i64 %51
%53 = load double, double* %52
%54 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %53)
%55 = add nuw nsw i64 %51, 1
%56 = icmp eq i64 %55, %40
br i1 %56, label %57, label %50
57: ; preds = %50
%58 = tail call i32 @fputc(i8 signext 10, i32* %0)
%59 = add i64 %48, %38
%60 = icmp slt i64 %59, %39
br i1 %60, label %47, label %61
61: ; preds = %57, %34
%62 = tail call i32 @free(double* %32)
br label %63
63: ; preds = %27, %11, %61
ret void
}